diff --git a/README.md b/README.md index ff9901e..81ba3ac 100644 --- a/README.md +++ b/README.md @@ -41,9 +41,9 @@ buildscript { maven { url "https://plugins.gradle.org/m2/" } } dependencies { - classpath 'eu.davidea:grabver:0.5.0' + classpath 'eu.davidea:grabver:0.6.0' // or with Gradle Plugins Repository - classpath "gradle.plugin.eu.davidea:grabver:0.5.0" + classpath "gradle.plugin.eu.davidea:grabver:0.6.0" } } ``` diff --git a/build-test.gradle b/build-test.gradle index 316c322..da9b8b9 100644 --- a/build-test.gradle +++ b/build-test.gradle @@ -18,7 +18,7 @@ buildscript { } //noinspection GroovyAssignabilityCheck dependencies { - classpath 'eu.davidea:grabver:0.5.0' + classpath 'eu.davidea:grabver:0.6.0' } } diff --git a/build.gradle b/build.gradle index e5508a4..522e262 100644 --- a/build.gradle +++ b/build.gradle @@ -39,7 +39,7 @@ ext { // Library Repository libraryName = 'GrabVer' - libraryVersion = '0.5.0' + libraryVersion = '0.6.0' displayName = 'Gradle Automatic Build Versioning Plugin' libraryDescription = 'An easy Gradle plugin that follows semver.org rules to automatically generate the Patch version, Build number and Code version, while Major, Minor and Pre-Release suffix remain under our control.' libraryLabels = ['semver', 'version', 'versioning', 'build-versioning', 'automatic-versioning', 'intellij-idea', 'android-studio', 'auto-reset'] diff --git a/module_a/build.gradle b/module_a/build.gradle index bd284c1..791e708 100644 --- a/module_a/build.gradle +++ b/module_a/build.gradle @@ -6,7 +6,7 @@ buildscript { mavenLocal() } dependencies { - classpath 'eu.davidea:grabver:0.5.0' + classpath 'eu.davidea:grabver:0.6.0' } } diff --git a/module_b/build.gradle b/module_b/build.gradle index 5cded20..c4a776d 100644 --- a/module_b/build.gradle +++ b/module_b/build.gradle @@ -6,7 +6,7 @@ buildscript { mavenLocal() } dependencies { - classpath 'eu.davidea:grabver:0.5.0' + classpath 'eu.davidea:grabver:0.6.0' } } diff --git a/src/main/groovy/eu/davidea/gradle/GrabVer.groovy b/src/main/groovy/eu/davidea/gradle/GrabVer.groovy index ce850c4..38a191a 100644 --- a/src/main/groovy/eu/davidea/gradle/GrabVer.groovy +++ b/src/main/groovy/eu/davidea/gradle/GrabVer.groovy @@ -37,19 +37,19 @@ import org.gradle.api.Project class GrabVer implements Plugin { void apply(Project project) { - println("====== STARTED GrabVer v0.5.0") + println("====== STARTED GrabVer v0.6.0") println("INFO - ProjectName=" + project.name) project.task('grabverRelease') { // Dummy task to trigger release versioning (also used in unit test) } + project.task('grabverSkip') { + // Dummy task to skip versioning (also used in unit test) + } // Create new empty versioning instance VersioningExtension versioning = project.extensions.create("versioning", VersioningExtension) - def runTasks = project.gradle.startParameter.taskNames - println("INFO - runTasks=" + runTasks) - // Module versioning String module = project.name String filename = 'version.properties' @@ -66,12 +66,16 @@ class GrabVer implements Plugin { File versionFile = getFile(filename) OrderedProperties versionProps = loadProperties(project, versionFile) - if ('clean' in runTasks || 'test' in runTasks) { - println("INFO - Skipping on Task clean & test") + // Check runTasks + def runTasks = project.gradle.startParameter.taskNames + println("INFO - runTasks=" + runTasks) + + if (runTasks.contains("clean") || runTasks.contains("test") || runTasks.contains("grabverSkip")) { + println("INFO - Skipping on Task: clean, test & grabverSkip") versioning.evaluated = true } else { // Increment depends on release - if ('assemble' in runTasks || 'assembleRelease' in runTasks || 'grabverRelease' in runTasks) { + if (runTasks.contains("grabverRelease") || runTasks.contains(":" + module + ":assembleRelease")) { println("INFO - Running with 'release' task: 'Code' version will auto increment") versioning.increment = 1 } else { @@ -82,7 +86,7 @@ class GrabVer implements Plugin { project.afterEvaluate { if (!('clean' in runTasks)) { // Save new values - println("INFO - Saving Versioning: " + versioning) + println("INFO - Saving versioning: " + versioning) versionProps.setProperty(VersionType.MAJOR.toString(), String.valueOf(versioning.major)) versionProps.setProperty(VersionType.MINOR.toString(), String.valueOf(versioning.minor)) versionProps.setProperty(VersionType.PATCH.toString(), String.valueOf(versioning.patch)) diff --git a/src/main/groovy/eu/davidea/gradle/VersioningExtension.groovy b/src/main/groovy/eu/davidea/gradle/VersioningExtension.groovy index 664d66f..a375fa3 100644 --- a/src/main/groovy/eu/davidea/gradle/VersioningExtension.groovy +++ b/src/main/groovy/eu/davidea/gradle/VersioningExtension.groovy @@ -138,7 +138,7 @@ class VersioningExtension { String toString() { return major + "." + minor + "." + patch + - (preRelease != null && !preRelease.isEmpty() ? "-" + preRelease : "") + + (isPreRelease() ? "-" + preRelease : "") + " #" + build + " code=" + code } diff --git a/src/test/groovy/eu/davidea/gradle/GrabVerTest.groovy b/src/test/groovy/eu/davidea/gradle/GrabVerTest.groovy index e7548c9..9e5ba2e 100644 --- a/src/test/groovy/eu/davidea/gradle/GrabVerTest.groovy +++ b/src/test/groovy/eu/davidea/gradle/GrabVerTest.groovy @@ -40,6 +40,25 @@ class GrabVerTest { Assert.assertEquals("code check", 4, project.versioning.code) } + @Test + void testAutoIncrement_Skip_Versioning() throws Exception { + List tasks = new ArrayList<>() + tasks.add("grabverSkip") + tasks.add("grabverRelease") + project.gradle.startParameter.setTaskNames(tasks) + project.pluginManager.apply PLUGIN_ID + project.versioning { + major = 1 + minor = 1 + } + printResults("[Skip]") + Assert.assertEquals("major check",1, project.versioning.major) + Assert.assertEquals("minor check",1, project.versioning.minor) + Assert.assertEquals("patch check",1, project.versioning.patch) + Assert.assertEquals("build check",20, project.versioning.build) + Assert.assertEquals("code check", 3, project.versioning.code) + } + @Test void testAutoIncrement_Release_VersionChange() throws Exception { List tasks = new ArrayList<>()