Skip to content

Commit

Permalink
allowing changing project version when uploading archives (useful for…
Browse files Browse the repository at this point in the history
… fixing a version in between releases)

Former-commit-id: 13503f6
  • Loading branch information
detonator413 committed Jan 17, 2019
1 parent 3afc7d9 commit dda5802
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,30 @@ subprojects {
archives sourceJar
}


task gitRev(type: Exec) {
commandLine 'git', 'rev-parse', '--short', 'HEAD'
standardOutput = new ByteArrayOutputStream()
ext.hash = {
standardOutput.toString()
}
}

// allows to upload non-snapshot versions that are tight to git revision (substitutes the version if it's a snapshot one)
// usage "gradle uploadArchives -PversionWithGitRev"
task changeVersionIfNeeded(dependsOn: gitRev) {
doLast {
def suffix = '-SNAPSHOT'
if (project.hasProperty('versionWithGitRev') && project.version.endsWith(suffix)) {
println project.version
project.version = project.version.substring(0, project.version.length() - suffix.length()) + "-" + tasks.gitRev.hash()
println "Version to be uploaded: " + project.version
}
}
}

compileJava.dependsOn(changeVersionIfNeeded)

uploadArchives {
// if you want to enable uploading to some maven repo, add those properties to ~/.gradle/gradle.properties, e.g.:
/*
Expand Down

0 comments on commit dda5802

Please sign in to comment.