Publish doFirst block not executing


Using Gradle version 2.3
apply plugin: 'eclipse’
apply plugin: 'java’
apply plugin: 'maven-publish’
apply plugin: ‘com.jfrog.artifactory’

I’m trying to force a -Pversion parameter on the command line but only for the ‘publish’ task.

publish <<{ 
        doFirst { 
                if (version.equalsIgnoreCase("unspecified")) { 
                        println "If publishing, you must provide version parameter" 
                        println "./gradlew -Pversion=#.#.# | ./gradlew -Pversion=SNAPSHOT"
                } else if (version.equalsIgnoreCase('SNAPSHOT')) {
                } else {
                        println "Building RELEASE version ${version}"
                println "************************************"
                println "* Building version ${version} " 
                println "************************************"

However, # sh gradlew -x test publish
goes and ahead and publishes everything with ‘unspecified’ as the version. Nothing from the block above is printed.

If I put the block outside of the publish block, it works but it obviously applies to all tasks.

Nevermind - the task is artifactoryPublish which publish depends on.

And if it matters, it was likely ignoring your “doFirst” block because you were using the “<<” notation, which implicitly wraps the body with “doLast”. It might have worked if you removed the “<<”.