Skip to content

Commit 2f3bbf0

Browse files
committed
refactor: improve the tck process to be lazy evaluated
1 parent 89560ea commit 2f3bbf0

File tree

1 file changed

+32
-19
lines changed

1 file changed

+32
-19
lines changed

gradle/tck-config.gradle

Lines changed: 32 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,45 @@
1+
configurations {
2+
tck {
3+
transitive = false
4+
}
5+
6+
// Because we reference tests in the SimpleTestSuite to be able to run them in the IDE,
7+
// the tests need explicitly added to the classpath as well
8+
testImplementation.extendsFrom(tck)
9+
}
10+
111
dependencies {
212
if (!project.hasProperty('includeBaseTckClass') || project.findProperty('includeBaseTckClass')) {
313
testImplementation project(':grails-datastore-gorm-tck-base')
414
}
5-
testImplementation project(':grails-datastore-gorm-tck')
15+
// So we can easily extract the compiled classes
16+
tck project(':grails-datastore-gorm-tck')
617
testImplementation project(':grails-datastore-gorm-tck-domains')
7-
}
8-
9-
// TODO: gradle will happily put the jar file on the classpath, but junit won't find the tests. Dynamic test discovery also won't find them.
10-
tasks.register('extractTckJar', Copy) {
11-
dependsOn(configurations.testRuntimeClasspath)
1218

13-
Provider<Directory> extractTarget = layout.buildDirectory.dir('extracted-tck-classes')
14-
15-
doFirst {
16-
extractTarget.get().asFile.deleteDir()
19+
runtimeOnly 'org.apache.groovy:groovy-dateutil', {
20+
// Groovy Date Utils Extensions are used in the tests
1721
}
22+
}
1823

19-
outputs.dir(extractTarget)
20-
File tckJar = configurations.testRuntimeClasspath.resolve().find { it.name.startsWith("grails-datastore-gorm-tck-${projectVersion}") }
21-
if (tckJar) {
22-
from(zipTree(tckJar))
23-
into(extractTarget)
24-
}
24+
// TODO: gradle will happily put the jar file on the classpath, but junit won't find the tests.
25+
// Dynamic test discovery also won't find them so extract the class files to force junit to work.
26+
TaskProvider<Sync> extractTck = tasks.register('extractTckJar', Sync) {
27+
inputs.files(configurations.tck)
28+
29+
from { zipTree(configurations.tck.singleFile) }
30+
into(layout.buildDirectory.dir('extracted-tck-classes'))
2531
}
2632

2733
tasks.withType(Test).configureEach {
28-
dependsOn('extractTckJar')
29-
doFirst {
30-
testClassesDirs += files(layout.buildDirectory.dir('extracted-tck-classes'))
34+
testClassesDirs = objects.fileCollection().from(extractTck, testClassesDirs)
35+
finalizedBy('cleanupTckClasses')
36+
}
37+
38+
// There is a known issue with IntelliJ that can cause it's inspection process to lock up.
39+
// this is a work around to help prevent the scenario that causes the lock up.
40+
tasks.register('cleanupTckClasses') {
41+
Provider<Directory> extractDir = layout.buildDirectory.dir('extracted-tck-classes')
42+
doLast {
43+
extractDir.get().asFile.deleteDir()
3144
}
3245
}

0 commit comments

Comments
 (0)