Skip to content

Fixes #1693: configureForSpotbugs using withDependencies instead of afterEvaluate - #1694

Merged
Frisch12 merged 2 commits into
freefair:mainfrom
maor-pontera:fix/lombok-spotbugs-with-dependencies
Mar 28, 2026
Merged

Frisch12 merged 2 commits into
freefair:mainfrom
maor-pontera:fix/lombok-spotbugs-with-dependencies

Conversation

@maor-pontera

Copy link
Copy Markdown
Contributor

No description provided.

@Frisch12 Frisch12 left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@maor-pontera

Copy link
Copy Markdown
Contributor Author

@Frisch12 I addressed the review points in the last commit.

@Frisch12
Frisch12 merged commit d5f3c35 into freefair:main Mar 28, 2026
7 checks passed
@maor-pontera
maor-pontera deleted the fix/lombok-spotbugs-with-dependencies branch March 29, 2026 06:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants