@@ -30,17 +30,29 @@ repositories {
30
30
mavenCentral()
31
31
}
32
32
33
+ configurations {
34
+ groovyClasspath
35
+ }
36
+
33
37
dependencies {
34
- def agpVersion = " 3.5.4"
35
- compileOnly " com.android.tools.build:gradle:$agpVersion "
38
+ def versions = [
39
+ ' agp' : ' 3.5.4' ,
40
+ ' spock' : ' 2.0-M5-groovy-3.0'
41
+ ]
42
+
43
+ // Used for compiling the main classes
44
+ groovyClasspath ' org.codehaus.groovy:groovy-all:2.5.12'
45
+
46
+ compileOnly " com.android.tools.build:gradle:${ versions.agp} "
47
+
36
48
implementation gradleApi()
37
- testImplementation " com.android.tools.build:gradle: $a gpVersion "
49
+
38
50
testImplementation gradleTestKit()
39
- testImplementation " junit:junit:4.13.2 "
40
- testImplementation " org.spockframework:spock-core:2.0-M5-groovy-3.0@jar "
41
- testImplementation " org.opentest4j:opentest4j:1.2.0 "
42
- testRuntimeOnly ' cglib:cglib-nodep:3.3.0 '
43
- testRuntimeOnly ' org.objenesis:objenesis:3.2 '
51
+ testImplementation " com.android.tools.build:gradle: ${ versions.agp } "
52
+ testImplementation platform( " org.spockframework:spock-bom: ${ versions.spock } " )
53
+ testImplementation( " org.spockframework:spock-core " ) { exclude group : ' org.codehaus.groovy ' }
54
+ testImplementation( " org.spockframework:spock-junit4 " ) { exclude group : ' org.codehaus.groovy ' }
55
+ testImplementation " org.junit.jupiter:junit-jupiter-api "
44
56
}
45
57
46
58
java {
@@ -49,8 +61,15 @@ java {
49
61
}
50
62
}
51
63
52
- def generatedResources = " $buildDir /generated-resources/main"
64
+ // We do this only for the the main source set as the test source set needs to use
65
+ // Groovy 3 for Spock 2.0 compatibility. The main classes need to be compiled with
66
+ // Groovy 2 so that they will work with older versions of Gradle.
67
+ tasks. named(' compileGroovy' ). configure {
68
+ groovyClasspath = configurations. groovyClasspath
69
+ }
53
70
71
+ // Generate a json file that contains the matrix of Gradle and AGP versions to test against.
72
+ def generatedResources = " $buildDir /generated-resources/main"
54
73
tasks. register(' generateVersions' ) {
55
74
def outputFile = file(" $generatedResources /versions.json" )
56
75
inputs. property " version" , version
@@ -70,6 +89,7 @@ sourceSets {
70
89
}
71
90
}
72
91
92
+ // Main plugin publishing metadata
73
93
gradlePlugin {
74
94
plugins {
75
95
androidCacheFixPlugin {
@@ -92,8 +112,9 @@ pluginBundle {
92
112
}
93
113
}
94
114
115
+ // A local repo we publish our library to for testing in order to workaround limitations
116
+ // in the TestKit plugin classpath.
95
117
def localRepo = file(" $buildDir /local-repo" )
96
-
97
118
publishing {
98
119
repositories {
99
120
maven {
@@ -115,22 +136,17 @@ tasks.register('generateTestTasksJson') {
115
136
}
116
137
}
117
138
139
+ // Configuration common to all test tasks
118
140
tasks. withType(Test ). configureEach {
119
141
dependsOn publish
120
142
systemProperty " local.repo" , localRepo. toURI()
143
+ useJUnitPlatform()
121
144
retry {
122
145
maxRetries = isCI ? 1 : 0
123
146
maxFailures = 20
124
147
}
125
148
}
126
149
127
- tasks. named(" test" ). configure {
128
- useJUnit {
129
- // The main test task runs everything not annotated with the MultiVersionTest category
130
- excludeCategories ' org.gradle.android.MultiVersionTest'
131
- }
132
- }
133
-
134
150
// Generate a test task for each Android version and run the tests annotated with the MultiVersionTest category
135
151
supportedVersions. keySet(). each { androidVersion ->
136
152
def versionSpecificTest = tasks. register(androidTestTaskName(androidVersion), Test ) {
@@ -140,9 +156,7 @@ supportedVersions.keySet().each { androidVersion ->
140
156
javaLauncher = javaToolchains. launcherFor {
141
157
languageVersion = jdkVersionFor(androidVersion)
142
158
}
143
- useJUnit {
144
- includeCategories ' org.gradle.android.MultiVersionTest'
145
- }
159
+
146
160
systemProperty ' org.gradle.android.testVersion' , androidVersion
147
161
}
148
162
@@ -163,6 +177,7 @@ static def jdkVersionFor(String version) {
163
177
return JavaLanguageVersion . of(VersionNumber . parse(version) > VersionNumber . parse(" 7.0.0-alpha01" ) ? 11 : 8 )
164
178
}
165
179
180
+ // A basic sanity check to run before running all test tasks
166
181
tasks. register(" sanityCheck" ) {
167
182
dependsOn tasks. withType(CodeNarc ), validatePlugins
168
183
}
0 commit comments