Skip to content

Commit

Permalink
Always register the integration scope & tasks (#368)
Browse files Browse the repository at this point in the history
This ensures a fresh created grails 7 app won't fail gradle commands.
  • Loading branch information
jdaugherty authored Dec 8, 2024
1 parent 91db950 commit 90daa80
Showing 1 changed file with 54 additions and 55 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,68 +59,67 @@ class IntegrationTestGradlePlugin implements Plugin<Project> {
@Override
void apply(Project project) {
File[] sourceDirs = findIntegrationTestSources(project)
if (sourceDirs) {
List<File> acceptedSourceDirs = []
final SourceSetContainer sourceSets = SourceSets.findSourceSets(project)
final SourceSetOutput mainSourceSetOutput = SourceSets.findMainSourceSet(project).output
final SourceSetOutput testSourceSetOutput = SourceSets.findSourceSet(project, TEST_SOURCE_SET_NAME).output
final SourceSet integrationTest = sourceSets.create(INTEGRATION_TEST_SOURCE_SET_NAME)
integrationTest.compileClasspath += mainSourceSetOutput + testSourceSetOutput
integrationTest.runtimeClasspath += mainSourceSetOutput + testSourceSetOutput

for (File srcDir in sourceDirs) {
registerSourceDir(integrationTest, srcDir)
acceptedSourceDirs.add srcDir
}

final File resources = new File(project.projectDir, "grails-app/conf")
integrationTest.resources.srcDir(resources)
List<File> acceptedSourceDirs = []
final SourceSetContainer sourceSets = SourceSets.findSourceSets(project)
final SourceSetOutput mainSourceSetOutput = SourceSets.findMainSourceSet(project).output
final SourceSetOutput testSourceSetOutput = SourceSets.findSourceSet(project, TEST_SOURCE_SET_NAME).output
final SourceSet integrationTest = sourceSets.create(INTEGRATION_TEST_SOURCE_SET_NAME)
integrationTest.compileClasspath += mainSourceSetOutput + testSourceSetOutput
integrationTest.runtimeClasspath += mainSourceSetOutput + testSourceSetOutput

for (File srcDir in sourceDirs) {
registerSourceDir(integrationTest, srcDir)
acceptedSourceDirs.add srcDir
}

final DependencyHandler dependencies = project.dependencies
dependencies.add(INTEGRATION_TEST_IMPLEMENTATION_CONFIGURATION_NAME, mainSourceSetOutput)
dependencies.add(INTEGRATION_TEST_IMPLEMENTATION_CONFIGURATION_NAME, testSourceSetOutput)
final File resources = new File(project.projectDir, "grails-app/conf")
integrationTest.resources.srcDir(resources)

final ConfigurationContainer configurations = project.configurations
configurations.named(INTEGRATION_TEST_IMPLEMENTATION_CONFIGURATION_NAME) {
it.extendsFrom(configurations.named(TEST_IMPLEMENTATION_CONFIGURATION_NAME).get())
}
configurations.named(INTEGRATION_TEST_RUNTIME_ONLY_CONFIGURATION_NAME) {
it.extendsFrom(configurations.named(TEST_RUNTIME_ONLY_CONFIGURATION_NAME).get())
}
final DependencyHandler dependencies = project.dependencies
dependencies.add(INTEGRATION_TEST_IMPLEMENTATION_CONFIGURATION_NAME, mainSourceSetOutput)
dependencies.add(INTEGRATION_TEST_IMPLEMENTATION_CONFIGURATION_NAME, testSourceSetOutput)

final TaskContainer tasks = project.tasks
final TaskProvider<Test> integrationTestTask = tasks.register(INTEGRATION_TEST_TASK_NAME, Test) {
it.group = LifecycleBasePlugin.VERIFICATION_GROUP
it.testClassesDirs = integrationTest.output.classesDirs
it.classpath = integrationTest.runtimeClasspath
it.shouldRunAfter(TEST_TASK_NAME)
it.finalizedBy(MERGE_TEST_REPORTS_TASK_NAME)
it.reports.html.required.set(false)
it.maxParallelForks = 1
it.testLogging {
events "passed"
}
}
tasks.named("check") {
it.dependsOn(integrationTestTask)
}
final ConfigurationContainer configurations = project.configurations
configurations.named(INTEGRATION_TEST_IMPLEMENTATION_CONFIGURATION_NAME) {
it.extendsFrom(configurations.named(TEST_IMPLEMENTATION_CONFIGURATION_NAME).get())
}
configurations.named(INTEGRATION_TEST_RUNTIME_ONLY_CONFIGURATION_NAME) {
it.extendsFrom(configurations.named(TEST_RUNTIME_ONLY_CONFIGURATION_NAME).get())
}

tasks.register(MERGE_TEST_REPORTS_TASK_NAME, TestReport) {
it.mustRunAfter(tasks.withType(Test).toArray())
it.destinationDirectory.set(project.layout.buildDirectory.dir("reports/tests"))
// These must point to the binary test results directory generated by a Test task instance.
// If Test task instances are specified directly, this task would depend on them and run them.
it.testResults.from(
project.files("$project.buildDir/test-results/binary/test", "$project.buildDir/test-results/binary/integrationTest"),
// different versions of Gradle store these results in different places. ugh.
project.files("$project.buildDir/test-results/test/binary", "$project.buildDir/test-results/integrationTest/binary")
)
final TaskContainer tasks = project.tasks
final TaskProvider<Test> integrationTestTask = tasks.register(INTEGRATION_TEST_TASK_NAME, Test) {
it.group = LifecycleBasePlugin.VERIFICATION_GROUP
it.testClassesDirs = integrationTest.output.classesDirs
it.classpath = integrationTest.runtimeClasspath
it.shouldRunAfter(TEST_TASK_NAME)
it.finalizedBy(MERGE_TEST_REPORTS_TASK_NAME)
it.reports.html.required.set(false)
it.maxParallelForks = 1
it.testLogging {
events "passed"
}
}
tasks.named("check") {
it.dependsOn(integrationTestTask)
}

if (ideaIntegration) {
final File[] files = acceptedSourceDirs.toArray(new File[acceptedSourceDirs.size()])
integrateIdea(project, files)
}
tasks.register(MERGE_TEST_REPORTS_TASK_NAME, TestReport) {
it.mustRunAfter(tasks.withType(Test).toArray())
it.destinationDirectory.set(project.layout.buildDirectory.dir("reports/tests"))
// These must point to the binary test results directory generated by a Test task instance.
// If Test task instances are specified directly, this task would depend on them and run them.
it.testResults.from(
project.files("$project.buildDir/test-results/binary/test", "$project.buildDir/test-results/binary/integrationTest"),
// different versions of Gradle store these results in different places. ugh.
project.files("$project.buildDir/test-results/test/binary", "$project.buildDir/test-results/integrationTest/binary")
)
}

if (ideaIntegration) {
final File[] files = acceptedSourceDirs.toArray(new File[acceptedSourceDirs.size()])
integrateIdea(project, files)
}
}

Expand Down

0 comments on commit 90daa80

Please sign in to comment.