Gradle 7 fails with "Cannot run Project.afterEvaluate(Action) when the project is already evaluated"

I am trying to prepare my project for Gradle 7, unfortunately, the build fails:

Build file '/home/flo/data/code/smack/build.gradle' line: 446

* What went wrong:
A problem occurred evaluating root project 'Smack'.
> Failed to apply plugin class 'org.gradle.api.publish.plugins.PublishingPlugin'.
   > Cannot run Project.afterEvaluate(Action) when the project is already evaluated.

The line in question, 446, is

	apply plugin: 'maven-publish'

and since this is an official pluging and from my interpretation of the error message, I assume it is unrelated to the maven-publish plugin. Instead, it is potentially cause by something that triggers the evaluation of the project before the plugin is applied (which has become an error with Gradle 7). If my assessment of the situation is correct, then the question is: What triggers the evaluation?

Unfortunately, my gradle foo ends here, I am stuck on how to approach/diagnose this issue. Any help is appreciated. The branch preparing of Gradle 7 is at

and a build scan of the build is available under

Any help is much appreciated. Thanks in advance. :slight_smile:

FYI, you did not activate that buildscan, so you should do ASAP and post the correct link.

1 Like

The issue is related to the root project’s call to evaluationDependsOnChildren, which IMO should be avoided if you can. I don’t know the details behind what’s changed in Gradle to make it fail, maybe it is intentional, maybe a regression, I’m not sure.

I was able to reproduce your problem with a simple build and I was able to fix it by moving evaluationDependsOnChildren() after my subprojects block (which applies the maven-publish plugin).

1 Like

I am not sure if I can avoid it. As the code comment states, the evaluationDependsOnChildren is required to resolve the dependencies, so that the versions of the dynamic version dependencies are known to javadocAll which will link to the javadoc of those dependencies.

But I am obvious open to suggestions how to get rid of evaluationDependsOnChildren.