Added the ability to specify the version via the command line.
This commit is contained in:
parent
8d423a506a
commit
16d1a06571
2 changed files with 21 additions and 19 deletions
|
@ -8,7 +8,7 @@ buildscript {
|
||||||
mavenLocal()
|
mavenLocal()
|
||||||
}
|
}
|
||||||
dependencies {
|
dependencies {
|
||||||
classpath "net.thauvin.erik.gradle:semver:0.9.9-beta"
|
classpath "net.thauvin.erik.gradle:semver:1.0.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -20,7 +20,7 @@ mainClassName = 'App'
|
||||||
|
|
||||||
version = 1.0
|
version = 1.0
|
||||||
|
|
||||||
def f = new File("test.properties")
|
def f = new File("version.properties")
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
|
|
||||||
|
@ -30,15 +30,6 @@ repositories {
|
||||||
jcenter()
|
jcenter()
|
||||||
}
|
}
|
||||||
|
|
||||||
clean {
|
|
||||||
delete fileTree(dir: "$projectDir", include: "*.properties")
|
|
||||||
}
|
|
||||||
|
|
||||||
incrementPatch {
|
|
||||||
doFirst {
|
|
||||||
println("[Gradle] exists: " + f.exists() + ", canRead: " + f.canRead())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
incrementBuildMeta {
|
incrementBuildMeta {
|
||||||
doFirst {
|
doFirst {
|
||||||
|
@ -48,7 +39,6 @@ incrementBuildMeta {
|
||||||
}
|
}
|
||||||
|
|
||||||
run {
|
run {
|
||||||
//dependsOn("incrementPatch")
|
|
||||||
doFirst {
|
doFirst {
|
||||||
println("Version: $version")
|
println("Version: $version")
|
||||||
args = [f.name]
|
args = [f.name]
|
||||||
|
|
|
@ -116,16 +116,17 @@ class SemverPlugin : Plugin<Project> {
|
||||||
Properties().apply {
|
Properties().apply {
|
||||||
load(reader)
|
load(reader)
|
||||||
|
|
||||||
hasReqProps = stringPropertyNames().containsAll(setOf(config.majorKey, config.minorKey,
|
val requiredProps = setOf(config.majorKey, config.minorKey, config.patchKey,
|
||||||
config.patchKey, config.preReleaseKey, config.buildMetaKey))
|
config.preReleaseKey, config.buildMetaKey)
|
||||||
|
hasReqProps = stringPropertyNames().containsAll(requiredProps) && !hasEnv(requiredProps)
|
||||||
|
|
||||||
version.major = getProperty(config.majorKey, Version.DEFAULT_MAJOR)
|
version.major = loadProperty(this, config.majorKey, Version.DEFAULT_MAJOR)
|
||||||
version.minor = getProperty(config.minorKey, Version.DEFAULT_MINOR)
|
version.minor = loadProperty(this, config.minorKey, Version.DEFAULT_MINOR)
|
||||||
version.patch = getProperty(config.patchKey, Version.DEFAULT_PATCH)
|
version.patch = loadProperty(this, config.patchKey, Version.DEFAULT_PATCH)
|
||||||
version.preRelease = getProperty(config.preReleaseKey, Version.DEFAULT_EMPTY)
|
version.preRelease = loadProperty(this, config.preReleaseKey, Version.DEFAULT_EMPTY)
|
||||||
version.preReleasePrefix =
|
version.preReleasePrefix =
|
||||||
getProperty(config.preReleasePrefixKey, Version.DEFAULT_PRERELEASE_PREFIX)
|
getProperty(config.preReleasePrefixKey, Version.DEFAULT_PRERELEASE_PREFIX)
|
||||||
version.buildMeta = getProperty(config.buildMetaKey, Version.DEFAULT_EMPTY)
|
version.buildMeta = loadProperty(this, config.buildMetaKey, Version.DEFAULT_EMPTY)
|
||||||
version.buildMetaPrefix =
|
version.buildMetaPrefix =
|
||||||
getProperty(config.buildMetaPrefixKey, Version.DEFAULT_BUILDMETA_PREFIX)
|
getProperty(config.buildMetaPrefixKey, Version.DEFAULT_BUILDMETA_PREFIX)
|
||||||
version.separator = getProperty(config.separatorKey, Version.DEFAULT_SEPARATOR)
|
version.separator = getProperty(config.separatorKey, Version.DEFAULT_SEPARATOR)
|
||||||
|
@ -147,4 +148,15 @@ class SemverPlugin : Plugin<Project> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun hasEnv(keys: Set<String>): Boolean {
|
||||||
|
keys.forEach {
|
||||||
|
if (System.getProperties().containsKey(it)) return true
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun loadProperty(props: Properties, key: String, default: String): String {
|
||||||
|
return System.getProperty(key, props.getProperty(key, default))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue