Skip to content
This repository has been archived by the owner on Jan 18, 2021. It is now read-only.

Commit

Permalink
writeVersion task only writes file when executed (#10)
Browse files Browse the repository at this point in the history
Previously, even running `./gradlew tasks` would cause the version.properties file to be written.
This task will now only write the file when executed.
  • Loading branch information
iamdanfox authored and zoubeiri committed May 19, 2016
1 parent 9283f55 commit 1e032ad
Showing 1 changed file with 20 additions and 8 deletions.
28 changes: 20 additions & 8 deletions write-version.gradle
Original file line number Diff line number Diff line change
@@ -1,12 +1,24 @@
// depends on https://github.com/palantir/gradle-git-version

task writeVersion {
description "Writes a version.properties file with the current git version to <project>/src/main/resources/."
def contents = "productVersion: " + project.version
def resourcesDir = file("$projectDir/src/main/resources")
if(!resourcesDir.exists()) {
resourcesDir.mkdir()
task writeVersion(type: WriteVersionTask) {
versionFile = "$projectDir/src/main/resources/version.properties"
}

class WriteVersionTask extends DefaultTask {
def versionFile

File getVersionFile() {
project.file(versionFile)
}

String getDescription() {
"Writes the current git version to a specified file (e.g. <project>/src/main/resources/version.properties)."
}

@TaskAction
def writeToFile() {
getVersionFile().getParentFile().mkdirs()
getVersionFile().text = "productVersion: " + project.version
}
def versionFile = new File("$resourcesDir/version.properties")
versionFile.text = contents
}

0 comments on commit 1e032ad

Please sign in to comment.