Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove dependency to Android Gradle Plugin in build scripts #66

Merged
merged 1 commit into from
Dec 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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