Using Java lambdas is not supported as task inputs

Hello,

I am developping a Gradle plugin, in Java. It defines several tasks, and customize tasks from other plugin. For example it customizes the behavior of the JavaCompile task. We use doFirst/doLast on this task for this purpose. Until now, everything was ok, our testsuite (which uses Gradle Testkit) worked fine. But I added the generation of the code coverage with Jacoco and the jacoco-gradle-testkit-plugin plugin, which makes the testsuite to fail. This plugin adds the property org.gradle.jvmargs in the gradle.properties of the tested project, to define the Jacoco agent. When this plugin is enabled, I get this kind of error when launching the tests:

* What went wrong:
    A problem was found with the configuration of task ':compileJava' (type 'JavaCompile').
      - Additional action of task ':compileJava' was implemented by the Java lambda 'com.mycompany.gradle.plugins.MyProjectConfiguration$$Lambda$1062/0x000000080080cc40'.

        Reason: Using Java lambdas is not supported as task inputs.

        Possible solution: Use an (anonymous inner) class instead.

        For more information, please refer to https://docs.gradle.org/8.6/userguide/validation_problems.html#implementation_unknown in the Gradle documentation.

According to the message and the documentation, I understand that Java lambdas must not be used in doFirst/doLast. What I don’t understand is why I did not get the error message before using the Jacoco plugin. Do I have this error because we now use a Java agent ? Why ?

Regards

Hard to say without an MCVE, but well, as the error says, just use an anonymous class instead. :slight_smile:

Ok, I will try to provide an MCVE. I forgot to mention that it works when I use anonymous class, but I would like to understand why I did not have the problem before, it intrigues me :slight_smile:

1 Like