Maven-publish with multiple repositories and release tasks

I am trying to using the maven-publish plugin with gradle 1.8 and snapshot/release repositories.

Inspired by the two posts from: and I am using if statements in the publishing part of my buildfile.

Things work great when using a versions defined at the beginning of the build file with an if statement to set the repository-url. When I use version = ‘0.2’ the artifacts get created as “myJar-0.2.jar” and they are published to the release repository correctly. When using version = ‘0.2-SNAPSHOT’ the artifacts get created as "myJar-0.2-SNAPSHOT.jar’ and are published to the snapshot repository.

BUT when I try to change the version in a gradleTask.whenReady statement (like suggested in the docs here: the artifacts get created correctly as either “myJar-0.2.jar” or "myJar-0.2-SNAPSHOT.jar’, but the publishing task is always searching for “myJar-0.2.jar”.

So when trying to create a SNAPSHOT jar it gets created but can’t be published (since it is not found).

I published my build.gradle file as GitHub Gist here:

Am I missing something here?

The new publishing plugins use a new configuration model that is a work in progress. All ‘publishing’ blocks are evaluated after the project is evaluated, but before ‘project.afterEvaluate’ (and before ‘tasks.whenReady’). Changing ‘project.version’ after the publishing block has been evaluated has no effect.

The actual solution to your problem will depend on your logic for determining snapshot vs release versions.

Ok… I managed to do this by passing a version via command-line-argument.

ext.defaultVersion = '0.3-SNAPSHOT'
ext.isRelease = false
  if (version.equalsIgnoreCase("unspecified")) {
 version = defaultVersion
} else if (!version.matches(~/[0-9]/)) {
 println "Invalid version number '$version' given. Falling back to default!"
 version = defaultVersion
  if (version.endsWith('-SNAPSHOT')) {
 println "Building SNAPSHOT version $version"
} else {
 isRelease = true;
 println "Building RELEASE version $version"