How to get publication's full SNAPSHOT filename?

I have a gradle build that we have publishing to a SNAPSHOT repo for non-release versions on multiple projects. The build publishes to an Artifactory SNAPSHOT repo and it generates a timestamp on that repo when I publish.

How do I get the full SNAPSHOT filename at the time of publishing so I can store it elsewhere? E.g. MyArchive-1.0.0-SNAPSHOT-NAME-20180313.163134-16.zip instead of the base name: MyArchive-1.0.0-SNAPSHOT-NAME.zip

version = "1.0.0-SNAPSHOT"
publishing {
	publications {
		maven(MavenPublication) {		
			artifactId 'MyArchive' 
			artifact myArchive
		}
    
  }
}



subprojects { 
  version = versionNum + (snapshot == 'RELEASE' ? '.' + buildNum : "-${snapshot}")
	
	group = "myCompany"
	publishing {         
      repositories {
            maven {
                credentials {
                    username System.properties['pubUser']
                    password System.properties['pubPassword']
					
                }
				def releaseType =  snapshot == 'RELEASE' ? releaseurl : snapshoturl
				url releaseType
            }
        }
    }
}

Hi,

did you found solution?

I am trying to solve the exact problem.

Afraid I could not find a gradle way to it. Kind of hacky, but you could have a task that runs after your publish task then query the generic snapshot url and capture what the redirected url is from that. I entertained this, but didn’t write anything because the need for this became unnecessary.

I came up with the following;

task showSnapshotVersion() {
    enabled = project.version.contains('SNAPSHOT')
    dependsOn publish
    def repo = publishing.repositories[0]
    def artifactUrl = repo.url.toString() + project.group.replaceAll("\\.", "/") + "/" + project.name + "/" + project.version + "/maven-metadata.xml"
    def authString = "${repo.credentials.username}:${repo.credentials.password}".getBytes().encodeBase64().toString()
    doFirst {
        def conn = artifactUrl.toURL().openConnection()
        conn.setRequestProperty("Authorization", "Basic ${authString}")
        if (!(conn.responseCode == 200)) {
            throw new Exception("Unable to retrieve published version: ${conn.responseCode}: ${conn.responseMessage}")
        }
        def metadata = new XmlSlurper().parseText(conn.content.text)
        println "===========\nsnapshot version = ${metadata.versioning.snapshotVersions.snapshotVersion[0].value.text()}\n================="
    }
}
tasks.publish.finalizedBy(tasks.showSnapshotVersion)

(and yes, if there are two different publishes of the same artefact at the same time, the output of the first one published may erroneously show the timestamp of the second one published)