Gradle does not pick correct version of war file in Jenkin

I have an issue with Gradle which is used to deploy spring boot application to cloud foundry. maven.deployer does not pick the correct version of war file as per the naming convention specified in the gradle. War file is created successfully in buil/distributions, but it is not getting picked correctly by uploadarchive task. Any help would be great.

Getting error:

:uploadArchives (Thread[main,5,main]) completed. Took 1.378 secs.

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':uploadArchives'.
> Could not publish configuration 'archives'
   > Error deploying artifact 'com.*****:***-SSO_RC:war': Error deploying artifact: Failed to transfer file: http://*******/releases/com****-SSO_RC/0.1.0/****-SSO_RC-0.1.0.war. Return code is: 400

* Try:
Run with --stacktrace option to get the stack trace. Run with --debug option to get more log output.

BUILD FAILED

Build.gradle

version "0.1.0"  //Art added Snapshot to version
group "com*****"

project.ext.test = 'test'

// Define property defaults if they don't exist
if( !project.hasProperty('classifier' ) ){
	ext.classifier = 'LOCAL'
}
if( !project.hasProperty('buildNumber' ) ){
	ext.buildNumber = '0'
}

ext.isSnapshot = (ext.classifier == "RELEASE" || ext.classifier.contains("RC" ) ) ? false : true

apply plugin: "maven"
apply plugin: 'java'
apply plugin: 'war'
apply plugin: 'eclipse-wtp'
apply plugin: 'spring-boot'
apply plugin: 'cloudfoundry'
apply plugin: 'idea'
apply plugin: 'eclipse'

buildscript {
    repositories {
        //mavenCentral()
		maven { url  nexusPublicRepoURL }
    }
    dependencies {
     	classpath("org.springframework.boot:spring-boot-gradle-plugin:1.2.3.RELEASE")
        classpath("org.springframework:spring-webmvc:4.1.6.RELEASE")
        classpath "org.cloudfoundry:cf-gradle-plugin:1.1.0"
    }
}


// Uses JDK 7
sourceCompatibility = 1.7
targetCompatibility = 1.7


// 1. Get dependencies from Maven local repository
// 2. Get dependencies from Maven central repository
repositories {
	maven { url  nexusPublicRepoURL }
    //mavenCentral()
}

//Project dependencies
dependencies {
	compile 'ch.qos.logback:logback-classic:1.1.2'
	compile 'org.springframework:spring-webmvc:4.1.6.RELEASE'
	compile 'jstl:jstl:1.2'
	compile 'com.fasterxml.jackson.core:jackson-databind:2.5.3'
	//include in compile only, exclude in the war
	providedCompile 'javax.servlet:servlet-api:2.5' 
	// compile("org.springframework.boot:spring-boot-starter-web")
    //providedRuntime("org.springframework.boot:spring-boot-starter-tomcat")
}

/*configurations {
    providedRuntime
}*/

eclipse {
    classpath {
         containers.remove('org.eclipse.jdt.launching.JRE_CONTAINER')
         containers 'org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7'
    }
}


uploadArchives {
	repositories.mavenDeployer {
		repository(url: nexusReleaseRepoURL) {
			 logger.info("${nexusReleaseRepoURL} is nexusReleaseRepoURL")
			authentication(userName: nexusUsername, password: nexusPassword)
		}
		snapshotRepository(url: nexusSnapshotRepoURL) {
			authentication(userName: nexusUsername, password: nexusPassword)
		}
	}
}

if( project.hasProperty( 'development' ) ){
	cloudfoundry{
		host = '***-ssodev'
		space = 'development'
		target = 'https://api.****.com'
		domain = '****.com'
		env = [
		"JBP_LOG_LEVEL": "DEBUG"
		]
		services {
			"syslog-drain" {
				label ="syslog-drain"
			}

		}
	}
} else if ( project.hasProperty( 'production' ) ) {
	cloudfoundry {
		host = '***-sso'
		space = 'production'
		target = 'https://api.*****.com'
		domain = '****.com'

		services {
			"syslog-drain" {
				label ="syslog-drain"
			}

		}
	}
}

cloudfoundry {
	username = cfUsername
	password = cfPassword
	application = '****'
	//file = war.outputFile
	file = file("build/distributions/" + buildArchiveName())
    logger.info("${file} is file inside Cloudfoundry")
	memory = 1024
	instances = 1
	organization = "***-org"
	trustSelfSignedCerts = "true"
}

bootRepackage {
 	mainClass = '<%= packageName %>.Application'
 }

war {
    archiveName = buildArchiveName()
    logger.info("${archiveName} is archiveName")
    destinationDir = file('build/distribution/')
}	

def buildArchiveName(){
	if( project.hasProperty('archiveBuildNumber' ) ){
		return "****sso-${version}-${classifier}.${archiveBuildNumber}.war".toString()
	}
	else {
		return "****sso-${version}-${classifier}.${buildNumber}.war".toString()
	}
}

Does it matter what the file name is when it’s uploaded to cloudfoundry?

I’d try simplifying things a bit more. You’re putting the war into ‘build/distribution’ and you’re looking for it in ‘build/distributions’ in the cloudfoundry block. I’d change cloudfoundry to use file = war.archivePath and just make sure you configure the war task before cloudfoundry.