From 90daa80a5325fe0c251fda6030c80b8d566299fa Mon Sep 17 00:00:00 2001 From: James Daugherty Date: Sun, 8 Dec 2024 17:46:39 -0500 Subject: [PATCH] Always register the integration scope & tasks (#368) This ensures a fresh created grails 7 app won't fail gradle commands. --- .../core/IntegrationTestGradlePlugin.groovy | 109 +++++++++--------- 1 file changed, 54 insertions(+), 55 deletions(-) diff --git a/src/main/groovy/org/grails/gradle/plugin/core/IntegrationTestGradlePlugin.groovy b/src/main/groovy/org/grails/gradle/plugin/core/IntegrationTestGradlePlugin.groovy index 21a610b5..f3a54229 100644 --- a/src/main/groovy/org/grails/gradle/plugin/core/IntegrationTestGradlePlugin.groovy +++ b/src/main/groovy/org/grails/gradle/plugin/core/IntegrationTestGradlePlugin.groovy @@ -59,68 +59,67 @@ class IntegrationTestGradlePlugin implements Plugin { @Override void apply(Project project) { File[] sourceDirs = findIntegrationTestSources(project) - if (sourceDirs) { - List 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 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 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 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) } }