Repository navigation
Fixes #1693: configureForSpotbugs using withDependencies instead of afterEvaluate - #1694
Conversation
…ead of afterEvaluate
There was a problem hiding this comment.
Code Review — Automated
Summary
Using Configuration.withDependencies instead of project.afterEvaluate is the right way to do this in Gradle. Good direction! There are a few things to look at before merging though.
Should fix before merge — getByName can crash for source sets added later
LombokPlugin.java, configureForSpotbugs method
The new code uses getByName(...) inside sourceSets.all(...). The problem: all also runs for source sets that get added later (like testFixtures). If the configuration doesn't exist yet at that point, this throws an UnknownConfigurationException.
You can use findByName instead — it just returns null if it doesn't exist yet:
javaPluginExtension.getSourceSets().all(sourceSet -> {
Configuration compileOnly = project.getConfigurations()
.findByName(sourceSet.getCompileOnlyConfigurationName());
if (compileOnly != null) {
compileOnly.withDependencies(deps -> {
String toolVersion = resolveSpotBugVersion();
deps.add(project.getDependencies().create(
"com.github.spotbugs:spotbugs-annotations:" + toolVersion));
});
}
});Suggestion — resolveSpotBugVersion() now runs more often
Before, this was called once. Now it runs once per source set, every time dependencies get resolved. It uses DslObject reflection under the hood. This is probably fine and maybe even intended — but worth adding a short comment so the next person knows it's on purpose.
Suggestion — Test assertion might break in the future
The test checks getUnresolvedModuleDependencies() to find spotbugs-annotations. This works because ProjectBuilder has no repositories, so everything stays "unresolved". But if someone adds a local Maven repo to the test setup later, this assertion stops working. A small comment explaining why it's done this way would help.
Result
The approach looks good! The findByName issue should be fixed before merge — the rest are just ideas to make the code a bit more robust.
|
@Frisch12 I addressed the review points in the last commit. |
No description provided.