freefair / gradle-plugins

Gradle Plugin Collection
https://docs.freefair.io/gradle-plugins/current/reference/
MIT License
221 stars 33 forks source link

Lombok plugin: Delombok task fails with Gradle 8.1.1 #801

Closed gwitsch closed 1 year ago

gwitsch commented 1 year ago

Hi, after updating to Gradle 8.1.1 and Lombok plugin 8.0.1 the task delombok fails. Previous Gradle version was 7.6.1 and Lombok plugin was 6.6

20:14:44  > Task :generateEffectiveLombokConfig UP-TO-DATE
20:14:44  > Task :compileJava UP-TO-DATE
20:14:44  > Task :processResources UP-TO-DATE
20:14:44  > Task :classes UP-TO-DATE
20:14:44  > Task :jar UP-TO-DATE
20:14:44  > Task :delombok FAILED
20:14:44  
20:14:44  FAILURE: Build failed with an exception.
20:14:44  
20:14:44  * What went wrong:
20:14:44  A problem was found with the configuration of task ':delombok' (type 'Delombok').
20:14:44    - Gradle detected a problem with the following location: '/var/lib/jenkins/workspace/trunk/shareDatabase/shareDatabase/build/generated/sources/annotationProcessor/java/main'.
20:14:44      
20:14:44      Reason: Task ':delombok' uses this output of task ':compileJava' without declaring an explicit or implicit dependency. This can lead to incorrect results being produced, depending on what order the tasks are executed.
20:14:44      
20:14:44      Possible solutions:
20:14:44        1. Declare task ':compileJava' as an input of ':delombok'.
20:14:44        2. Declare an explicit dependency on ':compileJava' from ':delombok' using Task#dependsOn.
20:14:44        3. Declare an explicit dependency on ':compileJava' from ':delombok' using Task#mustRunAfter.
20:14:44      
20:14:44      Please refer to https://docs.gradle.org/8.1.1/userguide/validation_problems.html#implicit_dependency for more details about this problem.
20:14:44  
20:14:44  * Try:
20:14:44  > Run with --stacktrace option to get the stack trace.
20:14:44  > Run with --info or --debug option to get more log output.
20:14:44  > Run with --scan to get full insights.
20:14:44  
20:14:44  * Get more help at https://help.gradle.org/

The temporary solution is quiet easy. All I had to do was updating the dependsOn configuration for the Delombok tasks:

tasks.withType(Delombok).configureEach {
    dependsOn compileJava
}

But it would be a better approach if the plugin already does that by itself.

I might also need to mention that the error appears in combination with the creation of the javadoc and sources jar during the build. Those jars are created with Gradle's built-in javadocJar and sourcesJar tasks.

Only calling the jar task on my Java project does not cause the problem.

gwitsch commented 1 year ago

Hm, this might be a more complex issue than first expected. It seems that an Annotation processor and an additional source directory might be the route cause. I will do some further inspection and will be back...

gwitsch commented 1 year ago

Did some further research: My problem has been solved with the above mentioned fix. However I don't think, that's a bug in the Lombok plugin.

In my case it has been caused by the combination Lombok plugin and the annotation processor org.hibernate:hibernate-jpamodelgen

As the jpamodelgen gets integrated in the compileJava task, Gradle complained when running the delombok task. This is called when creating the javadoc jar. So updating the dependsOn configuration works for me.