I would like to capture the unique version of an artifact that Gradle creates when it publishes to a Maven repository. I’m using the old uploadArchives task as follows:
[ant:null] Deploying to https://mynexus.example.com/nexus-deps/content/repositories/snapshots
[INFO] Retrieving previous build number from remote
Uploading: com/example/mything/1.0-SNAPSHOT/mything-1.0-20140528.000250-425.jar to repository remote at https://mynexus.example.com/nexus-deps/content/repositories/snapshots
I’d like to capture “1.0-20140528.000250-425” for use in a CI build (Jenkins). I have been through the docs and the source code up and down, and can’t figure out how to do this. I’m open to any method: setting an environment variable, writing to disk, etc.
Thanks, Peter. Yes, the logic seems buried inside CustomDeployTask which is used by the BaseMavenDeployer. I was hoping there was some way to get to it that I’d missed.
I’ve turned off unique versioning using “uniqueVersion = false”, but I can’t seem to set the version it uploads with. No matter what I try, it always publishes with “1.0-SNAPSHOT”. It’s extremely frustrating. Here’s what I’ve got so far:
No matter where I specify artifactVersion, Gradle always outputs:
Uploading: com/example/mything/1.0-SNAPSHOT/mything-1.0-SNAPSHOT.zip to repository remote at https://mynexus.example.com/nexus-deps/content/repositories/snapshots
What setting can I use to override this vexing default?
If you set “uniqueVersion = false”, then you’re telling Maven that every snapshot version will be published the literal ‘SNAPSHOT’ instead of a unique version. You cannot specify a version yourself in this case.
So I guess I’m not sure how I get control over the version number. I need to be able to (1) either set it myself or (2) programmatically be able to access the one generated by Gradle and/or the underlying plugin. I think what I’m understanding from this thread is that this isn’t possible?
Inexplicably (to me, at least), Gradle still ignores the version I’m giving it:
:publishMavenPublicationToMavenRepository
Uploading: com/example/mything/1.0-SNAPSHOT/mything-1.0-20140609.202841-1.zip to repository remote at https://mynexus.example.com/nexus-deps/content/repositories/snapshots
Transferring 72917K from remote
Uploaded 72917K
:publish
Notice it still uses 1.0-SNAPSHOT as the version, and the zip file name is a string I don’t even recognize. That is NOT the string generated for my variable “artifactVersion.”
I noticed through some experimentation that the problem arises when “artifactVersion” begins with “1.0-”. If I remove those characters from the start of the string, Gradle publishes normally with the version I specify and everything appears to succeed.
Is there some strange behavior Gradle and/or the Maven plugin default to if it detects “1.0” in the version?
Here’s a little more detail on this. It appears that anytime the version number begins with some variation of a digit and a dash, then Gradle automatically substitutes a SNAPSHOT in the path. Here’s a self-contained runnable example (note: requires a local file named fake.txt):
Uploading: temp1/temp2/1-SNAPSHOT/temp2-1-20140609.223414-2.txt to repository remote at https://mynexus.example.com/nexus-deps/content/repositories/snapshots
Notice the path has been changed, and the version in the filename no longer uses my version algorithm (there’s no “-0” at the end). I don’t know if this is Nexus or Gradle, but it seems like it’s Gradle. What am I missing?