Maven-publish not using version set dynamically in taskGraph.whenReady

Following the example in 14.13, the taskGraph whenReady can be used to set the version dynamically. When the java plugin executes, it honors this version for subprojects and sets the jar target as Lib-A-1.0-SNAPSHOT.jar. When maven publish plugin executes, it is looking ror the wrong file name (and not honoring the file name that the java plugin created) Lib-A.jar.

Example project on github

Gradle Version: 3.0
Operating System and JVM version: Windows 8 Java 8
Is this a regression? No.

The Maven Publish plugin is a bit special as it defers the evaluation of the code it uses for configuring the publications. You can implement your use case by configuring the actual publications instead of setting the project version. Please consider the following code as example.

apply plugin: 'java'
apply plugin: 'maven-publish'

group = ''

gradle.taskGraph.whenReady { taskGraph ->
    if (taskGraph.hasTask(':release')) {
        publishing.publications.mavenJava.version '1.0'
    } else {
        publishing.publications.mavenJava.version '1.0-SNAPSHOT'

publishing {
    publications {
        mavenJava(MavenPublication) {
    repositories {
        maven {
            url "$buildDir/repo"

task release {
    dependsOn publish

I’m afraid the code above had no effect on the outcome. Still looking at the primary version not the publication version.

I works properly for me. Keep in mind that the version only changes for the publication, not the artifact created by the jar task. I am going to send you PR later today.

Oh, I think I understand now… I was also setting the version (which affected the jar file name). If I do not set a version, but simply change the publication it will publish the jar as that version.
Works. Behind a VPN so I can’t test the actual publish at the moment, but wouldnt that then mean my jar will not have the version as part of the filename?

The local artifact in build/libs would have the version reflected in the file name. However, when published the version would be added to file name and meta data in the designated repository.

Related issue: I’d like to change the url as well based on the snapshot or release version. Normally I can set this in the publications - but the mavenJava version attribute isnt set until after the taskGraph.whenReady, how can I change the url in the whenReady???

url “${publicationUrlBase}/libs-${publishing.publications.mavenJava.version.endsWith(’-SNAPSHOT’) ? ‘snapshot’ : ‘release’ }-local”