-
Notifications
You must be signed in to change notification settings - Fork 162
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix detection of android kotlin source directories in AGP >= 7
increase maximum gradle version to 8.5 increase maximum ktlint version to 1.1.0 increase maximum kotlin version to 1.9.21 fixes #702 based on work in #703
- Loading branch information
1 parent
a826dcd
commit caf668f
Showing
13 changed files
with
214 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
11.6.1 | ||
12.0.3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package org.assertj.core.api | ||
|
||
import org.assertj.core.internal.Objects | ||
import org.gradle.testkit.runner.BuildTask | ||
import org.gradle.testkit.runner.TaskOutcome | ||
|
||
fun ObjectAssert<BuildTask?>.hasOutcome(outcome: TaskOutcome) { | ||
Objects.instance().assertNotNull(this.info, this.actual) | ||
Objects.instance().assertEqual(this.info, this.actual!!.outcome, outcome) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
89 changes: 89 additions & 0 deletions
89
plugin/src/test/kotlin/org/jlleitschuh/gradle/ktlint/android/KtlintPluginAndroidTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
package org.jlleitschuh.gradle.ktlint.android | ||
|
||
import net.swiftzer.semver.SemVer | ||
import org.assertj.core.api.Assertions.assertThat | ||
import org.assertj.core.api.hasOutcome | ||
import org.gradle.testkit.runner.TaskOutcome | ||
import org.gradle.util.GradleVersion | ||
import org.jlleitschuh.gradle.ktlint.AbstractPluginTest | ||
import org.jlleitschuh.gradle.ktlint.CHECK_PARENT_TASK_NAME | ||
import org.jlleitschuh.gradle.ktlint.testdsl.TestVersions | ||
import org.jlleitschuh.gradle.ktlint.testdsl.androidProjectSetup | ||
import org.jlleitschuh.gradle.ktlint.testdsl.build | ||
import org.jlleitschuh.gradle.ktlint.testdsl.project | ||
import org.junit.jupiter.params.ParameterizedTest | ||
import org.junit.jupiter.params.provider.EnumSource | ||
|
||
class KtlintPluginAndroidTest : AbstractPluginTest() { | ||
|
||
@ParameterizedTest | ||
@EnumSource(AndroidTestInput::class) | ||
fun `ktlint pass src java`(input: AndroidTestInput) { | ||
project( | ||
input.gradleVersion, | ||
projectSetup = androidProjectSetup(input.agpVersion, input.kotlinVersion, input.ktlintVersion) | ||
) { | ||
withCleanSources("src/main/java/CleanSource.kt") | ||
build(CHECK_PARENT_TASK_NAME) { | ||
assertThat(task(":$mainSourceSetCheckTaskName")).hasOutcome(TaskOutcome.SUCCESS) | ||
assertThat(task(":$kotlinScriptCheckTaskName")).hasOutcome(TaskOutcome.SUCCESS) | ||
assertThat(task(":$CHECK_PARENT_TASK_NAME")).hasOutcome(TaskOutcome.SUCCESS) | ||
} | ||
} | ||
} | ||
|
||
@ParameterizedTest | ||
@EnumSource(AndroidTestInput::class) | ||
fun `ktlint pass src kotlin`(input: AndroidTestInput) { | ||
project( | ||
input.gradleVersion, | ||
projectSetup = androidProjectSetup(input.agpVersion, input.kotlinVersion, input.ktlintVersion) | ||
) { | ||
withCleanSources("src/main/kotlin/CleanSource.kt") | ||
if (SemVer.parse(input.agpVersion) < SemVer(7)) { | ||
build(CHECK_PARENT_TASK_NAME) { | ||
assertThat(output).contains("In AGP <7 kotlin source directories are not auto-detected.") | ||
assertThat(task(":$mainSourceSetCheckTaskName")).hasOutcome(TaskOutcome.SKIPPED) | ||
assertThat(task(":$kotlinScriptCheckTaskName")).hasOutcome(TaskOutcome.SUCCESS) | ||
assertThat(task(":$CHECK_PARENT_TASK_NAME")).hasOutcome(TaskOutcome.SUCCESS) | ||
} | ||
} else { | ||
build(CHECK_PARENT_TASK_NAME) { | ||
assertThat(task(":$mainSourceSetCheckTaskName")).hasOutcome(TaskOutcome.SUCCESS) | ||
assertThat(task(":$kotlinScriptCheckTaskName")).hasOutcome(TaskOutcome.SUCCESS) | ||
assertThat(task(":$CHECK_PARENT_TASK_NAME")).hasOutcome(TaskOutcome.SUCCESS) | ||
} | ||
} | ||
} | ||
} | ||
|
||
enum class AndroidTestInput( | ||
val gradleVersion: GradleVersion, | ||
val agpVersion: String, | ||
val kotlinVersion: String, | ||
val ktlintVersion: String? =null | ||
) { | ||
MIN( | ||
GradleVersion.version(TestVersions.minSupportedGradleVersion), | ||
TestVersions.minAgpVersion, | ||
"1.5.20", // AGP 4.1 requires kotlin 1.5.20 | ||
"0.47.1" // old AGP doesn't properly set variant info which ktlint >= 1 requires | ||
), | ||
GRADLE_7_5_AGP_7_4( | ||
GradleVersion.version("7.5"), // AGP 7.4 requires Gradle 7.5 | ||
"7.4.2", | ||
"1.5.20", // AGP 4.1 requires kotlin 1.5.20 | ||
"0.47.1" // old AGP doesn't properly set variant info which ktlint >= 1 requires | ||
), | ||
MAX_GRADLE_MIN_AGP( | ||
GradleVersion.version(TestVersions.maxSupportedGradleVersion), | ||
TestVersions.minAgpVersion, | ||
"1.5.20", // AGP 4.1 requires kotlin 1.5.20 | ||
), | ||
MAX( | ||
GradleVersion.version(TestVersions.maxSupportedGradleVersion), | ||
TestVersions.maxAgpVersion, | ||
TestVersions.maxSupportedKotlinPluginVersion | ||
) | ||
} | ||
} |
76 changes: 76 additions & 0 deletions
76
plugin/src/test/kotlin/org/jlleitschuh/gradle/ktlint/testdsl/AndroidSetup.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
package org.jlleitschuh.gradle.ktlint.testdsl | ||
|
||
import net.swiftzer.semver.SemVer | ||
import java.io.File | ||
|
||
fun androidProjectSetup( | ||
agpVersion: String, | ||
kotlinPluginVersion: String, | ||
ktlintVersion: String? = null | ||
): (File) -> Unit = { | ||
val ktLintOverride = ktlintVersion?.let { "ktlint { version = \"$it\" }\n" } ?: "" | ||
val setNamespace = if ((SemVer.parse(agpVersion) >= SemVer(7))) { | ||
" namespace = \"com.example.myapp\"\n" | ||
} else { | ||
"" | ||
} | ||
//language=Groovy | ||
it.resolve("build.gradle").writeText( | ||
""" | ||
|plugins { | ||
| id("com.android.application") | ||
| id("org.jetbrains.kotlin.android") | ||
| id("org.jlleitschuh.gradle.ktlint") | ||
|} | ||
| | ||
|repositories { | ||
| mavenCentral() | ||
|} | ||
|android { | ||
| compileSdk = 33 | ||
|$setNamespace} | ||
|$ktLintOverride | ||
""".trimMargin() | ||
) | ||
|
||
// before 4.2.0, AGP did not properly publish metadata for id resolution | ||
val oldAgpHack = if ((SemVer.parse(agpVersion) < SemVer(4, 2))) { | ||
""" | ||
| resolutionStrategy { | ||
| eachPlugin { | ||
| when (requested.id.id) { | ||
| "com.android.application" -> useModule("com.android.tools.build:gradle:$agpVersion") | ||
| } | ||
| } | ||
| } | ||
| | ||
""".trimMargin() | ||
} else { | ||
"" | ||
} | ||
val newAgp = if ((SemVer.parse(agpVersion) < SemVer(4, 2))) { | ||
"" | ||
} else { | ||
" id(\"com.android.application\") version \"$agpVersion\"\n " | ||
} | ||
|
||
//language=Groovy | ||
it.resolve("settings.gradle.kts").writeText( | ||
""" | ||
|pluginManagement { | ||
| repositories { | ||
| mavenLocal() | ||
| gradlePluginPortal() | ||
| google() | ||
| mavenCentral() | ||
| } | ||
| | ||
| plugins { | ||
| id("org.jetbrains.kotlin.android") version("$kotlinPluginVersion") | ||
| id("org.jlleitschuh.gradle.ktlint") version("${TestVersions.pluginVersion}") | ||
| $newAgp} | ||
|$oldAgpHack} | ||
| | ||
""".trimMargin() | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters