Skip to content

Instantly share code, notes, and snippets.

@rileyrg
Created May 1, 2014 10:42
Show Gist options
  • Save rileyrg/11448957 to your computer and use it in GitHub Desktop.
Save rileyrg/11448957 to your computer and use it in GitHub Desktop.
loadVersion : how?
ext.versionFile = file('version.properties')
task wrapper(type:Wrapper){
gradleVersion="1.10"
}
task loadVersion {
project.version = readVersion()
println project.version
}
ProjectVersion readVersion() {
logger.quiet 'Reading the version file.'
if (!versionFile.exists()) {
throw new GradleException("Required version file does not exit: $versionFile.canonicalPath")
}
Properties versionProps = new Properties()
versionFile.withInputStream { stream ->
versionProps.load(stream)
}
new ProjectVersion(versionProps.major.toInteger(), versionProps.minor.toInteger(), versionProps.release.toBoolean())
}
task makeReleaseVersion(type: ReleaseVersionTask) {
release = version.release
destFile = versionFile
}
class ReleaseVersionTask extends DefaultTask {
@Input Boolean release
@OutputFile File destFile
ReleaseVersionTask() {
group = 'versioning'
description = 'Makes project a release version.'
}
@TaskAction
void start() {
project.version.release = true
ant.propertyfile(file: destFile) {
entry(key: 'release', type: 'string', operation: '=', value: 'true')
}
}
}
class ProjectVersion {
Integer major
Integer minor
Boolean release
ProjectVersion(Integer major, Integer minor) {
this.major = major
this.minor = minor
this.release = Boolean.FALSE
}
ProjectVersion(Integer major, Integer minor, Boolean release) {
this(major, minor)
this.release = release
}
@Override
String toString() {
"$major.$minor${release ? '-RELEASE' : '-SNAPSHOT'}"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment