Merge pull request #2 from lewismorgan/props-updates
Add option for disabling saves every project evaluation
This commit is contained in:
commit
a0ddcae5f0
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_PREFIX_KEY = "buildmeta.prefix"
|
||||
const val DEFAULT_SEPARATOR = "separator"
|
||||
const val DEFAULT_SAVE_AFTER_PROJECT_EVALUATE = true
|
||||
}
|
||||
|
||||
var properties = DEFAULT_PROPERTIES
|
||||
|
@ -63,4 +64,5 @@ open class SemverConfig {
|
|||
var separatorKey = DEFAULT_SEPARATOR
|
||||
get() = "$keysPrefix$field"
|
||||
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)
|
||||
|
||||
propsFile.apply {
|
||||
if (!exists()) {
|
||||
// Need to create the file as canWrite() will not work unless the file exists
|
||||
createNewFile()
|
||||
}
|
||||
if (canWrite()) {
|
||||
FileOutputStream(this).writer().use {
|
||||
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")) {
|
||||
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)
|
||||
project.afterEvaluate(this::afterEvaluate)
|
||||
|
||||
project.tasks.apply {
|
||||
create("incrementMajor", SemverIncrementTask::class.java, config, version, SemverConfig.DEFAULT_MAJOR_KEY)
|
||||
|
@ -132,7 +136,10 @@ class SemverPlugin : Plugin<Project> {
|
|||
}
|
||||
project.version = version.semver
|
||||
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