After a publish, I want to know what the url of the published artifact is (to use it in other gradle tasks for automated deployment).
Is there any way to capture this generated url?
Sadly this information is unavailable via the gradle build system... What you can do is create a task that finalizes the publish
task
. Then have that task
query the maven repository for the most recent build. Maven will look in the maven-metadata.xml
file and return the <release>
tag value or the most recent upload if that's missing. You can get the exact download url from the response's Location
header.
Here is an example of how you would query a maven repo
$ curl -Is 'http://my.nexus.repo.com:8081/nexus/service/local/artifact/maven/redirect?r=Release&g=com.my.group.id&a=myArtifactId&v=RELEASE&p=war' | grep -Fi Location | cut -d' ' -f2
http://my.nexus.repo.com:8081/nexus/service/local/repositories/Release/content/com/my/group/id/myArtifactId/1.0.012/myArtifactId-1.0.012.war
Explaining the command
curl -Is http://<nexus-url>:<nexus-port>/nexus/service/local/artifact/maven/redirect?r=<nexus-repository>&g=<artifact-group-id>&a=<artifact-name>&v=<artifact-version>
curl
-I # only print return headers
-s # quiet output of curl's downloading progress
url params
r # nexus-repository name, tends to be Release or Snapshot
g # group id for the artifact
a # artifact id
v # artifact version or a link like RELEASE (don't use LATEST it's problematic)
## you can also supply classifier and extension if needed
c # artifact classifier
e # artifact extension