jfrog / artifactory-gradle-plugin

JFrog Gradle plugin for Build Info extraction and Artifactory publishing.
Apache License 2.0
21 stars 15 forks source link

Cannot run Project.afterEvaluate(Action) when the project is already evaluated. #67

Closed jiri-muller closed 11 months ago

jiri-muller commented 1 year ago

Describe the bug

After upgrade from 5.1.2 to 5.1.5 (5.1.3 is also affected) following error is thrown:

An exception occurred applying plugin request [id: 'dqf.java-conventions']
> Failed to apply plugin class 'org.jfrog.gradle.plugin.artifactory.ArtifactoryPlugin'.
   > Cannot run Project.afterEvaluate(Action) when the project is already evaluated.

Current behavior

An exception occurred applying plugin request [id: 'dqf.java-conventions']
> Failed to apply plugin class 'org.jfrog.gradle.plugin.artifactory.ArtifactoryPlugin'.
   > Cannot run Project.afterEvaluate(Action) when the project is already evaluated.

Reproduction steps

I am applying artifactory plugin via convention plugin:

plugins {
    id("com.jfrog.artifactory")
}

artifactory {
 // bug is present even without this section
}

However I was not able to reproduce this behavior similarly configured empty project. Other plugins used in project:

org.gradle.maven-publish org.owasp.dependencycheck com.diffplug.spotless

Same issue mentioned on SO https://stackoverflow.com/questions/77021002/jfrog-artifactory-stopped-working-in-android-studio-apply-plugin-com-jfrog-ar

Expected behavior

Project should build successfully like when 5.1.2 is used.

Artifactory Gradle plugin version

5.1.5

Operating system type and version

Linux Ubuntu 22.04.3 LTS

JFrog Artifactory version

No response

Gradle version

8.3 - Kotlin DSL

jiri-muller commented 12 months ago

Same behavior for v5.1.6

TheBatOutOfHell commented 12 months ago

Same issue here. Gradle 8.3; JAVA_HOME is openjdk-17 and I am targeting JAVA 1_8 Builds. The problem occurs on diffent projects of the same structure: root project with multiple submodules.

in the root projects build.gradle I have plugins block with id 'com.jfrog.artifactory' version '5.1.6' apply false

in the subproject I then only use id 'com.jfrog.artifactory

I get

An exception occurred applying plugin request [id: 'com.jfrog.artifactory']
> Failed to apply plugin class 'org.jfrog.gradle.plugin.artifactory.ArtifactoryPlugin'.
   > Cannot run Project.afterEvaluate(Action) when the project is already evaluated.

Using version 5.1.2 right now because this seems to be the latest version working in my projects.

yahavi commented 12 months ago

Hey @jiri-muller & @TheBatOutOfHell, Appreciate you letting us know about this problem. We tried, but couldn't replicate it so far. Could you please consider making a minimal reproducer for this issue?

TheBatOutOfHell commented 12 months ago

@yahavi Thanks for your response. For my case I can reproduce it with small example:

app-root.zip

app-root with module app...

no other stuff, no other plugins besides war-plugin. Even only including com.jfrog.artifactory version 1.5.6... no execution blocks artifactory... etc.

doing a gradle --refresh-dependencies for me already fails with given error.

Setting version to 5.1.2 build will be successful. Versions above will fail.

Thx for looking into it. kr Rob

PatriceManser commented 11 months ago

We experience the same issues with version 5.1.3 ...

Gradle 8.1.1 JDK 11.0.20-zulu

For us it is crucial to have at least version 5.1.3 of the plugin, because only since this version, Gradle's configuration cache is working for our build.

When importing our project into Eclipse, the above mentioned error occurs. In IntelliJ or via Gradle directly, we do not have these kinds of problems. Now we had to introduce special handling for builds in Eclipse, that set the version to 5.1.2 .

With 5.1.2 it works properly in Eclipse, but configuration cache is not usable.

TheBatOutOfHell commented 11 months ago

In my case (root project with modules) the problems occured no matter the platform... be it within Intellij or in console. However after some tests I now seem to have a working solution which allows me to use version 5.1.6. I simply changed the apply false in the root project build.gradle to apply true, so instead of

plugins {
    id 'com.jfrog.artifactory' version '5.1.6' apply false
}

I use

plugins {
    id 'com.jfrog.artifactory' version '5.1.6' apply true
}

Not fully what I want though as I do not want or need to apply the plugin in the root project (following: https://docs.gradle.org/current/userguide/plugins.html#sec:subprojects_plugins_dsl).

And just to make sure: apply false worked until version 5.1.2.

MarkRx commented 11 months ago

I was able to work around this by applying the plugin to the root project before applying it to any child projects. Note in my case I still use the older apply plugin mechanism since the newer plugins { } block is still lacking in some features I need.

// root build.gradle
apply plugin: 'com.jfrog.artifactory'

subprojects { subproject ->
    apply plugin: 'com.jfrog.artifactory'
    . . .
}
TheBatOutOfHell commented 11 months ago

I have now switched to conventions plugin with buildSrc; integrating artifactory plugin in conventions file yields the same error again. And again working with 5.1.2.

However using 5.1.6 I "temporarily?" fixed it by explicitly loading the plugin in the root projects build.gradle:

plugins { id 'com.jfrog.artifactory' apply true }

yahavi commented 11 months ago

@MarkRx @PatriceManser @TheBatOutOfHell @jiri-muller Thanks to @TheBatOutOfHell's reproducer, we were able to replicate this problem. We've gone ahead and set up a fix for it over at https://github.com/jfrog/artifactory-gradle-plugin/pull/70. We'll make sure to keep you updated on our progress.

yahavi commented 11 months ago

@MarkRx @PatriceManser @TheBatOutOfHell @jiri-muller Gradle Artifactory plugin version 5.1.9 has been released. This update incorporates a fix for a particular issue. We would be grateful for any feedback you might have on it.

TheBatOutOfHell commented 11 months ago

Hello @yahavi From my point of view it is working again now with version 5.1.9.

Thx!

jiri-muller commented 11 months ago

Hi @yahavi, I can confirm 5.1.9 works for me. Thank you!