Hi
We have just upgraded our Gradle to 2.4 version and noticed something has changed in this version which I could not figure out.
Our script is very simple,we apply java and distribution plugin and at the end of the build use uploadArchives to upload the artifacts(jar and zip file produced by distZip) into Nexus and this was working fine until we upgraded Gradle from 2.2 to 2.4.
From 2.4 onwards,we see that gradle also runs distTar task and during uploadArchives task it tries to upload Tar file which is not there and failed.
import org.apache.tools.ant.filters.*
import java.io.File
apply plugin: 'maven'
apply plugin: 'java'
apply plugin: 'distribution'
archivesBaseName ='Account'
ext.repoUserName=System.properties['REPO_USER_NAME']
ext.repoPassword=System.properties['REPO_PASSWORD']
ext.readOnlyRepoURL=System.env['COMMON_REPO']
ext.releaseRepoURL=System.env['REPO_URL']
buildscript {
repositories {
maven{
url System.env['COMMON_REPO']
}
}
dependencies {
classpath 'de.undercouch:gradle-download-task:1.2'
}
}
apply plugin: 'de.undercouch.download'
import de.undercouch.gradle.tasks.download.Download
configurations.all{
transitive=false
}
artifacts{
archives distZip
}
uploadArchives{
repositories.mavenDeployer {
configuration = configurations.archives
repository(url: releaseRepoURL) {
authentication(userName: repoUserName, password: repoPassword)
}
}
}
//Store the Java source dir and resources(properties files,xml files output dir globally)
ext{
javaSrcDir=sourceSets.main.java.srcDirs.toList()[0]
resourceOutputDir=sourceSets.main.output.resourcesDir
classesOutputDir=sourceSets.main.output.classesDir
libOutputDir=libsDir
}
distributions {
main {
contents {
from ( resourceOutputDir )
}
}
}
//processResources task is from Java plugin and use this block to replace tokens
processResources {
/*No need to mention token name if they are same,it will be automatically replaced.
However token name is case sensitive,so if the case is not matched it will not be
replaced automatically.Try to use same case else explicitly replace the token.
E.g. filter(ReplaceTokens, tokens: [
WEBSPHERE_IP:project.buildEnvProps.websphere_ip
WEBSPHERE_PORT::project.buildEnvProps.websphere_port
])
*/
//Replace all the tokens while moving file to build directory
filter(ReplaceTokens, tokens: project.buildEnvProps)
}
repositories {
maven{
url releaseRepoURL
url readOnlyRepoURL
}
}
processResources.dependsOn('clean')
compileJava.dependsOn('processResources')
jar.dependsOn(compileJava)
distZip.dependsOn('jar')
Output :
:distTar
:clean
:processResources
:compileJava
:classes
:jar
:distZip
:compileTestJava UP-TO-DATE
:processTestResources UP-TO-DATE
:testClasses UP-TO-DATE
:test UP-TO-DATE
:uploadArchives FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':uploadArchives'.
> Could not publish configuration 'archives'
> Cannot publish artifact 'Account.tar (com.services:Account:1.0.2)' (C:\AccountService\build\distributions\Account-1.0.2.tar) as it does not exist.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
BUILD FAILED
As we can see from the output above,it run distTar first before running clean and hence the Account-1.0.2.tar is deleted when the clean task is running. I could alter the dependencies to run distTar after clean task but that is not what I wanted,I do not even want to run distTar .
Thanks