@@ -102,31 +102,34 @@ tasks.named("processTestResources", Copy::class.java).configure {
102102 }
103103}
104104
105- // Add custom dependency configurations
105+ // Add custom dependency configurations for Functional Tests.
106+ // Different versions of the Android Gradle Plugin should be testable in the same project;
107+ // to do this, create a custom configuration for each version & assign the correct dependency to it.
108+ // At runtime, the functional tests will look up a file listing of all dependencies, making it the
109+ // plugin classpath for the respective test.
110+ data class AgpConfiguration (val version : String , val dependency : String ) {
111+ // Example: version = "3.2" --> configurationName = "testAgp32x"
112+ val configurationName = " testAgp${version.replace(" ." , " " )} x"
113+ }
114+
115+ private val agpConfigurations = listOf (
116+ AgpConfiguration (" 3.2" , Libs .com_android_tools_build_gradle_32x),
117+ AgpConfiguration (" 3.3" , Libs .com_android_tools_build_gradle_33x),
118+ AgpConfiguration (" 3.4" , Libs .com_android_tools_build_gradle_34x),
119+ AgpConfiguration (" 3.5" , Libs .com_android_tools_build_gradle_35x)
120+ )
121+
106122configurations {
107- create(" testAgp32x" ) {
108- description = " Local dependencies used for compiling & running " +
109- " tests source code in Gradle functional tests against AGP 3.2.X"
110- extendsFrom(configurations.getByName(" implementation" ))
111- resolutionStrategy.force(Libs .com_android_tools_build_gradle_32x)
112- }
113- create(" testAgp33x" ) {
114- description = " Local dependencies used for compiling & running " +
115- " tests source code in Gradle functional tests against AGP 3.3.X"
116- extendsFrom(configurations.getByName(" implementation" ))
117- resolutionStrategy.force(Libs .com_android_tools_build_gradle_33x)
118- }
119- create(" testAgp34x" ) {
120- description = " Local dependencies used for compiling & running " +
121- " tests source code in Gradle functional tests against AGP 3.4.X"
122- extendsFrom(configurations.getByName(" implementation" ))
123- resolutionStrategy.force(Libs .com_android_tools_build_gradle_34x)
124- }
125- create(" testAgp35x" ) {
126- description = " Local dependencies used for compiling & running " +
127- " tests source code in Gradle functional tests against AGP 3.5.X"
128- extendsFrom(configurations.getByName(" implementation" ))
129- resolutionStrategy.force(Libs .com_android_tools_build_gradle_35x)
123+ // Create a custom configuration for each version
124+ agpConfigurations.forEach { agpConfig ->
125+ create(agpConfig.configurationName) {
126+ description = " Local dependencies used for compiling & running " +
127+ " tests source code in Gradle functional tests against AGP ${agpConfig.version} "
128+ extendsFrom(configurations.getByName(" implementation" ))
129+ dependencies {
130+ this @create(agpConfig.dependency)
131+ }
132+ }
130133 }
131134}
132135
@@ -179,15 +182,16 @@ tasks.withType<WriteClasspathResource> {
179182// ------------------------------------------------------------------------------------------------
180183
181184dependencies {
185+ compileOnly(Libs .com_android_tools_build_gradle)
182186 implementation(gradleApi())
183- implementation(Libs .com_android_tools_build_gradle)
184187 implementation(Libs .kotlin_gradle_plugin)
185188 implementation(Libs .kotlin_stdlib_jdk8)
186189 implementation(Libs .java_semver)
187190 implementation(Libs .stream)
188191 implementation(Libs .junit_platform_commons)
189192
190193 testImplementation(gradleTestKit())
194+ testImplementation(Libs .com_android_tools_build_gradle)
191195 testImplementation(Libs .commons_io)
192196 testImplementation(Libs .commons_lang)
193197 testImplementation(Libs .mockito_core)
0 commit comments