@@ -5,6 +5,7 @@ import org.junit.jupiter.api.Assertions.assertTrue
55import org.junit.jupiter.api.Tag
66import org.junit.jupiter.api.Test
77import java.io.File
8+ import kotlin.io.path.createTempDirectory
89
910/* *
1011 * Lightweight checks that the composite build still configures with the configuration cache enabled.
@@ -13,35 +14,108 @@ import java.io.File
1314class PluginIntegrationTest {
1415 private fun repoRoot (): File {
1516 var dir = File (requireNotNull(System .getProperty(" user.dir" )))
16- while (! dir.resolve(" settings.gradle.kts" ).exists() && dir.parentFile != null ) {
17+ while (
18+ ! (dir.resolve(" settings.gradle.kts" ).exists() &&
19+ dir.resolve(" plugin" ).isDirectory &&
20+ dir.resolve(" app" ).isDirectory) &&
21+ dir.parentFile != null
22+ ) {
1723 dir = dir.parentFile ? : break
1824 }
19- require(dir.resolve(" settings.gradle.kts" ).exists()) { " Unable to locate repository root from ${System .getProperty(" user.dir" )} " }
25+ require(
26+ dir.resolve(" settings.gradle.kts" ).exists() &&
27+ dir.resolve(" plugin" ).isDirectory &&
28+ dir.resolve(" app" ).isDirectory,
29+ ) { " Unable to locate repository root from ${System .getProperty(" user.dir" )} " }
2030 return dir
2131 }
2232
2333 @Test
2434 fun `compile plugin with configuration cache` () {
25- val root = repoRoot()
26- val result =
35+ val result = runRepoBuild(" :plugin:compileKotlin" , " --configuration-cache" )
36+ assertTrue(result.output.contains(" BUILD SUCCESSFUL" ))
37+ }
38+
39+ private fun runBuild (
40+ projectDir : File ,
41+ vararg args : String ,
42+ ): org.gradle.testkit.runner.BuildResult {
43+ return GradleRunner .create()
44+ .withProjectDir(projectDir)
45+ .withArguments(* args, " --stacktrace" )
46+ .forwardOutput()
47+ .build()
48+ }
49+
50+ private fun runBuildWithGradleVersion (
51+ projectDir : File ,
52+ gradleVersion : String ,
53+ vararg args : String ,
54+ ): org.gradle.testkit.runner.BuildResult {
55+ val runner =
2756 GradleRunner .create()
28- .withProjectDir(root )
29- .withArguments(" compileKotlin " , " --configuration-cache " )
57+ .withProjectDir(projectDir )
58+ .withArguments(* args , " --stacktrace " )
3059 .forwardOutput()
31- .build( )
32- assertTrue(result.output.contains( " BUILD SUCCESSFUL " ) )
60+ .withGradleVersion(gradleVersion )
61+ return runner.build( )
3362 }
3463
3564 private fun runRepoBuild (vararg args : String ) =
36- GradleRunner .create()
37- .withProjectDir(repoRoot())
38- .withArguments(* args, " --stacktrace" )
39- .forwardOutput()
40- .build()
65+ runBuild(repoRoot(), * args)
66+
67+ private fun copyRepoForAgpCompatibilityTest (): File {
68+ val source = repoRoot()
69+ val temp = createTempDirectory(prefix = " stringcare-agp-compat-" ).toFile()
70+ // Copy only the pieces required to configure :app and :plugin.
71+ listOf (" app" , " plugin" , " library" , " buildSrc" , " gradle" ).forEach { name ->
72+ source.resolve(name).copyRecursively(temp.resolve(name), overwrite = true )
73+ }
74+ listOf (" settings.gradle.kts" , " build.gradle.kts" , " gradle.properties" ).forEach { fileName ->
75+ source.resolve(fileName).copyTo(temp.resolve(fileName), overwrite = true )
76+ }
77+ return temp
78+ }
79+
80+ private fun setAgpVersion (
81+ copiedRepo : File ,
82+ version : String ,
83+ ) {
84+ val versionsFile = copiedRepo.resolve(" gradle/libs.versions.toml" )
85+ val updated = versionsFile.readText().replace(Regex (""" ^agp = ".*"$""" , RegexOption .MULTILINE ), """ agp = "$version """" )
86+ versionsFile.writeText(updated)
87+ }
88+
89+ private fun assertAppConfiguresWithAgp (version : String ) {
90+ val copiedRepo = copyRepoForAgpCompatibilityTest()
91+ setAgpVersion(copiedRepo, version)
92+ val gradleVersion =
93+ when (version) {
94+ " 9.0.0" -> " 9.1.0"
95+ else -> null
96+ }
97+ val result =
98+ if (gradleVersion == null ) {
99+ runBuild(copiedRepo, " :app:help" )
100+ } else {
101+ runBuildWithGradleVersion(copiedRepo, gradleVersion, " :app:help" )
102+ }
103+ assertTrue(result.output.contains(" BUILD SUCCESSFUL" ))
104+ }
105+
106+ @Test
107+ fun `app configures with agp 8_7_3` () {
108+ assertAppConfiguresWithAgp(" 8.7.3" )
109+ }
110+
111+ @Test
112+ fun `app configures with agp 9_0_0` () {
113+ assertAppConfiguresWithAgp(" 9.0.0" )
114+ }
41115
42116 @Test
43117 fun `multi-module fixture configures successfully` () {
44- val fixture = repoRoot().resolve(" src/test/resources/test-projects/multi-module" )
118+ val fixture = repoRoot().resolve(" plugin/ src/test/resources/test-projects/multi-module" )
45119 assertTrue(fixture.exists())
46120 assertTrue(fixture.resolve(" settings.gradle.kts" ).exists())
47121 assertTrue(fixture.resolve(" app/build.gradle.kts" ).exists())
@@ -50,16 +124,16 @@ class PluginIntegrationTest {
50124
51125 @Test
52126 fun `multi-module fixture supports parallel build graph` () {
53- val result = runRepoBuild(" compileKotlin" , " --parallel" )
127+ val result = runRepoBuild(" :plugin: compileKotlin" , " --parallel" )
54128 assertTrue(result.output.contains(" BUILD SUCCESSFUL" ))
55129 }
56130
57131 @Test
58132 fun `simple-app fixture reuses configuration cache` () {
59- val fixture = repoRoot().resolve(" src/test/resources/test-projects/simple-app" )
133+ val fixture = repoRoot().resolve(" plugin/ src/test/resources/test-projects/simple-app" )
60134 assertTrue(fixture.exists())
61- val first = runRepoBuild(" compileKotlin" , " --configuration-cache" )
62- val second = runRepoBuild(" compileKotlin" , " --configuration-cache" )
135+ val first = runRepoBuild(" :plugin: compileKotlin" , " --configuration-cache" )
136+ val second = runRepoBuild(" :plugin: compileKotlin" , " --configuration-cache" )
63137 assertTrue(first.output.contains(" BUILD SUCCESSFUL" ))
64138 assertTrue(second.output.contains(" BUILD SUCCESSFUL" ))
65139 assertTrue(
0 commit comments