Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 2 additions & 7 deletions gradle/java_no_deps.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -150,13 +150,8 @@ ext.testcontainersLimit = gradle.sharedServices.registerIfAbsent("testcontainers
maxParallelUsages = project.findProperty("testcontainersMaxParallelUsages").toInteger()
}

// Task for tests that want to run forked in their own separate JVM
tasks.register('forkedTest', Test) {
group = LifecycleBasePlugin.VERIFICATION_GROUP
useJUnitPlatform()
testClassesDirs = sourceSets.test.output.classesDirs
classpath = sourceSets.test.runtimeClasspath
}
// Every project gets a forked test task for its default 'test' source set.
addForkedTestTask('test')

// testRuntimeActivation is registered in individual module build files after this convention is
// applied, so tasks.named() won't work here — use a lazy hook that intercepts it on registration.
Expand Down
26 changes: 26 additions & 0 deletions gradle/test-suites.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -77,3 +77,29 @@ ext.addTestSuiteForDir = { testSuiteName, dirName ->
ext.addTestSuite = { testSuiteName ->
ext.addTestSuiteForDir(testSuiteName, testSuiteName)
}

// Registers a task that runs the '*ForkedTest' classes of a source set, each in its own JVM.
//
// The task name ends in 'ForkedTest', which is what makes the test convention plugin restrict it to
// '**/*ForkedTest*', set forkEvery=1 and apply the shared forked-test concurrency limit. 'check',
// 'allTests' and 'allLatestDepTests' pick the task up automatically, because they match Test tasks
// by type rather than by name.
//
// Modules whose tests live in the default 'test' source set get 'forkedTest' registered for them by
// java_no_deps.gradle. Modules that use their own suites instead - for example to compile the same
// tests against several Scala versions - have no 'test' sources, so their forked tests never run
// unless they opt in:
//
// addTestSuite('baseTest')
// addForkedTestTask('baseTest') // registers 'baseTestForkedTest'
//
// Returns the TaskProvider so callers can configure the task further.
ext.addForkedTestTask = { String sourceSetName ->
def taskName = sourceSetName == 'test' ? 'forkedTest' : "${sourceSetName}ForkedTest"
return tasks.register(taskName, Test) {
group = LifecycleBasePlugin.VERIFICATION_GROUP
useJUnitPlatform()
testClassesDirs = sourceSets[sourceSetName].output.classesDirs
classpath = sourceSets[sourceSetName].runtimeClasspath
}
}