diff --git a/build-logic/base/src/main/groovy/org/spockframework/gradle/SpockBasePlugin.groovy b/build-logic/base/src/main/groovy/org/spockframework/gradle/SpockBasePlugin.groovy index 9de191e2d7..cb8286a1b9 100644 --- a/build-logic/base/src/main/groovy/org/spockframework/gradle/SpockBasePlugin.groovy +++ b/build-logic/base/src/main/groovy/org/spockframework/gradle/SpockBasePlugin.groovy @@ -19,11 +19,38 @@ package org.spockframework.gradle import groovy.transform.CompileStatic import org.gradle.api.Plugin import org.gradle.api.Project +import org.gradle.api.tasks.compile.GroovyCompile +import org.gradle.api.tasks.compile.JavaCompile import org.gradle.api.tasks.testing.Test +import org.gradle.jvm.toolchain.JavaLanguageVersion +import org.gradle.jvm.toolchain.JavaToolchainService @CompileStatic class SpockBasePlugin implements Plugin { + void apply(Project project) { + compileTasks(project) + testTasks(project) + } + + private static void compileTasks(Project project) { + project.with { + def javaToolchains = extensions.getByType(JavaToolchainService) + tasks.withType(JavaCompile).configureEach { comp -> + if (it.name == 'compileJava') { + comp.javaCompiler.set(javaToolchains.compilerFor { + it.languageVersion.set(JavaLanguageVersion.of(8)) + }) + } + comp.options.encoding = 'UTF-8' + } + tasks.withType(GroovyCompile).configureEach { + it.options.encoding = 'UTF-8' + } + } + } + + private static void testTasks(Project project) { project.tasks.withType(Test).configureEach { task -> def taskName = task.name.capitalize() File configFile = project.file("Spock${taskName}Config.groovy") diff --git a/build.gradle b/build.gradle index ffb1911504..3770e5d0d6 100644 --- a/build.gradle +++ b/build.gradle @@ -102,6 +102,7 @@ subprojects { apply plugin: "java-library" apply plugin: "groovy" apply plugin: "jacoco" + apply plugin: "org.spockframework.base" java { toolchain { @@ -109,18 +110,6 @@ subprojects { } } - tasks.withType(JavaCompile).configureEach { - if (it.name == 'compileJava') { - javaCompiler = javaToolchains.compilerFor { - languageVersion = JavaLanguageVersion.of(8) - } - } - options.encoding = 'UTF-8' - } - tasks.withType(GroovyCompile).configureEach { - options.encoding = 'UTF-8' - } - sourceSets.all { ss -> for (gv in variants.findAll { variant <= it }) { java { diff --git a/spock-specs/specs.gradle b/spock-specs/specs.gradle index 898fe4ae04..fcfe90c139 100644 --- a/spock-specs/specs.gradle +++ b/spock-specs/specs.gradle @@ -1,9 +1,5 @@ import org.spockframework.gradle.JacocoJavaagentProvider -plugins { - id 'org.spockframework.base' -} - ext.displayName = "Spock Framework - Specs for Core Module" description = "Spock specifications for the Core Module. Yes, we eat our own dog food." diff --git a/spock-testkit/testkit.gradle b/spock-testkit/testkit.gradle index c1f34e97c2..8f1ce1f5b2 100644 --- a/spock-testkit/testkit.gradle +++ b/spock-testkit/testkit.gradle @@ -1,7 +1,3 @@ -plugins { - id 'org.spockframework.base' -} - ext.displayName = "Spock Framework - Temp Specs for Core Module" //configurations {