Skip to content

Commit

Permalink
Remove dependency to Android Gradle Plugin in buildscripts (#66)
Browse files Browse the repository at this point in the history
  • Loading branch information
moallemi authored Dec 12, 2022
1 parent f991e20 commit f8be1ea
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 11 deletions.
2 changes: 1 addition & 1 deletion gradle/publish.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

project.description = "Generate Android version code and version name automatically from git tags, date,... ."
project.group = "me.moallemi.gradle"
project.version = "2.0.0"
project.version = "2.0.1"

project.ext {
pluginId = 'me.moallemi.advanced-build-version'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,7 @@ import org.gradle.util.GradleVersion

fun checkAndroidGradleVersion(project: Project) {
val androidGradlePlugin = getAndroidPlugin(project)
if (androidGradlePlugin == null) {
throw IllegalStateException(
"The Android Gradle plugin not found. " +
"gradle-advanced-build-version only works with Android gradle library."
)
} else if (!checkAndroidVersion(androidGradlePlugin.version)) {
if (androidGradlePlugin != null && !checkAndroidVersion(androidGradlePlugin.version)) {
throw GradleException("gradle-advanced-build-version does not support Android Gradle plugin ${androidGradlePlugin.version}")
} else if (!project.plugins.hasPlugin("com.android.application")) {
throw GradleException("gradle-advanced-build-version only works with android application modules")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ class AdvancedBuildVersionPluginSetUpIntegrationTest {
}
assertThat(
exception.message,
containsString("gradle-advanced-build-version only works with Android gradle library.")
containsString("gradle-advanced-build-version only works with android application modules")
)
}

Expand Down Expand Up @@ -172,6 +172,49 @@ class AdvancedBuildVersionPluginSetUpIntegrationTest {
assertThat(output.output, containsString("Applying Advanced Build Version Plugin"))
}

@Test
fun `plugin works with android application plugin applied`() {
publishToLocalMaven()

File("src/test/test-data", "app").copyRecursively(testProjectRoot.root)

writeBuildGradle(
"""
buildscript {
repositories {
google()
jcenter()
mavenLocal()
}
}
plugins {
id("com.android.application")
id("$PLUGIN_ID")
}
android {
compileSdkVersion 29
buildToolsVersion "29.0.2"
defaultConfig {
applicationId "com.example.myapplication"
minSdkVersion 14
targetSdkVersion 22
versionCode 1
versionName "1.0"
}
}
""".trimIndent()
)

val output = GradleRunner.create()
.withProjectDir(testProjectRoot.root)
.withPluginClasspath()
.withGradleVersion(CURRENT_GRADLE_VERSION)
.build()
assertThat(output.output, containsString("Applying Advanced Build Version Plugin"))
}

@Test
fun `build fails with unsupported android gradle plugin 3_1_0`() {
publishToLocalMaven()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,13 @@ class CompatibilityManagerKtTest {
every { iterator().hasNext() } returns false
}

val exception = assertThrows(IllegalStateException::class.java) {
every { project.plugins.hasPlugin(any<String>()) } returns false

val exception = assertThrows(GradleException::class.java) {
checkAndroidGradleVersion(project)
}
assertEquals(
exception.message, "The Android Gradle plugin not found. " +
"gradle-advanced-build-version only works with Android gradle library."
exception.message, "gradle-advanced-build-version only works with android application modules"
)
}

Expand Down

0 comments on commit f8be1ea

Please sign in to comment.