2

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
            }            
        }
        ....
    }
}
informatik01
  • 16,038
  • 10
  • 74
  • 104
Sukhbir
  • 553
  • 8
  • 23

3 Answers3

1

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.

informatik01
  • 16,038
  • 10
  • 74
  • 104
Sukhbir
  • 553
  • 8
  • 23
  • 2
    FYI, using annotation processors when compiling test suites (https://github.com/gradle/gradle/issues/20113) is now available in the latest release candidate https://docs.gradle.org/release-candidate/release-notes.html. – Tom Tresansky May 18 '22 at 20:16
  • From Gradle 7.5, `annotationProcessor` is supported in inside `dependencies` block of a test suite. For more info: https://docs.gradle.org/current/userguide/jvm_test_suite_plugin.html#configure_dependencies_of_a_test_suite – maximus Jul 22 '22 at 08:52
1

This is what I used to not rewrite the same dependencies twice for test and customTest tasks (I also use lombok for my test):

configurations {
    customTestImplementation {
        extendsFrom testImplementation
    }
    customTestCompileOnly {
        extendsFrom testCompileOnly
    }
    customTestAnnotationProcessor {
        extendsFrom annotationProcessor
    }
}
maximus
  • 1,290
  • 1
  • 14
  • 18
-2

Directly from the official lombok website.

repositories {
    mavenCentral()
}

dependencies {
    compileOnly 'org.projectlombok:lombok:1.18.22'
    annotationProcessor 'org.projectlombok:lombok:1.18.22'
    
    testCompileOnly 'org.projectlombok:lombok:1.18.22'
    testAnnotationProcessor 'org.projectlombok:lombok:1.18.22'
}

Lombok annotations are applied during compilation, so it should be added in compileOnly stage, not in runtimeOnly.

Emil
  • 97
  • 4
  • I already have all these dependencies mentioned in my global dependencies block. I am asking how can i add these dependencies in my suites project ? – Sukhbir Feb 23 '22 at 18:13
  • Yeah. Thanks for the downvote, it really encourages me to answer your questions. Have you tried copying the dependencies i linked into your testSuite dependencies. Again; lombok is applied during compilation, so you shouldn't apply it in the `runtimeOnly` and `implementation` stage. – Emil Feb 23 '22 at 18:23