diff --git a/build.gradle b/build.gradle index d5bef78be4..57da10ebc9 100644 --- a/build.gradle +++ b/build.gradle @@ -1,8 +1,8 @@ plugins { id 'io.spring.nohttp' version '0.0.10' id 'io.freefair.aspectj' version '6.5.0.3' apply false - id 'org.jetbrains.kotlin.jvm' version '1.7.20' apply false - id 'org.jetbrains.kotlin.plugin.serialization' version '1.7.20' apply false + // kotlinVersion is managed in gradle.properties + id 'org.jetbrains.kotlin.plugin.serialization' version "${kotlinVersion}" apply false id 'org.jetbrains.dokka' version '1.7.20' id 'org.asciidoctor.jvm.convert' version '3.3.2' apply false id 'org.asciidoctor.jvm.pdf' version '3.3.2' apply false @@ -16,9 +16,6 @@ plugins { ext { moduleProjects = subprojects.findAll { it.name.startsWith("spring-") } javaProjects = subprojects - project(":framework-bom") - project(":framework-platform") - withoutJclOverSlf4j = { - exclude group: "org.slf4j", name: "jcl-over-slf4j" - } } configure(allprojects) { project -> @@ -59,23 +56,6 @@ configure([rootProject] + javaProjects) { project -> matching { it.name.endsWith("Classpath") }.all { it.extendsFrom(dependencyManagement) } } - pluginManager.withPlugin("kotlin") { - - compileKotlin { - kotlinOptions { - languageVersion = "1.7" - apiVersion = "1.7" - freeCompilerArgs = ["-Xjsr305=strict", "-Xsuppress-version-warnings", "-opt-in=kotlin.RequiresOptIn"] - allWarningsAsErrors = true - } - } - compileTestKotlin { - kotlinOptions { - freeCompilerArgs = ["-Xjsr305=strict", "-opt-in=kotlin.RequiresOptIn"] - } - } - } - test { useJUnitPlatform() include(["**/*Tests.class", "**/*Test.class"]) @@ -165,7 +145,6 @@ configure(moduleProjects) { project -> configure(rootProject) { description = "Spring Framework" - apply plugin: "kotlin" apply plugin: "io.spring.nohttp" apply plugin: 'org.springframework.build.api-diff' @@ -188,4 +167,4 @@ configure(rootProject) { maxHeapSize = "1g" } -} +} diff --git a/buildSrc/README.md b/buildSrc/README.md index f101ed75f2..90dfdd23db 100644 --- a/buildSrc/README.md +++ b/buildSrc/README.md @@ -7,7 +7,8 @@ They are declared in the `build.gradle` file in this folder. The `org.springframework.build.conventions` plugin applies all conventions to the Framework build: -* Configuring the Java compiler, see `CompilerConventions` +* Configuring the Java compiler, see `JavaConventions` +* Configuring the Kotlin compiler, see `KotlinConventions` * Configuring testing in the build with `TestConventions` diff --git a/buildSrc/build.gradle b/buildSrc/build.gradle index 27dfb54fea..e21f9231a9 100644 --- a/buildSrc/build.gradle +++ b/buildSrc/build.gradle @@ -7,7 +7,18 @@ repositories { gradlePluginPortal() } +ext { + def propertiesFile = new File(new File("$projectDir").parentFile, "gradle.properties") + propertiesFile.withInputStream { + def properties = new Properties() + properties.load(it) + set("kotlinVersion", properties["kotlinVersion"]) + } +} + dependencies { + implementation("org.jetbrains.kotlin:kotlin-gradle-plugin:${kotlinVersion}") + implementation("org.jetbrains.kotlin:kotlin-compiler-embeddable:${kotlinVersion}") implementation "me.champeau.gradle:japicmp-gradle-plugin:0.3.0" implementation "org.gradle:test-retry-gradle-plugin:1.4.1" } diff --git a/buildSrc/src/main/java/org/springframework/build/ConventionsPlugin.java b/buildSrc/src/main/java/org/springframework/build/ConventionsPlugin.java index bcfc9641fc..e54ddce559 100644 --- a/buildSrc/src/main/java/org/springframework/build/ConventionsPlugin.java +++ b/buildSrc/src/main/java/org/springframework/build/ConventionsPlugin.java @@ -19,6 +19,7 @@ package org.springframework.build; import org.gradle.api.Plugin; import org.gradle.api.Project; import org.gradle.api.plugins.JavaBasePlugin; +import org.jetbrains.kotlin.gradle.plugin.KotlinBasePlugin; /** * Plugin to apply conventions to projects that are part of Spring Framework's build. @@ -26,7 +27,9 @@ import org.gradle.api.plugins.JavaBasePlugin; * * When the {@link JavaBasePlugin} is applied, the conventions in {@link TestConventions} * are applied. - * When the {@link JavaBasePlugin} is applied, the conventions in {@link CompilerConventions} + * When the {@link JavaBasePlugin} is applied, the conventions in {@link JavaConventions} + * are applied. + * When the {@link KotlinBasePlugin} is applied, the conventions in {@link KotlinConventions} * are applied. * * @author Brian Clozel @@ -35,7 +38,8 @@ public class ConventionsPlugin implements Plugin { @Override public void apply(Project project) { + new JavaConventions().apply(project); + new KotlinConventions().apply(project); new TestConventions().apply(project); - new CompilerConventions().apply(project); } } diff --git a/buildSrc/src/main/java/org/springframework/build/CompilerConventions.java b/buildSrc/src/main/java/org/springframework/build/JavaConventions.java similarity index 98% rename from buildSrc/src/main/java/org/springframework/build/CompilerConventions.java rename to buildSrc/src/main/java/org/springframework/build/JavaConventions.java index dda5eaee0d..134f99fe9f 100644 --- a/buildSrc/src/main/java/org/springframework/build/CompilerConventions.java +++ b/buildSrc/src/main/java/org/springframework/build/JavaConventions.java @@ -33,7 +33,7 @@ import org.gradle.api.tasks.compile.JavaCompile; * @author Sam Brannen * @author Sebastien Deleuze */ -public class CompilerConventions { +public class JavaConventions { private static final List COMPILER_ARGS; diff --git a/buildSrc/src/main/java/org/springframework/build/KotlinConventions.java b/buildSrc/src/main/java/org/springframework/build/KotlinConventions.java new file mode 100644 index 0000000000..f0ef7f3d59 --- /dev/null +++ b/buildSrc/src/main/java/org/springframework/build/KotlinConventions.java @@ -0,0 +1,47 @@ +/* + * Copyright 2002-2022 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.build; + +import java.util.ArrayList; +import java.util.List; + +import org.gradle.api.Project; +import org.jetbrains.kotlin.gradle.dsl.KotlinJvmOptions; +import org.jetbrains.kotlin.gradle.tasks.KotlinCompile; + +/** + * @author Brian Clozel + */ +public class KotlinConventions { + + void apply(Project project) { + project.getPlugins().withId("org.jetbrains.kotlin.jvm", + (plugin) -> project.getTasks().withType(KotlinCompile.class, this::configure)); + } + + private void configure(KotlinCompile compile) { + KotlinJvmOptions kotlinOptions = compile.getKotlinOptions(); + kotlinOptions.setApiVersion("1.7"); + kotlinOptions.setLanguageVersion("1.7"); + kotlinOptions.setJvmTarget("17"); + kotlinOptions.setAllWarningsAsErrors(true); + List freeCompilerArgs = new ArrayList<>(compile.getKotlinOptions().getFreeCompilerArgs()); + freeCompilerArgs.addAll(List.of("-Xsuppress-version-warnings", "-Xjsr305=strict", "-opt-in=kotlin.RequiresOptIn")); + compile.getKotlinOptions().setFreeCompilerArgs(freeCompilerArgs); + } + +} diff --git a/gradle.properties b/gradle.properties index 22e37de470..28d0adf107 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,5 +1,9 @@ version=6.0.0-SNAPSHOT -org.gradle.jvmargs=-Xmx2048m + org.gradle.caching=true +org.gradle.jvmargs=-Xmx2048m org.gradle.parallel=true + +kotlinVersion=1.7.20 + kotlin.stdlib.default.dependency=false