checkerframework-gradle-plugin
checkerframework-gradle-plugin copied to clipboard
Get "Cannot run Project.afterEvaluate(Closure) when the project is already evaluated." when add some configurations
When I try to specify the checker framework version in the dependency block like:
dependencies {
// ...
val checkerFrameworkVersion = "3.25.0"
compileOnly("org.checkerframework:checker-qual:$checkerFrameworkVersion")
testCompileOnly("org.checkerframework:checker-qual:$checkerFrameworkVersion")
implecmentation("org.checkerframework:checker-util:$checkerFrameworkVersion")
checkerFramework("org.checkerframework:checker:$checkerFrameworkVersion")
// ...
}
or add skipVersionCheck = true
to the configuration:
configure<org.checkerframework.gradle.plugin.CheckerFrameworkExtension> {
checkers = listOf(
"org.checkerframework.checker.nullness.NullnessChecker"
)
excludeTests = true
skipVersionCheck = true
}
I got the following errors:
Execution failed for task ':dependencies'.
> Failed to notify dependency resolution listener.
> Cannot run Project.afterEvaluate(Closure) when the project is already evaluated.
> Cannot run Project.afterEvaluate(Closure) when the project is already evaluated.
> Cannot run Project.afterEvaluate(Closure) when the project is already evaluated.
* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.
Can you help me to figure out why, please? I use Gradle 7.4.2 with Kotlin build script and JDK 17.
Thanks for reporting the problem, and I'm sorry you are having trouble.
Could you provide some more information to help us diagnose the problem and confirm a fix?
- What are configurations that work? (You gave some that don't work for you.)
- Can you please provide a full example, so that we can reproduce the problem and our fix?
Hi! Sorry you are having trouble. I tried to reproduce the issue you've reported using a simple gradle repository, and I'm not seeing any problems. My attempt to reproduce is here. You can run ./gradlew -b build.gradle.kts clean build
to see that everything appears to work.
Can you provide additional instructions to reproduce the problem, or modify my attempt to reproduce to actually demonstrate the issue? Without that, we won't be able to provide much help, unfortunately.
I am very appreciative of your quick reply. Sorry, I have been a little busy recently, but I will seek to provide examples as soon as I can.
Hi, sorry for replying so late, I find the problem is when using with the Lombok plugin. You can check the problematic build.gradle in my forked repository: https://github.com/blackdiz/sample-gradle-project/tree/repro-cf-gradle-212
I am seeing the same issue as @blackdiz. Here is my branch:
https://github.com/msridhar/tainting-example/tree/called-methods-lombok
On that branch, here is what I see:
$ ./gradlew compileJava --console=plain --stacktrace
Starting a Gradle Daemon (subsequent builds will be faster)
> Task :createCheckerFrameworkManifest
> Task :generateEffectiveLombokConfig FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':generateEffectiveLombokConfig'.
> Cannot run Project.afterEvaluate(Closure) when the project is already evaluated.
* Try:
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.
* Exception is:
org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':generateEffectiveLombokConfig'.
[...]
Caused by: org.gradle.api.InvalidUserCodeException: Cannot run Project.afterEvaluate(Closure) when the project is already evaluated.
at org.gradle.api.internal.project.DefaultProject.failAfterProjectIsEvaluated(DefaultProject.java:1068)
at org.gradle.api.internal.project.DefaultProject.afterEvaluate(DefaultProject.java:1062)
at org.gradle.api.Project$afterEvaluate.call(Unknown Source)
at org.checkerframework.gradle.plugin.CheckerFrameworkPlugin$1.execute(CheckerFrameworkPlugin.groovy:139)
at org.checkerframework.gradle.plugin.CheckerFrameworkPlugin$1.execute(CheckerFrameworkPlugin.groovy)
at org.gradle.api.internal.collections.CollectionFilter$1.execute(CollectionFilter.java:59)
at org.gradle.api.internal.DefaultDomainObjectCollection.all(DefaultDomainObjectCollection.java:161)
at org.gradle.api.internal.DefaultDomainObjectCollection.withType(DefaultDomainObjectCollection.java:203)
at org.gradle.api.DomainObjectCollection$withType$0.call(Unknown Source)
at org.checkerframework.gradle.plugin.CheckerFrameworkPlugin.handleLombokPlugin(CheckerFrameworkPlugin.groovy:105)
The issue was caused by adding id "io.freefair.lombok" version "6.5.1"
to the plugins
section.
@blackdiz and @msridhar sorry for the delay in looking into this. afterEvaluate
is an anti-pattern, so I decided to try to remove it entirely. The result is #219, which I think fixes this problem - I tested it on the example @blackdiz provided.
The fix worked for me; thanks!