checkerframework-gradle-plugin icon indicating copy to clipboard operation
checkerframework-gradle-plugin copied to clipboard

Get "Cannot run Project.afterEvaluate(Closure) when the project is already evaluated." when add some configurations

Open blackdiz opened this issue 2 years ago • 3 comments

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.

blackdiz avatar Sep 10 '22 03:09 blackdiz

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?

mernst avatar Sep 10 '22 15:09 mernst

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.

kelloggm avatar Sep 12 '22 18:09 kelloggm

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.

blackdiz avatar Sep 13 '22 04:09 blackdiz

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

blackdiz avatar Sep 19 '22 07:09 blackdiz

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.

msridhar avatar Oct 16 '22 00:10 msridhar

@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.

kelloggm avatar Oct 17 '22 16:10 kelloggm

The fix worked for me; thanks!

msridhar avatar Oct 17 '22 17:10 msridhar