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?
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.
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…
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.
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.