Add option for disabling saves every project evaluation
Caveat: If the properties file does not yet exist, this setting is ignored so it can be created
This commit is contained in:
parent
2cbea71c6f
commit
53910122f4
2 changed files with 11 additions and 2 deletions
|
@ -43,6 +43,7 @@ open class SemverConfig {
|
||||||
const val DEFAULT_BUILDMETA_KEY = "buildmeta"
|
const val DEFAULT_BUILDMETA_KEY = "buildmeta"
|
||||||
const val DEFAULT_BUILDMETA_PREFIX_KEY = "buildmeta.prefix"
|
const val DEFAULT_BUILDMETA_PREFIX_KEY = "buildmeta.prefix"
|
||||||
const val DEFAULT_SEPARATOR = "separator"
|
const val DEFAULT_SEPARATOR = "separator"
|
||||||
|
const val DEFAULT_SAVE_AFTER_PROJECT_EVALUATE = true
|
||||||
}
|
}
|
||||||
|
|
||||||
var properties = DEFAULT_PROPERTIES
|
var properties = DEFAULT_PROPERTIES
|
||||||
|
@ -63,4 +64,5 @@ open class SemverConfig {
|
||||||
var separatorKey = DEFAULT_SEPARATOR
|
var separatorKey = DEFAULT_SEPARATOR
|
||||||
get() = "$keysPrefix$field"
|
get() = "$keysPrefix$field"
|
||||||
var keysPrefix = DEFAULT_KEYS_PREFIX
|
var keysPrefix = DEFAULT_KEYS_PREFIX
|
||||||
|
var saveAfterProjectEvaluate = DEFAULT_SAVE_AFTER_PROJECT_EVALUATE
|
||||||
}
|
}
|
||||||
|
|
|
@ -70,6 +70,10 @@ class SemverPlugin : Plugin<Project> {
|
||||||
put(config.separatorKey, version.separator)
|
put(config.separatorKey, version.separator)
|
||||||
|
|
||||||
propsFile.apply {
|
propsFile.apply {
|
||||||
|
if (!exists()) {
|
||||||
|
// Need to create the file as canWrite() will not work unless the file exists
|
||||||
|
createNewFile()
|
||||||
|
}
|
||||||
if (canWrite()) {
|
if (canWrite()) {
|
||||||
FileOutputStream(this).writer().use {
|
FileOutputStream(this).writer().use {
|
||||||
store(it, "Generated by the Semver Plugin for Gradle")
|
store(it, "Generated by the Semver Plugin for Gradle")
|
||||||
|
@ -86,8 +90,8 @@ class SemverPlugin : Plugin<Project> {
|
||||||
if (GradleVersion.current() < GradleVersion.version("4.8.1")) {
|
if (GradleVersion.current() < GradleVersion.version("4.8.1")) {
|
||||||
throw GradleException("The $simpleName plugin requires Gradle version 4.8.1 or greater.")
|
throw GradleException("The $simpleName plugin requires Gradle version 4.8.1 or greater.")
|
||||||
}
|
}
|
||||||
project.afterEvaluate(this::afterEvaluate)
|
|
||||||
config = project.extensions.create("semver", SemverConfig::class.java)
|
config = project.extensions.create("semver", SemverConfig::class.java)
|
||||||
|
project.afterEvaluate(this::afterEvaluate)
|
||||||
|
|
||||||
project.tasks.apply {
|
project.tasks.apply {
|
||||||
create("incrementMajor", SemverIncrementTask::class.java, config, version, SemverConfig.DEFAULT_MAJOR_KEY)
|
create("incrementMajor", SemverIncrementTask::class.java, config, version, SemverConfig.DEFAULT_MAJOR_KEY)
|
||||||
|
@ -132,7 +136,10 @@ class SemverPlugin : Plugin<Project> {
|
||||||
}
|
}
|
||||||
project.version = version.semver
|
project.version = version.semver
|
||||||
project.logger.info("[$simpleName] Project version set to: ${project.version}")
|
project.logger.info("[$simpleName] Project version set to: ${project.version}")
|
||||||
saveProperties(config, version)
|
// If first time running and there is no props file, and saveAfterEvaluate is false, then version props would never have been saved before
|
||||||
|
if (config.saveAfterProjectEvaluate || !isFile) {
|
||||||
|
saveProperties(config, version)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue