javagradlepluginssuite

How to add Lombok (annotationProcessor type) dependency in test suites plugin in Gradle?


I have created a new test suite using jvm-test-suite plugin.

I have added few implementation type dependencies and it was working fine, no error was coming. But I also want to add Lombok dependency in that test suite, I tried it with implementation keyword, after that I checked the project is getting compiled but at the runtime those annotations (e.g.: SneakyThrows) of Lombok are getting ignored and I was getting error.

After that I tried adding Lombok dependency with annotationProcessor keyword which resulting is below given error at Gradle sync. So basically it looks like annotationProcessor keyword and testAnnotationProcessor are not getting recognized and thus this error is coming.


Exception is:
org.gradle.api.GradleScriptException: A problem occurred evaluating root project 'serverlessserver'.
    at org.gradle.groovy.scripts.internal.DefaultScriptRunnerFactory$ScriptRunnerImpl.run(DefaultScriptRunnerFactory.java:93)

Caused by: groovy.lang.MissingMethodException: No signature of method: build_aiuizpn3ddvrwt4slowy7mi4q.testing() is applicable for argument types: (build_aiuizpn3ddvrwt4slowy7mi4q$_run_closure4) values: [build_aiuizpn3ddvrwt4slowy7mi4q$_run_closure4@74ada7e2]

Gradle file snippet:

testing {
    suites {
        test {
            useJUnitJupiter()
        }

        customTest(JvmTestSuite) {
            dependencies {
                implementation project
                ... // other dependencies
                annotationProcessor 'org.projectlombok:lombok:1.18.22' // adding this line is resulting in error message
            }            
        }
        ....
    }
}

Solution

  • I communicated with Gradle development team on their Slack support channel. I got the answer to this question which solved my problem and hence I am posting it here for other people.

    Plugin do not provide direct annotation processor support inside testing/suites block by default as of now, the team is implementing it and probably they will support it in future releases.

    You can still mention this annotation processor in outer most dependencies block of build.gradle file along with test suite name.

    Example of build.gradle file:

    dependencies {
        .....
        // dependencies you already have in your project
    
        // add this line. "customTest" here is the name of test suite you defined.
        customTestAnnotationProcessor('org.projectlombok:lombok:1.18.22')
    }
    

    One more thing you have to make sure is that you have defined your test suites before this dependencies block in build.gradle file. Otherwise, the annotationProcessor statement in dependencies do not recognize the test suite and will give error.