Skip to content

Commit 56045d7

Browse files
authored
AGP 8.12.1, 9.0.0 Alpha 2 & address Kotlin bundling fix for functional tests (#381)
1 parent 61379a1 commit 56045d7

File tree

6 files changed

+44
-28
lines changed

6 files changed

+44
-28
lines changed

build-logic/src/main/kotlin/Environment.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ enum class SupportedAgp(
1919
AGP_8_9("8.9.3", gradle = "8.11.1"),
2020
AGP_8_10("8.10.1", gradle = "8.11.1"),
2121
AGP_8_11("8.11.1", gradle = "8.13"),
22-
AGP_8_12("8.12.0", gradle = "8.13"),
22+
AGP_8_12("8.12.1", gradle = "8.13"),
2323
AGP_8_13("8.13.0-rc01", gradle = "8.13"),
24-
AGP_9_0("9.0.0-alpha01", gradle = "9.0.0"),
24+
AGP_9_0("9.0.0-alpha02", gradle = "9.0.0"),
2525
;
2626

2727
companion object {

build-logic/src/main/kotlin/Tasks.kt

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -85,28 +85,30 @@ fun Project.configureTestResources() {
8585
val agpDependency = libs.plugins.android(plugin).substringBeforeLast(":")
8686
project.dependencies.add(this.name, "${agpDependency}:${plugin.version}")
8787

88-
// Add the Kotlin Gradle Plugin explicitly,
88+
// For Android Gradle Plugins before 9.x, add the Kotlin Gradle Plugin explicitly,
8989
// acknowledging the different plugin variants introduced in Kotlin 1.7.
90-
// Acknowleding the minimum required Gradle version, request the correct variant for KGP
90+
// Acknowledging the minimum required Gradle version, request the correct variant for KGP
9191
// (see https://docs.gradle.org/current/userguide/implementing_gradle_plugins.html#plugin-with-variants)
92-
project.dependencies.add(
93-
this.name,
94-
"org.jetbrains.kotlin:kotlin-gradle-plugin:${libs.versions.kotlin}"
95-
).apply {
96-
with(this as ExternalModuleDependency) {
97-
attributes {
98-
attribute(
99-
TARGET_JVM_ENVIRONMENT_ATTRIBUTE,
100-
objects.named(TargetJvmEnvironment::class.java, STANDARD_JVM)
101-
)
102-
attribute(
103-
USAGE_ATTRIBUTE,
104-
objects.named(Usage::class.java, JAVA_RUNTIME)
105-
)
106-
attribute(
107-
GRADLE_PLUGIN_API_VERSION_ATTRIBUTE,
108-
objects.named(GradlePluginApiVersion::class.java, minimumGradleVersion)
109-
)
92+
if (plugin < SupportedAgp.AGP_9_0) {
93+
project.dependencies.add(
94+
this.name,
95+
"org.jetbrains.kotlin:kotlin-gradle-plugin:${libs.versions.kotlin}"
96+
).apply {
97+
with(this as ExternalModuleDependency) {
98+
attributes {
99+
attribute(
100+
TARGET_JVM_ENVIRONMENT_ATTRIBUTE,
101+
objects.named(TargetJvmEnvironment::class.java, STANDARD_JVM)
102+
)
103+
attribute(
104+
USAGE_ATTRIBUTE,
105+
objects.named(Usage::class.java, JAVA_RUNTIME)
106+
)
107+
attribute(
108+
GRADLE_PLUGIN_API_VERSION_ATTRIBUTE,
109+
objects.named(GradlePluginApiVersion::class.java, minimumGradleVersion)
110+
)
111+
}
110112
}
111113
}
112114
}
@@ -128,12 +130,12 @@ fun Project.configureTestResources() {
128130
// 1) Use output classes from the plugin itself
129131
// 2) Use resources from the plugin (i.e. plugin IDs etc.)
130132
// 3) Use AGP-specific dependencies
131-
val classesDirs = file("$buildDir/classes").listFiles()
133+
val classesDirs = layout.buildDirectory.dir("classes").get().asFile.listFiles()
132134
?.filter { it.isDirectory }
133135
?.map { File(it, "main") }
134136
?.filter { it.exists() && it.isDirectory && it.list()?.isEmpty() == false }
135137
?: emptyList()
136-
val resourcesDirs = file("$buildDir/resources").listFiles()
138+
val resourcesDirs = layout.buildDirectory.dir("resources").get().asFile.listFiles()
137139
?.filter { it.isDirectory }
138140
?: emptyList()
139141

plugin/android-junit5/src/main/kotlin/de/mannodermaus/gradle/plugins/junit5/internal/extensions/ProjectExt.kt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@ internal val Project.android
1919

2020
@OptIn(ExperimentalContracts::class)
2121
internal fun Project.whenAndroidPluginAdded(block: (BasePlugin) -> Unit) {
22-
contract { callsInPlace(block, InvocationKind.AT_MOST_ONCE) }
23-
2422
val configured = AtomicBoolean(false)
2523
plugins.withType(BasePlugin::class.java) { plugin ->
2624
// Prevent duplicate configuration

plugin/android-junit5/src/test/kotlin/de/mannodermaus/gradle/plugins/junit5/util/projects/FunctionalTestProjectCreator.kt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,10 @@ class FunctionalTestProjectCreator(
6565
file.write("sdk.dir = ${environment.androidSdkFolder.absolutePath}")
6666
}
6767
File(projectFolder, "gradle.properties").bufferedWriter().use { file ->
68-
file.write("android.useAndroidX = true")
68+
file.appendLine("android.useAndroidX = true")
69+
70+
// From AGP 9, test components are only generated for the debug build type; disable this behavior
71+
file.appendLine("android.onlyEnableUnitTestForTheTestedBuildType = false")
6972
}
7073

7174
// Copy over the source folders

plugin/android-junit5/src/test/resources/test-projects/custom-build-type/config.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ useCustomBuildType = "staging"
33

44
[[expectations]]
55
buildType = "debug"
6-
tests = "JavaTest"
6+
tests = "JavaTest,JavaDebugTest"
77

88
[[expectations]]
99
buildType = "release"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package de.mannodermaus.app;
2+
3+
import static org.junit.jupiter.api.Assertions.assertEquals;
4+
5+
import org.junit.jupiter.api.Test;
6+
7+
class JavaDebugTest {
8+
@Test
9+
void test() {
10+
Adder adder = new Adder();
11+
assertEquals(4, adder.add(2, 2), "This should succeed!");
12+
}
13+
}

0 commit comments

Comments
 (0)