This works fine if I’m using a local repository, but it fails when using a remote repository like Maven or Artifactory. Gradle doesn’t fetch those jar files before it runs the ant taskdef, which of course fails. I could put all this code into a task, and make that task depend on svnConf; but the whole point of this code is to set properties on the project itself (like project.version), so I think I need this code to run before the execution phase.
Bottom line: How can I make Gradle retrieve the jar files for svnConf right away, so I can run that taskdef?
There is no need to force anything because asPath will do this automatically. There is likely some other problem like repositories not being declared correctly.
We’re storing our jar files locally, rather than grabbing them from Maven or Artifactory. So it’s really a non-issue for us. Also, I seem to recall that Peter was right and we had a different misconfiguration in our build system somewhere.
// Read the current revision from SVN.
// Set up the classpath and (ant) taskdef for the svn lib.
configurations {
svnConf
}
dependencies {
svnConf "org.tigris:svnant:1.3+"
svnConf "org.tigris:svnClientAdapter:0.9+"
}
ant {
taskdef(resource: 'org/tigris/subversion/svnant/svnantlib.xml',
classpath: configurations.svnConf.asPath)
}
ant {
svnSetting(id: 'svnSettings', javahl: 'false', svnkit: 'false')
svn(refid: 'svnSettings') {
info(target: rootDir.path)
}
}
// Extract the last path component of the SVN URL. This will
// be either trunk or the branch/tag name.
rootProject.svnBranchName = ant.properties['svn.info.url'].split('/').last()
assert rootProject.svnBranchName.length() > 0
// Execute the svnversion command as an external process, and
// parse its output.
new ByteArrayOutputStream().withStream { os ->
exec {
executable = 'svnversion'
args = [rootDir.path]
standardOutput = os
}
rootProject.svnRevision = os.toString().trim().replace(':', '-')
}
This will set rootProject.svnBranchName to the name of the current branch of “trunk”, and rootProject.svnRevision will be the the output of svnversion.