From 3c9da22d7c0f482cc733e0db3e3b140d78091c0d Mon Sep 17 00:00:00 2001 From: Yang Date: Tue, 27 Oct 2026 12:32:00 +1100 Subject: [PATCH 1/3] TIP --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 60840fa..4ab8b8f 100644 --- a/README.md +++ b/README.md @@ -62,6 +62,7 @@ plugins { +> [!TIP] > Upgrading from 1.x? See the [2.0 Migration Guide](docs/migration-guide.md). ## Usage From 0bd8b10e1701475a8eca67ff000f5186c5903eca Mon Sep 17 00:00:00 2001 From: Yang Date: Tue, 27 Oct 2026 18:49:39 +1100 Subject: [PATCH 2/3] Refactor fixture runner and project templates. --- build.gradle.kts | 11 +- .../fixtures/AndroidProjectTemplate.kt | 152 +++++++++++++ .../fixtures/BuildScriptLanguage.kt | 11 + .../appversioning/fixtures/FixtureProject.kt | 51 +++++ .../appversioning/fixtures/FixtureRunner.kt | 75 ++---- .../fixtures/ProjectTemplates.kt | 213 ------------------ .../tasks/GenerateAppVersionInfoTest.kt | 11 +- 7 files changed, 235 insertions(+), 289 deletions(-) create mode 100644 src/functionalTest/kotlin/io/github/reactivecircus/appversioning/fixtures/AndroidProjectTemplate.kt create mode 100644 src/functionalTest/kotlin/io/github/reactivecircus/appversioning/fixtures/BuildScriptLanguage.kt create mode 100644 src/functionalTest/kotlin/io/github/reactivecircus/appversioning/fixtures/FixtureProject.kt delete mode 100644 src/functionalTest/kotlin/io/github/reactivecircus/appversioning/fixtures/ProjectTemplates.kt diff --git a/build.gradle.kts b/build.gradle.kts index b2ac342..a37d830 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -23,6 +23,7 @@ mavenPublishing { } gradleTestKitSupport { + withSupportLibrary() disablePublication() } @@ -56,11 +57,6 @@ java { targetCompatibility = JavaVersion.VERSION_17 } -val fixtureClasspath = configurations.create("fixtureClasspath") -tasks.pluginUnderTestMetadata { - pluginClasspath.from(fixtureClasspath) -} - tasks.withType().configureEach { testLogging { events(TestLogEvent.PASSED, TestLogEvent.SKIPPED, TestLogEvent.FAILED) @@ -87,11 +83,6 @@ dependencies { functionalTestImplementation(kotlin("test-junit")) functionalTestImplementation(libs.burst) functionalTestImplementation(libs.agp.build.api) - fixtureClasspath(libs.agp.build.gradle.flatMap { dependency -> - fixtureAgpVersion.map { version -> - "${dependency.group}:${dependency.name}:$version" - } - }) detektPlugins(libs.plugin.detektKtlintWrapper) } diff --git a/src/functionalTest/kotlin/io/github/reactivecircus/appversioning/fixtures/AndroidProjectTemplate.kt b/src/functionalTest/kotlin/io/github/reactivecircus/appversioning/fixtures/AndroidProjectTemplate.kt new file mode 100644 index 0000000..c166c86 --- /dev/null +++ b/src/functionalTest/kotlin/io/github/reactivecircus/appversioning/fixtures/AndroidProjectTemplate.kt @@ -0,0 +1,152 @@ +package io.github.reactivecircus.appversioning.fixtures + +import com.autonomousapps.kit.AbstractGradleProject +import com.autonomousapps.kit.gradle.BuildScript +import com.autonomousapps.kit.gradle.Imports +import com.autonomousapps.kit.gradle.Plugin + +sealed class AndroidProjectTemplate { + abstract val projectName: String + abstract val pluginExtension: String? + abstract val buildScriptLanguage: BuildScriptLanguage + abstract val flavors: List + abstract val imports: List + + internal fun buildScript(fixtureAgpVersion: String): BuildScript { + val androidPluginId = if (this is AppProjectTemplate) "com.android.application" else "com.android.library" + return BuildScript.Builder().apply { + if (this@AndroidProjectTemplate.imports.isNotEmpty()) { + imports = Imports.of(this@AndroidProjectTemplate.imports) + } + plugins( + Plugin(androidPluginId, fixtureAgpVersion), + AppVersioningPlugin, + ) + additions = androidBlock() + "\n\n" + pluginExtension.orEmpty() + }.build() + } + + private fun androidBlock(): String = when (buildScriptLanguage) { + BuildScriptLanguage.Kts -> kotlinAndroidBlock() + BuildScriptLanguage.Groovy -> groovyAndroidBlock() + } + + private fun kotlinAndroidBlock(): String { + val flavorConfigs = if (flavors.isNotEmpty()) { + """ + flavorDimensions.add("environment") + productFlavors { + ${flavors.joinToString("\n") { "register(\"$it\") {}" }} + } + """.trimIndent() + } else { + "" + } + val abiConfigs = if (this is AppProjectTemplate && splitsApks) { + """ + splits { + abi { + isEnable = true + reset() + include("armeabi-v7a", "arm64-v8a", "x86", "x86_64") + isUniversalApk = $universalApk + } + } + """.trimIndent() + } else { + "" + } + return """ + android { + namespace = "$DEFAULT_PACKAGE_NAME.${projectName.replace("-", ".")}" + compileSdk = 36 + defaultConfig { + minSdk = 21 + ${if (this is AppProjectTemplate) "targetSdk = 36" else ""} + } + lint.checkReleaseBuilds = false + + $flavorConfigs + + $abiConfigs + } + """.trimIndent() + } + + private fun groovyAndroidBlock(): String { + val flavorConfigs = if (flavors.isNotEmpty()) { + """ + flavorDimensions "environment" + productFlavors { + ${flavors.joinToString("\n") { "$it {}" }} + } + """.trimIndent() + } else { + "" + } + val abiConfigs = if (this is AppProjectTemplate && splitsApks) { + """ + splits { + abi { + enable true + reset() + include "armeabi-v7a", "arm64-v8a", "x86", "x86_64" + universalApk $universalApk + } + } + """.trimIndent() + } else { + "" + } + return """ + android { + namespace '$DEFAULT_PACKAGE_NAME.${projectName.replace("-", ".")}' + compileSdk 36 + defaultConfig { + minSdk 21 + ${if (this is AppProjectTemplate) "targetSdk 36" else ""} + } + lint { + checkReleaseBuilds false + } + + $flavorConfigs + + $abiConfigs + } + """.trimIndent() + } + + val manifestFileContent: String + get() = """ + + + """.trimIndent() + + companion object { + private const val DEFAULT_PACKAGE_NAME = "io.github.reactivecircus.appversioning" + } +} + +private val AppVersioningPlugin = Plugin( + id = "io.github.reactivecircus.app-versioning", + version = AbstractGradleProject.PLUGIN_UNDER_TEST_VERSION, +) + +class AppProjectTemplate( + override val projectName: String = "app", + override val pluginExtension: String? = null, + override val buildScriptLanguage: BuildScriptLanguage = BuildScriptLanguage.Kts, + override val flavors: List = emptyList(), + val splitsApks: Boolean = false, + val universalApk: Boolean = false, + override val imports: List = emptyList(), +) : AndroidProjectTemplate() + +class LibraryProjectTemplate( + override val projectName: String = "library", + override val pluginExtension: String? = null, + override val buildScriptLanguage: BuildScriptLanguage = BuildScriptLanguage.Kts, + override val flavors: List = emptyList(), + override val imports: List = emptyList(), +) : AndroidProjectTemplate() diff --git a/src/functionalTest/kotlin/io/github/reactivecircus/appversioning/fixtures/BuildScriptLanguage.kt b/src/functionalTest/kotlin/io/github/reactivecircus/appversioning/fixtures/BuildScriptLanguage.kt new file mode 100644 index 0000000..c3237d2 --- /dev/null +++ b/src/functionalTest/kotlin/io/github/reactivecircus/appversioning/fixtures/BuildScriptLanguage.kt @@ -0,0 +1,11 @@ +package io.github.reactivecircus.appversioning.fixtures + +import com.autonomousapps.kit.GradleProject + +enum class BuildScriptLanguage { + Kts, + Groovy; + + internal val dslKind: GradleProject.DslKind + get() = if (this == Kts) GradleProject.DslKind.KOTLIN else GradleProject.DslKind.GROOVY +} diff --git a/src/functionalTest/kotlin/io/github/reactivecircus/appversioning/fixtures/FixtureProject.kt b/src/functionalTest/kotlin/io/github/reactivecircus/appversioning/fixtures/FixtureProject.kt new file mode 100644 index 0000000..9698224 --- /dev/null +++ b/src/functionalTest/kotlin/io/github/reactivecircus/appversioning/fixtures/FixtureProject.kt @@ -0,0 +1,51 @@ +package io.github.reactivecircus.appversioning.fixtures + +import com.autonomousapps.kit.GradleProject +import com.autonomousapps.kit.gradle.GradleProperties +import java.io.File + +internal fun createFixtureProject( + fixtureDir: File, + subprojects: List, + parentDirectoryName: String?, +): GradleProject { + val buildScriptLanguage = subprojects.firstOrNull()?.buildScriptLanguage ?: BuildScriptLanguage.Kts + require(subprojects.all { it.buildScriptLanguage == buildScriptLanguage }) { + "All subprojects in a fixture must use the same build script language." + } + val gradleRoot = if (parentDirectoryName.isNullOrBlank()) { + fixtureDir + } else { + fixtureDir.resolve(parentDirectoryName) + } + val fixtureAgpVersion = checkNotNull(System.getProperty("fixtureAgpVersion")) + val localBuildCacheUri = fixtureDir.resolve("local-cache").apply { mkdirs() }.toURI().toString() + val enableConfigurationCache = currentAgpSupportsConfigurationCache() + return GradleProject.Builder(gradleRoot, buildScriptLanguage.dslKind).apply { + withRootProject { + gradleProperties = GradleProperties.of( + "org.gradle.parallel=true", + "org.gradle.configureondemand=true", + "org.gradle.caching=true", + "org.gradle.configuration-cache=$enableConfigurationCache", + "org.gradle.isolated-projects=$enableConfigurationCache", + ) + withSettingsScript { + rootProjectName = "app-versioning-fixture" + additions = """ + buildCache { + local { + directory = "$localBuildCacheUri" + } + } + """.trimIndent() + } + } + subprojects.forEach { subproject -> + withSubproject(subproject.projectName) { + buildScript = subproject.buildScript(fixtureAgpVersion) + withFile("src/main/AndroidManifest.xml", subproject.manifestFileContent) + } + } + }.build() +} diff --git a/src/functionalTest/kotlin/io/github/reactivecircus/appversioning/fixtures/FixtureRunner.kt b/src/functionalTest/kotlin/io/github/reactivecircus/appversioning/fixtures/FixtureRunner.kt index 137094e..d04b05f 100644 --- a/src/functionalTest/kotlin/io/github/reactivecircus/appversioning/fixtures/FixtureRunner.kt +++ b/src/functionalTest/kotlin/io/github/reactivecircus/appversioning/fixtures/FixtureRunner.kt @@ -1,7 +1,7 @@ package io.github.reactivecircus.appversioning.fixtures +import com.autonomousapps.kit.GradleBuilder import org.gradle.testkit.runner.BuildResult -import org.gradle.testkit.runner.GradleRunner import org.gradle.util.GradleVersion import org.junit.rules.TemporaryFolder import java.io.File @@ -11,45 +11,30 @@ fun withFixtureRunner( subprojects: List, parentDirectoryName: String? = null, dryRun: Boolean = false, -) = FixtureRunner( - fixtureDir = fixtureDir, - subprojects = subprojects, - parentDirectoryName = parentDirectoryName, - dryRun = dryRun, -) +): FixtureRunner { + val project = createFixtureProject(fixtureDir.root, subprojects, parentDirectoryName) + project.write() + return FixtureRunner(project.rootDir, dryRun) +} class FixtureRunner( - fixtureDir: TemporaryFolder, - subprojects: List, - parentDirectoryName: String?, + private val gradleRoot: File, private val dryRun: Boolean, ) { - private val gradleRoot: File = if (parentDirectoryName.isNullOrBlank()) { - fixtureDir.root - } else { - fixtureDir.root.resolve(parentDirectoryName) - } - - init { - fixtureDir.buildFixture(gradleRoot, subprojects) - } - fun runAndCheckResult(vararg commands: String, action: BuildResult.() -> Unit) { - val buildResult = runner.withProjectDir(gradleRoot) - .withArguments(buildArguments(commands.toList())) - .withGradleVersion(GradleVersion.current().version) - .build() + val buildResult = runner(commands.toList()).build() action(buildResult) } fun runAndExpectFailure(vararg commands: String, action: BuildResult.() -> Unit) { - val buildResult = runner.withProjectDir(gradleRoot) - .withArguments(buildArguments(commands.toList())) - .withGradleVersion(GradleVersion.current().version) - .buildAndFail() + val buildResult = runner(commands.toList()).buildAndFail() action(buildResult) } + private fun runner(commands: List) = GradleBuilder + .runner(GradleVersion.current(), gradleRoot, *buildArguments(commands).toTypedArray()) + .withDebug(true) + private fun buildArguments(commands: List): List { val args = mutableListOf("--stacktrace", "--info") if (dryRun) { @@ -59,37 +44,3 @@ class FixtureRunner( return args } } - -private val runner = GradleRunner.create() - .withDebug(true) - -private fun TemporaryFolder.buildFixture(gradleRoot: File, subprojects: List) { - // settings.gradle - gradleRoot.resolve("settings.gradle.kts").also { it.parentFile.mkdirs() } - .writeText( - settingsFileContent( - localBuildCacheUri = root.resolve("local-cache").apply { mkdirs() }.toURI().toString(), - subprojects = subprojects - ) - ) - - // gradle.properties - gradleRoot.resolve("gradle.properties").also { it.parentFile.mkdir() } - .writeText(gradlePropertiesFileContent(enableConfigurationCache = currentAgpSupportsConfigurationCache())) - - // subprojects - subprojects.forEach { subproject -> - // build.gradle or build.gradle.kts - val buildFileName = if (subproject.buildScriptLanguage == BuildScriptLanguage.Kts) { - "build.gradle.kts" - } else { - "build.gradle" - } - gradleRoot.resolve("${subproject.projectName}/$buildFileName").also { it.parentFile.mkdirs() } - .writeText(subproject.buildFileContent) - - // AndroidManifest.xml - gradleRoot.resolve("${subproject.projectName}/src/main/AndroidManifest.xml").also { it.parentFile.mkdirs() } - .writeText(subproject.manifestFileContent) - } -} diff --git a/src/functionalTest/kotlin/io/github/reactivecircus/appversioning/fixtures/ProjectTemplates.kt b/src/functionalTest/kotlin/io/github/reactivecircus/appversioning/fixtures/ProjectTemplates.kt deleted file mode 100644 index 3a10b77..0000000 --- a/src/functionalTest/kotlin/io/github/reactivecircus/appversioning/fixtures/ProjectTemplates.kt +++ /dev/null @@ -1,213 +0,0 @@ -package io.github.reactivecircus.appversioning.fixtures - -import org.gradle.testkit.runner.internal.PluginUnderTestMetadataReading - -private val pluginClasspath: String by lazy { - PluginUnderTestMetadataReading.readImplementationClasspath() - .joinToString(",\n") { "\"${it.invariantSeparatorsPath}\"" } -} - -fun settingsFileContent( - localBuildCacheUri: String, - subprojects: List -) = """ - pluginManagement { - repositories { - mavenCentral() - google() - } - } - - buildscript { - dependencies { - classpath(files($pluginClasspath)) - } - } - - dependencyResolutionManagement { - repositories { - mavenCentral() - google() - } - } - - buildCache { - local { - directory = "$localBuildCacheUri" - } - } - - rootProject.name = "app-versioning-fixture" - - ${subprojects.map { it.projectName }.joinToString("\n") { "include(\":$it\")" }} -""".trimIndent() - -fun gradlePropertiesFileContent(enableConfigurationCache: Boolean): String { - return """ - org.gradle.parallel=true - org.gradle.configureondemand=true - org.gradle.caching=true - org.gradle.configuration-cache=$enableConfigurationCache - org.gradle.isolated-projects=$enableConfigurationCache - """.trimIndent() -} - -enum class BuildScriptLanguage { - Kts, - Groovy, -} - -sealed class AndroidProjectTemplate { - abstract val projectName: String - abstract val pluginExtension: String? - abstract val buildScriptLanguage: BuildScriptLanguage - abstract val flavors: List - - val buildFileContent: String get() = if (buildScriptLanguage == BuildScriptLanguage.Kts) { - ktsBuildFileContent - } else { - groovyBuildFileContent - } - - private val isAppProject = this is AppProjectTemplate - - private val ktsBuildFileContent: String - get() { - val flavorConfigs = if (flavors.isNotEmpty()) { - """ - flavorDimensions.add("environment") - productFlavors { - ${flavors.joinToString("\n") { "register(\"$it\") {}" }} - } - """.trimIndent() - } else { - "" - } - val abiConfigs = if (this is AppProjectTemplate) { - if (splitsApks) { - """ - splits { - abi { - isEnable = true - reset() - include("armeabi-v7a", "arm64-v8a", "x86", "x86_64") - isUniversalApk = $universalApk - } - } - """.trimIndent() - } else { - "" - } - } else { - "" - } - return """ - plugins { - id("com.android.${if (isAppProject) "application" else "library"}") - id("io.github.reactivecircus.app-versioning") - } - - ${pluginExtension ?: ""} - - android { - namespace = "$DEFAULT_PACKAGE_NAME.${projectName.replace("-", ".")}" - compileSdk = 36 - buildToolsVersion = "36.0.0" - defaultConfig { - minSdk = 21 - ${if (isAppProject) "targetSdk = 36" else ""} - } - - lint.checkReleaseBuilds = false - - $flavorConfigs - - $abiConfigs - } - """.trimIndent() - } - - private val groovyBuildFileContent: String - get() { - val flavorConfigs = if (flavors.isNotEmpty()) { - """ - flavorDimensions "environment" - productFlavors { - ${flavors.joinToString("\n") { "$it {}" }} - } - """.trimIndent() - } else { - "" - } - val abiConfigs = if (this is AppProjectTemplate) { - if (splitsApks) { - """ - splits { - abi { - enable true - reset() - include "armeabi-v7a", "arm64-v8a", "x86", "x86_64" - universalApk $universalApk - } - } - """.trimIndent() - } else { - "" - } - } else { - "" - } - return """ - plugins { - id 'com.android.${if (isAppProject) "application" else "library"}' - id 'io.github.reactivecircus.app-versioning' - } - - ${pluginExtension ?: ""} - - android { - namespace '$DEFAULT_PACKAGE_NAME.${projectName.replace("-", ".")}' - compileSdk 36 - buildToolsVersion "36.0.0" - defaultConfig { - minSdk 21 - ${if (isAppProject) "targetSdk 36" else ""} - } - - lint { - checkReleaseBuilds false - } - - $flavorConfigs - - $abiConfigs - } - """.trimIndent() - } - - val manifestFileContent: String - get() = """ - - - """.trimIndent() - - companion object { - private const val DEFAULT_PACKAGE_NAME = "io.github.reactivecircus.appversioning" - } -} - -class AppProjectTemplate( - override val projectName: String = "app", - override val pluginExtension: String? = null, - override val buildScriptLanguage: BuildScriptLanguage = BuildScriptLanguage.Kts, - override val flavors: List = emptyList(), - val splitsApks: Boolean = false, - val universalApk: Boolean = false, -) : AndroidProjectTemplate() - -class LibraryProjectTemplate( - override val projectName: String = "library", - override val pluginExtension: String? = null, - override val buildScriptLanguage: BuildScriptLanguage = BuildScriptLanguage.Kts, - override val flavors: List = emptyList() -) : AndroidProjectTemplate() diff --git a/src/functionalTest/kotlin/io/github/reactivecircus/appversioning/tasks/GenerateAppVersionInfoTest.kt b/src/functionalTest/kotlin/io/github/reactivecircus/appversioning/tasks/GenerateAppVersionInfoTest.kt index f94045a..6ac9e3b 100644 --- a/src/functionalTest/kotlin/io/github/reactivecircus/appversioning/tasks/GenerateAppVersionInfoTest.kt +++ b/src/functionalTest/kotlin/io/github/reactivecircus/appversioning/tasks/GenerateAppVersionInfoTest.kt @@ -307,7 +307,6 @@ class GenerateAppVersionInfoTest { val versionCodeFile = File(fixtureDir.root, "app/build/outputs/app_versioning/release/version_code.txt") val extensions = """ - import io.github.reactivecircus.appversioning.VersionCodeSpec val buildNumber = providers.gradleProperty("buildNumber").map(String::toInt).orElse(0) appVersioning { versionCode.set( @@ -322,7 +321,12 @@ class GenerateAppVersionInfoTest { withFixtureRunner( fixtureDir = fixtureDir, - subprojects = listOf(AppProjectTemplate(pluginExtension = extensions)) + subprojects = listOf( + AppProjectTemplate( + imports = listOf("io.github.reactivecircus.appversioning.VersionCodeSpec"), + pluginExtension = extensions, + ) + ) ).runAndCheckResult( "generateAppVersionInfoForRelease", "-PbuildNumber=78" @@ -794,8 +798,6 @@ class GenerateAppVersionInfoTest { ) val extensions = $$""" - import io.github.reactivecircus.appversioning.VersionCodeSpec - def buildNumber = providers.gradleProperty("buildNumber").map { it.toInteger() }.orElse(0) appVersioning { @@ -814,6 +816,7 @@ class GenerateAppVersionInfoTest { fixtureDir = fixtureDir, subprojects = listOf( AppProjectTemplate( + imports = listOf("io.github.reactivecircus.appversioning.VersionCodeSpec"), pluginExtension = extensions, buildScriptLanguage = BuildScriptLanguage.Groovy, ) From 9b25b261e063dc9127722d69d50e3a930f8f4516 Mon Sep 17 00:00:00 2001 From: Yang Date: Tue, 27 Oct 2026 18:56:47 +1100 Subject: [PATCH 3/3] Move all multi-line strings to `trimMargin`. --- .../AppVersioningPluginIntegrationTest.kt | 72 ++--- .../fixtures/AndroidProjectTemplate.kt | 122 ++++----- .../appversioning/fixtures/FixtureProject.kt | 12 +- .../tasks/GenerateAppVersionInfoTest.kt | 258 +++++++++--------- .../tasks/PrintAppVersionInfoTest.kt | 84 +++--- .../appversioning/VersionSpecs.kt | 16 +- .../tasks/GenerateAppVersionInfo.kt | 12 +- .../tasks/PrintAppVersionInfo.kt | 12 +- .../appversioning/VersionSpecsTest.kt | 16 +- 9 files changed, 302 insertions(+), 302 deletions(-) diff --git a/src/functionalTest/kotlin/io/github/reactivecircus/appversioning/AppVersioningPluginIntegrationTest.kt b/src/functionalTest/kotlin/io/github/reactivecircus/appversioning/AppVersioningPluginIntegrationTest.kt index 1c9895a..badbe4f 100644 --- a/src/functionalTest/kotlin/io/github/reactivecircus/appversioning/AppVersioningPluginIntegrationTest.kt +++ b/src/functionalTest/kotlin/io/github/reactivecircus/appversioning/AppVersioningPluginIntegrationTest.kt @@ -142,10 +142,10 @@ class AppVersioningPluginIntegrationTest( initGitRepo(fixtureDir.root) val extension = """ - appVersioning { - releaseBuildOnly.set(true) - } - """.trimIndent() + |appVersioning { + | releaseBuildOnly.set(true) + |} + """.trimMargin() withFixtureRunner( fixtureDir = fixtureDir, subprojects = listOf( @@ -178,10 +178,10 @@ class AppVersioningPluginIntegrationTest( initGitRepo(fixtureDir.root) val extension = """ - appVersioning { - enabled.set(false) - } - """.trimIndent() + |appVersioning { + | enabled.set(false) + |} + """.trimMargin() withFixtureRunner( fixtureDir = fixtureDir, subprojects = listOf( @@ -296,10 +296,10 @@ class AppVersioningPluginIntegrationTest( } val extension = """ - appVersioning { - enabled.set(false) - } - """.trimIndent() + |appVersioning { + | enabled.set(false) + |} + """.trimMargin() withFixtureRunner( fixtureDir = fixtureDir, subprojects = listOf( @@ -347,35 +347,35 @@ class AppVersioningPluginIntegrationTest( val extensionAppA = if (buildScriptLanguage == BuildScriptLanguage.Kts) { $$""" - appVersioning { - tagFilter.set("[0-9]*.[0-9]*.[0-9]*+appA") - versionCode.set { - tag.toSemVer().toVersionCode() + tag.commitsSinceLatestTag - } - versionName.set { - "appA-${tag.name}" - } - } - """.trimIndent() + |appVersioning { + | tagFilter.set("[0-9]*.[0-9]*.[0-9]*+appA") + | versionCode.set { + | tag.toSemVer().toVersionCode() + tag.commitsSinceLatestTag + | } + | versionName.set { + | "appA-${tag.name}" + | } + |} + """.trimMargin() } else { $$""" - appVersioning { - tagFilter.set("[0-9]*.[0-9]*.[0-9]*+appA") - versionCode { - tag.toSemVer().toVersionCode() + tag.commitsSinceLatestTag - } - versionName { - "appA-${tag.name}" - } - } - """.trimIndent() + |appVersioning { + | tagFilter.set("[0-9]*.[0-9]*.[0-9]*+appA") + | versionCode { + | tag.toSemVer().toVersionCode() + tag.commitsSinceLatestTag + | } + | versionName { + | "appA-${tag.name}" + | } + |} + """.trimMargin() } val extensionAppB = """ - appVersioning { - tagFilter.set("[0-9]*.[0-9]*.[0-9]*+appB") - } - """.trimIndent() + |appVersioning { + | tagFilter.set("[0-9]*.[0-9]*.[0-9]*+appB") + |} + """.trimMargin() val runner = withFixtureRunner( fixtureDir = fixtureDir, diff --git a/src/functionalTest/kotlin/io/github/reactivecircus/appversioning/fixtures/AndroidProjectTemplate.kt b/src/functionalTest/kotlin/io/github/reactivecircus/appversioning/fixtures/AndroidProjectTemplate.kt index c166c86..55bb4bc 100644 --- a/src/functionalTest/kotlin/io/github/reactivecircus/appversioning/fixtures/AndroidProjectTemplate.kt +++ b/src/functionalTest/kotlin/io/github/reactivecircus/appversioning/fixtures/AndroidProjectTemplate.kt @@ -34,94 +34,94 @@ sealed class AndroidProjectTemplate { private fun kotlinAndroidBlock(): String { val flavorConfigs = if (flavors.isNotEmpty()) { """ - flavorDimensions.add("environment") - productFlavors { - ${flavors.joinToString("\n") { "register(\"$it\") {}" }} - } - """.trimIndent() + |flavorDimensions.add("environment") + |productFlavors { + | ${flavors.joinToString("\n") { "register(\"$it\") {}" }} + |} + """.trimMargin() } else { "" } val abiConfigs = if (this is AppProjectTemplate && splitsApks) { """ - splits { - abi { - isEnable = true - reset() - include("armeabi-v7a", "arm64-v8a", "x86", "x86_64") - isUniversalApk = $universalApk - } - } - """.trimIndent() + |splits { + | abi { + | isEnable = true + | reset() + | include("armeabi-v7a", "arm64-v8a", "x86", "x86_64") + | isUniversalApk = $universalApk + | } + |} + """.trimMargin() } else { "" } return """ - android { - namespace = "$DEFAULT_PACKAGE_NAME.${projectName.replace("-", ".")}" - compileSdk = 36 - defaultConfig { - minSdk = 21 - ${if (this is AppProjectTemplate) "targetSdk = 36" else ""} - } - lint.checkReleaseBuilds = false - - $flavorConfigs - - $abiConfigs - } - """.trimIndent() + |android { + | namespace = "$DEFAULT_PACKAGE_NAME.${projectName.replace("-", ".")}" + | compileSdk = 36 + | defaultConfig { + | minSdk = 21 + | ${if (this is AppProjectTemplate) "targetSdk = 36" else ""} + | } + | lint.checkReleaseBuilds = false + | + | $flavorConfigs + | + | $abiConfigs + |} + """.trimMargin() } private fun groovyAndroidBlock(): String { val flavorConfigs = if (flavors.isNotEmpty()) { """ - flavorDimensions "environment" - productFlavors { - ${flavors.joinToString("\n") { "$it {}" }} - } - """.trimIndent() + |flavorDimensions "environment" + |productFlavors { + | ${flavors.joinToString("\n") { "$it {}" }} + |} + """.trimMargin() } else { "" } val abiConfigs = if (this is AppProjectTemplate && splitsApks) { """ - splits { - abi { - enable true - reset() - include "armeabi-v7a", "arm64-v8a", "x86", "x86_64" - universalApk $universalApk - } - } - """.trimIndent() + |splits { + | abi { + | enable true + | reset() + | include "armeabi-v7a", "arm64-v8a", "x86", "x86_64" + | universalApk $universalApk + | } + |} + """.trimMargin() } else { "" } return """ - android { - namespace '$DEFAULT_PACKAGE_NAME.${projectName.replace("-", ".")}' - compileSdk 36 - defaultConfig { - minSdk 21 - ${if (this is AppProjectTemplate) "targetSdk 36" else ""} - } - lint { - checkReleaseBuilds false - } - - $flavorConfigs - - $abiConfigs - } - """.trimIndent() + |android { + | namespace '$DEFAULT_PACKAGE_NAME.${projectName.replace("-", ".")}' + | compileSdk 36 + | defaultConfig { + | minSdk 21 + | ${if (this is AppProjectTemplate) "targetSdk 36" else ""} + | } + | lint { + | checkReleaseBuilds false + | } + | + | $flavorConfigs + | + | $abiConfigs + |} + """.trimMargin() } val manifestFileContent: String get() = """ - - - """.trimIndent() + | + | + """.trimMargin() companion object { private const val DEFAULT_PACKAGE_NAME = "io.github.reactivecircus.appversioning" diff --git a/src/functionalTest/kotlin/io/github/reactivecircus/appversioning/fixtures/FixtureProject.kt b/src/functionalTest/kotlin/io/github/reactivecircus/appversioning/fixtures/FixtureProject.kt index 9698224..60330a9 100644 --- a/src/functionalTest/kotlin/io/github/reactivecircus/appversioning/fixtures/FixtureProject.kt +++ b/src/functionalTest/kotlin/io/github/reactivecircus/appversioning/fixtures/FixtureProject.kt @@ -33,12 +33,12 @@ internal fun createFixtureProject( withSettingsScript { rootProjectName = "app-versioning-fixture" additions = """ - buildCache { - local { - directory = "$localBuildCacheUri" - } - } - """.trimIndent() + |buildCache { + | local { + | directory = "$localBuildCacheUri" + | } + |} + """.trimMargin() } } subprojects.forEach { subproject -> diff --git a/src/functionalTest/kotlin/io/github/reactivecircus/appversioning/tasks/GenerateAppVersionInfoTest.kt b/src/functionalTest/kotlin/io/github/reactivecircus/appversioning/tasks/GenerateAppVersionInfoTest.kt index 6ac9e3b..52cf189 100644 --- a/src/functionalTest/kotlin/io/github/reactivecircus/appversioning/tasks/GenerateAppVersionInfoTest.kt +++ b/src/functionalTest/kotlin/io/github/reactivecircus/appversioning/tasks/GenerateAppVersionInfoTest.kt @@ -40,10 +40,10 @@ class GenerateAppVersionInfoTest { @Test fun `GenerateAppVersionInfo fails when root Gradle project is not a git root directory and gitRootDirectory provided is not a git root directory`() { val extensions = """ - appVersioning { - gitRootDirectory.set(rootDir.resolve("../")) - } - """.trimIndent() + |appVersioning { + | gitRootDirectory.set(rootDir.resolve("../")) + |} + """.trimMargin() withFixtureRunner( fixtureDir = fixtureDir, @@ -64,10 +64,10 @@ class GenerateAppVersionInfoTest { @Test fun `GenerateAppVersionInfo fails when bareGitRepoDirectory provided is not a bare git repository`() { val extensions = """ - appVersioning { - bareGitRepoDirectory.set(rootDir.resolve("../")) - } - """.trimIndent() + |appVersioning { + | bareGitRepoDirectory.set(rootDir.resolve("../")) + |} + """.trimMargin() withFixtureRunner( fixtureDir = fixtureDir, @@ -96,10 +96,10 @@ class GenerateAppVersionInfoTest { val versionNameFile = File(fixtureDir.root, "android/app/build/outputs/app_versioning/release/version_name.txt") val extensions = """ - appVersioning { - gitRootDirectory.set(rootDir.resolve("../")) - } - """.trimIndent() + |appVersioning { + | gitRootDirectory.set(rootDir.resolve("../")) + |} + """.trimMargin() withFixtureRunner( fixtureDir = fixtureDir, @@ -124,11 +124,11 @@ class GenerateAppVersionInfoTest { val versionNameFile = File(fixtureDir.root, "app/build/outputs/app_versioning/release/version_name.txt") val extensions = """ - appVersioning { - gitRootDirectory.set(rootDir.resolve("non-existent")) - bareGitRepoDirectory.set(rootDir.resolve(".git")) - } - """.trimIndent() + |appVersioning { + | gitRootDirectory.set(rootDir.resolve("non-existent")) + | bareGitRepoDirectory.set(rootDir.resolve(".git")) + |} + """.trimMargin() withFixtureRunner( fixtureDir = fixtureDir, @@ -156,10 +156,10 @@ class GenerateAppVersionInfoTest { remoteGitRepo.tag(name = "1.2.3", message = "remote tag", commitId = commitId) val extension = """ - appVersioning { - fetchTagsWhenNoneExistsLocally.set(true) - } - """.trimIndent() + |appVersioning { + | fetchTagsWhenNoneExistsLocally.set(true) + |} + """.trimMargin() withFixtureRunner( fixtureDir = fixtureDir, @@ -230,9 +230,9 @@ class GenerateAppVersionInfoTest { assertTrue( output.contains( """ - Could not generate versionCode as "1.2" does not follow semantic versioning. - Please either ensure latest git tag follows semantic versioning, or provide a custom spec for generating versionCode using the `versionCode` property. - """.trimIndent() + |Could not generate versionCode as "1.2" does not follow semantic versioning. + |Please either ensure latest git tag follows semantic versioning, or provide a custom spec for generating versionCode using the `versionCode` property. + """.trimMargin() ) ) } @@ -255,11 +255,11 @@ class GenerateAppVersionInfoTest { assertTrue( output.contains( """ - Could not generate versionCode from "1.2.100" as the SemVer cannot be represented as an Integer. - This is usually because MAJOR or MINOR version is greater than 99, as by default maximum of 2 digits is allowed for MINOR and PATCH components of a SemVer tag. - Another reason might be that the overall positional notation of the SemVer (MAJOR * 10000 + MINOR * 100 + PATCH) is greater than the maximum value of an integer (2147483647). - As a workaround you can provide a custom spec for generating versionCode using the `versionCode` property. - """.trimIndent() + |Could not generate versionCode from "1.2.100" as the SemVer cannot be represented as an Integer. + |This is usually because MAJOR or MINOR version is greater than 99, as by default maximum of 2 digits is allowed for MINOR and PATCH components of a SemVer tag. + |Another reason might be that the overall positional notation of the SemVer (MAJOR * 10000 + MINOR * 100 + PATCH) is greater than the maximum value of an integer (2147483647). + |As a workaround you can provide a custom spec for generating versionCode using the `versionCode` property. + """.trimMargin() ) ) } @@ -284,12 +284,12 @@ class GenerateAppVersionInfoTest { assertTrue( output.contains( """ - No git tags found. Falling back to version code 0 and version name "". - If you want to fallback to the versionCode and versionName set via the DSL or manifest, or stop generating versionCode and versionName from Git tags: - appVersioning { - enabled.set(false) - } - """.trimIndent() + |No git tags found. Falling back to version code 0 and version name "". + |If you want to fallback to the versionCode and versionName set via the DSL or manifest, or stop generating versionCode and versionName from Git tags: + |appVersioning { + | enabled.set(false) + |} + """.trimMargin() ) ) assertEquals("0", versionCodeFile.readText()) @@ -307,17 +307,17 @@ class GenerateAppVersionInfoTest { val versionCodeFile = File(fixtureDir.root, "app/build/outputs/app_versioning/release/version_code.txt") val extensions = """ - val buildNumber = providers.gradleProperty("buildNumber").map(String::toInt).orElse(0) - appVersioning { - versionCode.set( - buildNumber.map { buildNum -> - VersionCodeSpec { - tag.toSemVer().toVersionCode() * 100 + buildNum - } - } - ) - } - """.trimIndent() + |val buildNumber = providers.gradleProperty("buildNumber").map(String::toInt).orElse(0) + |appVersioning { + | versionCode.set( + | buildNumber.map { buildNum -> + | VersionCodeSpec { + | tag.toSemVer().toVersionCode() * 100 + buildNum + | } + | } + | ) + |} + """.trimMargin() withFixtureRunner( fixtureDir = fixtureDir, @@ -343,12 +343,12 @@ class GenerateAppVersionInfoTest { } val extensions = """ - appVersioning { - versionCode.set { - tag.toSemVer().toVersionCode() * 100 - } - } - """.trimIndent() + |appVersioning { + | versionCode.set { + | tag.toSemVer().toVersionCode() * 100 + | } + |} + """.trimMargin() withFixtureRunner( fixtureDir = fixtureDir, @@ -371,10 +371,10 @@ class GenerateAppVersionInfoTest { val versionNameFile = File(fixtureDir.root, "app/build/outputs/app_versioning/release/version_name.txt") val extensions = """ - appVersioning { - versionCode.set { 0 } - } - """.trimIndent() + |appVersioning { + | versionCode.set { 0 } + |} + """.trimMargin() val runner = withFixtureRunner( fixtureDir = fixtureDir, @@ -416,12 +416,12 @@ class GenerateAppVersionInfoTest { val versionNameFile = File(fixtureDir.root, "app/build/outputs/app_versioning/release/version_name.txt") val extensions = $$""" - appVersioning { - versionName.set { - "Version $tag" - } - } - """.trimIndent() + |appVersioning { + | versionName.set { + | "Version $tag" + | } + |} + """.trimMargin() withFixtureRunner( fixtureDir = fixtureDir, @@ -458,13 +458,13 @@ class GenerateAppVersionInfoTest { ) val extensions = """ - appVersioning { - versionCode.set { - val offset = if (variant.flavorName == "paid") 1 else 0 - tag.toSemVer().toVersionCode() * 100 + offset - } - } - """.trimIndent() + |appVersioning { + | versionCode.set { + | val offset = if (variant.flavorName == "paid") 1 else 0 + | tag.toSemVer().toVersionCode() * 100 + offset + | } + |} + """.trimMargin() val flavors = listOf("free", "paid") val runner = withFixtureRunner( @@ -522,13 +522,13 @@ class GenerateAppVersionInfoTest { ) val extensions = $$""" - appVersioning { - versionName.set { - val suffix = if (!variant.isReleaseBuild) " (${variant.variantName})" else "" - "Version $tag$suffix" - } - } - """.trimIndent() + |appVersioning { + | versionName.set { + | val suffix = if (!variant.isReleaseBuild) " (${variant.variantName})" else "" + | "Version $tag$suffix" + | } + |} + """.trimMargin() val flavors = listOf("free", "paid") val runner = withFixtureRunner( @@ -579,22 +579,22 @@ class GenerateAppVersionInfoTest { val tagFilterAppC = "[0-9]*.[0-9]*.[0-9]*+appC" val extensionsAppA = """ - appVersioning { - tagFilter.set("$tagFilterAppA") - } - """.trimIndent() + |appVersioning { + | tagFilter.set("$tagFilterAppA") + |} + """.trimMargin() val extensionsAppB = """ - appVersioning { - tagFilter.set("$tagFilterAppB") - } - """.trimIndent() + |appVersioning { + | tagFilter.set("$tagFilterAppB") + |} + """.trimMargin() val extensionsAppC = """ - appVersioning { - tagFilter.set("$tagFilterAppC") - } - """.trimIndent() + |appVersioning { + | tagFilter.set("$tagFilterAppC") + |} + """.trimMargin() val runner = withFixtureRunner( fixtureDir = fixtureDir, @@ -742,16 +742,16 @@ class GenerateAppVersionInfoTest { ) val extensions = $$""" - appVersioning { - versionCode { - tag.toSemVer().toVersionCode() + tag.commitsSinceLatestTag - } - versionName { - def suffix = variant.debugBuild ? " (${variant.variantName})" : "" - "Version ${tag.name}${suffix}" - } - } - """.trimIndent() + |appVersioning { + | versionCode { + | tag.toSemVer().toVersionCode() + tag.commitsSinceLatestTag + | } + | versionName { + | def suffix = variant.debugBuild ? " (${variant.variantName})" : "" + | "Version ${tag.name}${suffix}" + | } + |} + """.trimMargin() val runner = withFixtureRunner( fixtureDir = fixtureDir, @@ -798,19 +798,19 @@ class GenerateAppVersionInfoTest { ) val extensions = $$""" - def buildNumber = providers.gradleProperty("buildNumber").map { it.toInteger() }.orElse(0) - - appVersioning { - versionCode.set( - buildNumber.map { buildNum -> - { tag.toSemVer().toVersionCode() * 100 + buildNum } as VersionCodeSpec - } - ) - versionName { - "Version ${tag.name}" - } - } - """.trimIndent() + |def buildNumber = providers.gradleProperty("buildNumber").map { it.toInteger() }.orElse(0) + | + |appVersioning { + | versionCode.set( + | buildNumber.map { buildNum -> + | { tag.toSemVer().toVersionCode() * 100 + buildNum } as VersionCodeSpec + | } + | ) + | versionName { + | "Version ${tag.name}" + | } + |} + """.trimMargin() val runner = withFixtureRunner( fixtureDir = fixtureDir, @@ -869,15 +869,15 @@ class GenerateAppVersionInfoTest { } val extensions = $$""" - appVersioning { - versionCode.set { - tag.toSemVer().toVersionCode() + tag.commitsSinceLatestTag - } - versionName.set { - "Version $tag" - } - } - """.trimIndent() + |appVersioning { + | versionCode.set { + | tag.toSemVer().toVersionCode() + tag.commitsSinceLatestTag + | } + | versionName.set { + | "Version $tag" + | } + |} + """.trimMargin() val runner = withFixtureRunner( fixtureDir = fixtureDir, @@ -937,15 +937,15 @@ class GenerateAppVersionInfoTest { } val extensions = $$""" - appVersioning { - versionCode.set { - tag.toSemVer().toVersionCode() + tag.commitsSinceLatestTag - } - versionName.set { - "Version $tag" - } - } - """.trimIndent() + |appVersioning { + | versionCode.set { + | tag.toSemVer().toVersionCode() + tag.commitsSinceLatestTag + | } + | versionName.set { + | "Version $tag" + | } + |} + """.trimMargin() val runner = withFixtureRunner( fixtureDir = fixtureDir, diff --git a/src/functionalTest/kotlin/io/github/reactivecircus/appversioning/tasks/PrintAppVersionInfoTest.kt b/src/functionalTest/kotlin/io/github/reactivecircus/appversioning/tasks/PrintAppVersionInfoTest.kt index 4745bcf..daea2a4 100644 --- a/src/functionalTest/kotlin/io/github/reactivecircus/appversioning/tasks/PrintAppVersionInfoTest.kt +++ b/src/functionalTest/kotlin/io/github/reactivecircus/appversioning/tasks/PrintAppVersionInfoTest.kt @@ -44,12 +44,12 @@ class PrintAppVersionInfoTest { assertTrue( output.contains( """ - App version info generated by Android App Versioning plugin: - Project: ":app" - Build variant: prodRelease - versionCode: 10203 - versionName: "1.2.3" - """.trimIndent() + |App version info generated by Android App Versioning plugin: + |Project: ":app" + |Build variant: prodRelease + |versionCode: 10203 + |versionName: "1.2.3" + """.trimMargin() ) ) } @@ -95,26 +95,26 @@ class PrintAppVersionInfoTest { AppProjectTemplate( projectName = "app-a", pluginExtension = """ - appVersioning { - tagFilter.set("[0-9]*.[0-9]*.[0-9]*+appA") - } - """.trimIndent() + |appVersioning { + | tagFilter.set("[0-9]*.[0-9]*.[0-9]*+appA") + |} + """.trimMargin() ), AppProjectTemplate( projectName = "app-b", pluginExtension = """ - appVersioning { - tagFilter.set("[0-9]*.[0-9]*.[0-9]*+appB") - } - """.trimIndent() + |appVersioning { + | tagFilter.set("[0-9]*.[0-9]*.[0-9]*+appB") + |} + """.trimMargin() ), AppProjectTemplate( projectName = "app-c", pluginExtension = """ - appVersioning { - tagFilter.set("[0-9]*.[0-9]*.[0-9]*+appC") - } - """.trimIndent() + |appVersioning { + | tagFilter.set("[0-9]*.[0-9]*.[0-9]*+appC") + |} + """.trimMargin() ) ) ) @@ -134,12 +134,12 @@ class PrintAppVersionInfoTest { assertTrue( output.contains( """ - App version info generated by Android App Versioning plugin: - Project: ":app-a" - Build variant: release - versionCode: 100 - versionName: "0.1.0+appA" - """.trimIndent() + |App version info generated by Android App Versioning plugin: + |Project: ":app-a" + |Build variant: release + |versionCode: 100 + |versionName: "0.1.0+appA" + """.trimMargin() ) ) @@ -147,12 +147,12 @@ class PrintAppVersionInfoTest { assertTrue( output.contains( """ - App version info generated by Android App Versioning plugin: - Project: ":app-b" - Build variant: release - versionCode: 10203 - versionName: "1.2.3+appB" - """.trimIndent() + |App version info generated by Android App Versioning plugin: + |Project: ":app-b" + |Build variant: release + |versionCode: 10203 + |versionName: "1.2.3+appB" + """.trimMargin() ) ) @@ -191,12 +191,12 @@ class PrintAppVersionInfoTest { assertTrue( output.contains( """ - App version info generated by Android App Versioning plugin: - Project: ":app" - Build variant: release - versionCode: 10203 - versionName: "1.2.3" - """.trimIndent() + |App version info generated by Android App Versioning plugin: + |Project: ":app" + |Build variant: release + |versionCode: 10203 + |versionName: "1.2.3" + """.trimMargin() ) ) } @@ -209,12 +209,12 @@ class PrintAppVersionInfoTest { assertTrue( output.contains( """ - App version info generated by Android App Versioning plugin: - Project: ":app" - Build variant: release - versionCode: 10203 - versionName: "1.2.3" - """.trimIndent() + |App version info generated by Android App Versioning plugin: + |Project: ":app" + |Build variant: release + |versionCode: 10203 + |versionName: "1.2.3" + """.trimMargin() ) ) } diff --git a/src/main/kotlin/io/github/reactivecircus/appversioning/VersionSpecs.kt b/src/main/kotlin/io/github/reactivecircus/appversioning/VersionSpecs.kt index 88a598d..ab76b11 100644 --- a/src/main/kotlin/io/github/reactivecircus/appversioning/VersionSpecs.kt +++ b/src/main/kotlin/io/github/reactivecircus/appversioning/VersionSpecs.kt @@ -38,20 +38,20 @@ private fun GitTag.toVersionCodeBySemVer(): Int { val prefix = if (name.startsWith("v")) "v" else "" val semVer = checkNotNull(runCatching { toSemVer(prefix = prefix) }.getOrNull()) { """ - Could not generate versionCode as "$name" does not follow semantic versioning. - Please either ensure latest git tag follows semantic versioning, or provide a custom spec for generating versionCode using the `versionCode` property. - """.trimIndent() + |Could not generate versionCode as "$name" does not follow semantic versioning. + |Please either ensure latest git tag follows semantic versioning, or provide a custom spec for generating versionCode using the `versionCode` property. + """.trimMargin() } return runCatching { semVer.toVersionCode() }.getOrElse { throw IllegalStateException( """ - Could not generate versionCode from "$name" as the SemVer cannot be represented as an Integer. - This is usually because MAJOR or MINOR version is greater than 99, as by default maximum of 2 digits is allowed for MINOR and PATCH components of a SemVer tag. - Another reason might be that the overall positional notation of the SemVer (MAJOR * 10000 + MINOR * 100 + PATCH) is greater than the maximum value of an integer (2147483647). - As a workaround you can provide a custom spec for generating versionCode using the `versionCode` property. - """.trimIndent(), + |Could not generate versionCode from "$name" as the SemVer cannot be represented as an Integer. + |This is usually because MAJOR or MINOR version is greater than 99, as by default maximum of 2 digits is allowed for MINOR and PATCH components of a SemVer tag. + |Another reason might be that the overall positional notation of the SemVer (MAJOR * 10000 + MINOR * 100 + PATCH) is greater than the maximum value of an integer (2147483647). + |As a workaround you can provide a custom spec for generating versionCode using the `versionCode` property. + """.trimMargin(), it, ) } diff --git a/src/main/kotlin/io/github/reactivecircus/appversioning/tasks/GenerateAppVersionInfo.kt b/src/main/kotlin/io/github/reactivecircus/appversioning/tasks/GenerateAppVersionInfo.kt index 9630912..8ded0b5 100644 --- a/src/main/kotlin/io/github/reactivecircus/appversioning/tasks/GenerateAppVersionInfo.kt +++ b/src/main/kotlin/io/github/reactivecircus/appversioning/tasks/GenerateAppVersionInfo.kt @@ -97,12 +97,12 @@ abstract class GenerateAppVersionInfo : DefaultTask() { } ?: run { logger.warn( """ - No git tags found. Falling back to version code $VERSION_CODE_FALLBACK and version name "$VERSION_NAME_FALLBACK". - If you want to fallback to the versionCode and versionName set via the DSL or manifest, or stop generating versionCode and versionName from Git tags: - appVersioning { - enabled.set(false) - } - """.trimIndent() + |No git tags found. Falling back to version code $VERSION_CODE_FALLBACK and version name "$VERSION_NAME_FALLBACK". + |If you want to fallback to the versionCode and versionName set via the DSL or manifest, or stop generating versionCode and versionName from Git tags: + |appVersioning { + | enabled.set(false) + |} + """.trimMargin() ) versionCodeFile.get().asFile.writeText(VERSION_CODE_FALLBACK.toString()) versionNameFile.get().asFile.writeText(VERSION_NAME_FALLBACK) diff --git a/src/main/kotlin/io/github/reactivecircus/appversioning/tasks/PrintAppVersionInfo.kt b/src/main/kotlin/io/github/reactivecircus/appversioning/tasks/PrintAppVersionInfo.kt index 2d28d27..e2cb61f 100644 --- a/src/main/kotlin/io/github/reactivecircus/appversioning/tasks/PrintAppVersionInfo.kt +++ b/src/main/kotlin/io/github/reactivecircus/appversioning/tasks/PrintAppVersionInfo.kt @@ -31,12 +31,12 @@ abstract class PrintAppVersionInfo : DefaultTask() { if (versionCodeFile.isPresent && versionNameFile.isPresent) { logger.quiet( """ - App version info generated by Android App Versioning plugin: - Project: ":${projectName.get()}" - Build variant: ${buildVariantName.get()} - versionCode: ${versionCodeFile.get().asFile.readText().trim().toInt()} - versionName: "${versionNameFile.get().asFile.readText().trim()}" - """.trimIndent() + |App version info generated by Android App Versioning plugin: + |Project: ":${projectName.get()}" + |Build variant: ${buildVariantName.get()} + |versionCode: ${versionCodeFile.get().asFile.readText().trim().toInt()} + |versionName: "${versionNameFile.get().asFile.readText().trim()}" + """.trimMargin() ) } else { logger.warn( diff --git a/src/test/kotlin/io/github/reactivecircus/appversioning/VersionSpecsTest.kt b/src/test/kotlin/io/github/reactivecircus/appversioning/VersionSpecsTest.kt index c144b22..c56a9c9 100644 --- a/src/test/kotlin/io/github/reactivecircus/appversioning/VersionSpecsTest.kt +++ b/src/test/kotlin/io/github/reactivecircus/appversioning/VersionSpecsTest.kt @@ -25,9 +25,9 @@ class VersionSpecsTest { } assertEquals( """ - Could not generate versionCode as "1.2" does not follow semantic versioning. - Please either ensure latest git tag follows semantic versioning, or provide a custom spec for generating versionCode using the `versionCode` property. - """.trimIndent(), + |Could not generate versionCode as "1.2" does not follow semantic versioning. + |Please either ensure latest git tag follows semantic versioning, or provide a custom spec for generating versionCode using the `versionCode` property. + """.trimMargin(), exception.message ) } @@ -39,11 +39,11 @@ class VersionSpecsTest { } assertEquals( """ - Could not generate versionCode from "1.2.100" as the SemVer cannot be represented as an Integer. - This is usually because MAJOR or MINOR version is greater than 99, as by default maximum of 2 digits is allowed for MINOR and PATCH components of a SemVer tag. - Another reason might be that the overall positional notation of the SemVer (MAJOR * 10000 + MINOR * 100 + PATCH) is greater than the maximum value of an integer (2147483647). - As a workaround you can provide a custom spec for generating versionCode using the `versionCode` property. - """.trimIndent(), + |Could not generate versionCode from "1.2.100" as the SemVer cannot be represented as an Integer. + |This is usually because MAJOR or MINOR version is greater than 99, as by default maximum of 2 digits is allowed for MINOR and PATCH components of a SemVer tag. + |Another reason might be that the overall positional notation of the SemVer (MAJOR * 10000 + MINOR * 100 + PATCH) is greater than the maximum value of an integer (2147483647). + |As a workaround you can provide a custom spec for generating versionCode using the `versionCode` property. + """.trimMargin(), exception.message ) }