ProjectsEvaluatedBuildListener creates/configures the artifactoryPublish task too early
See original GitHub issueThe ProjectsEvaluatedBuildListener
has an afterEvaluate
hook which configures the artifactoryPublish
task. This is a problem for Gradle Plugin developers who apply the com.jfrog.artifactory
plugin as part of their library which is then used by other projects.
Our library itself does its artifactory configuration within an afterEvaluate
block because it needs to read project build information before it can correctly configure the publications needed. The problem I’m having after version 4.4.9
of the plugin is that I have no control over the ordering of afterEvaluate
blocks, so the ProjectsEvaluatedBuildListener
block is executing before mine, so when the artifactoryPublish
task runs there are publications there but the generatePomFileFor...
task isn’t there as a task dependency, so the consuming application’s build fails when running artifactoryPublish
.
My code:
project.afterEvaluate { proj ->
// Artifactory has already been configured on the root project by the com.mycompany.base plugin
// Just need to add the main publication
def configurationsForPom = getConfigurationsForMavenPom()
def bootJarTask = proj.tasks.findByName 'bootJar' // Spring boot 2 disables the jar task & instead has its own bootJar task. This is 1 reason why this is in an afterEvaluate block so that the full build file can be evaluated before creating the publication
def jarTask = bootJarTask?.enabled ? bootJarTask : proj.tasks['jar']
proj.configure(proj.publishing) {
publications {
mainJava(MavenPublication) {
artifactId "${ -> proj.myExtension.artifactId}"
// Change due to https://github.com/gradle/gradle/issues/1061
// from proj.components.java
artifact jarTask
artifact proj.tasks[SOURCESJAR_TASK_NAME]
artifact proj.tasks[JAVADOCJAR_TASK_NAME]
pom.withXml {
// Another reason this needs to be in an afterEvaluate block
PluginHelper.fixMavenPomDependencySection(proj, asNode(), *configurationsForPom)
}
}
}
}
// And then configure the artifactoryPublish task to publish the main publication
proj.configure(proj.tasks['artifactoryPublish']) {
publications 'mainJava'
}
}
This is what I’m seeing when my application applies my plugin and then runs artifactoryPublish
:
:artifactoryPublish
:artifactoryDeploy FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':artifactoryDeploy'.
> File '/jenkins_home/03/d3445737/workspace/folder/project 2.1/project/subproject/target/publications/mainJava/pom-default.xml' does not exist, and need to be published from publication mainJava
* 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.
Issue Analytics
- State:
- Created 5 years ago
- Reactions:3
- Comments:12 (5 by maintainers)
Top GitHub Comments
Note that this issue is unrelated to the problem described in https://github.com/gradle/gradle/issues/4783. Let’s focus on that one first and then continue with this one.
Thanks @AlexeiVainshtein for the update. I’ll wait and see what comes from this. Until there is some resolution we are stuck on version 4.4.9 of the plugin.