Cannot include build in project that uses maven-publish plugin

I have a project with a dependency on another Gradle based project. When I try to include the dependency using –include-build I get the following error (names munged):

FAILURE: Build failed with an exception.

* Where:
Build file '/home/me/projects/my-project/my-model/build.gradle.kts' line: 1

* What went wrong:
An exception occurred applying plugin request [id: 'org.gradle.maven-publish']
> Failed to apply plugin class 'org.gradle.api.publish.plugins.PublishingPlugin'.
   > Project#afterEvaluate(Action) on project ':my-model' cannot be executed in the current context.

The only way I can get it to build with the included dependency is to remove the maven-publish plugin. Any idea where to start with this one?

Do the builds use the same Gradle version or different versions when run individually?

And can you share a build --scan URL if it comes that far, if not then at least a --stacktrace.

The gradle versions were not the same (8.11 vs 8.14.3) but upgrading the included one to 8.14.3 did not change the behavior. Build scan: Build Scan® activation | Develocity

I should point out that the included build uses the maven-publish plugin also, but it seems to be the application in the main build that it doesn’t like.

8.11 and 8.14.3 are probably similar enough.
But if for example the included is written for 7.x and the including is using 8.x, then the included is also run with 8.x as the Gradle version of the including build is used to build both.
When you updated the included to 8.14.3, did you try to run it standalone to see whether it works with that Gradle version?

Also, as it complains about afterEvaluate, is that something within your logic or within some 3rd party plugin that you use?

Independent of the concrete problem, if it is in your build logic, you should try to get rid of it. Using afterEvaluate is highly disouraged bad practice, and the main earnings of using it are ordering problems, timing problems, and race conditions. Imho it should be avoided at almost any cost.

Hm, no, it seems to be the actual publishing plugin that does the afterEvaluate call. :-/
Can you share that project / those projects or is it something proprietary?

Right the afterEvaluate is in the publishing plugin itself. And yes the included build does work fine with 8.14.3 standalone. Unfortunately sharing the full projects is a no-go.

And could you knit an MCVE maybe?

Hmm. I have a sub-project in the main build that uses the Docker Compose plugin: GitHub - avast/gradle-docker-compose-plugin: Simplifies usage of Docker Compose for integration testing in Gradle environment. After some experimentation, I see that if I remove that the build works.

Hm, maybe it does something bad, it does quite some things with tasks and projects and included builds from a cursory look.

Maybe with now knowing that, you can build an MCVE to then report to whoever is the culprit. :slight_smile:

Or maybe it helps if you update it from ...10 to ...19. :man_shrugging:

I tried updating already - no dice. It’s hard to say if it’s actually even a bug in that plugin; after all maven-publish is what it complains about and removing that “fixes” it also…

Ok I seem to have fixed it. For posterity, here’s a snippet of how I was configuring the docker compose plugin and what I changed:

val integrationTest by tasks.registering(Test::class) {
    description = "Execute integration tests."
    group = "verification"
    classpath = sourceSets["integrationTest"].runtimeClasspath
    testClassesDirs = sourceSets["integrationTest"].output.classesDirs
}

dockerCompose {
    isRequiredBy(integrationTest.get()) // Adding the .get() here fixed it...presumably by forcing the integrationTest task to be configured?
    captureContainersOutputToFiles = project.layout.buildDirectory.dir("test-logs/integrationTest")
    environment.put("JAR_FILENAME", tasks.shadowJar.flatMap { it.archiveFileName })
    environment.put("JAR_FILE", tasks.shadowJar.flatMap { it.archiveFile })
}

Well no, you did not fix it, you just worked-around a bug.
Using the get() you break the task-configuration avoidance for the integrationTest task.
At the same time you are giving a Task to the isRequiredBy and not any longer a TaskProvider, which triggers a completely different code-path.
So you sacrifice the task-configuration avoidance of that task to work-around the bug that still slumbers somewhere.

Btw. it is not the maven-publish plugin that triggers the error, but the publishing plugin, which is applied by the maven-publish plugin. :slight_smile:

It might still be a good idea to report the issue, but you would probably still need to create an MCVE to even find out whom to best report this to.
I suspect the compose plugin, but without something to look at, cannot say for sure.

Btw. you might consider using the JVM Testsuites plugin to create your integ tests including task sourceset and so on, instead of doing it by hand as you do now. :slight_smile: