|
| 1 | +/* |
| 2 | + * Copyright 2020-2023 the original author or authors. |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * https://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | + |
| 17 | +package org.springframework.graphql.build.conventions; |
| 18 | + |
| 19 | +import java.util.ArrayList; |
| 20 | +import java.util.List; |
| 21 | + |
| 22 | +import org.gradle.api.Project; |
| 23 | +import org.jetbrains.kotlin.gradle.dsl.KotlinJvmOptions; |
| 24 | +import org.jetbrains.kotlin.gradle.tasks.KotlinCompile; |
| 25 | + |
| 26 | +/** |
| 27 | + * Convention for compiling Kotlin code. |
| 28 | + * @author Brian Clozel |
| 29 | + */ |
| 30 | +public class KotlinConventions { |
| 31 | + |
| 32 | + public void apply(Project project) { |
| 33 | + project.getPlugins().withId("org.jetbrains.kotlin.jvm", |
| 34 | + (plugin) -> project.getTasks().withType(KotlinCompile.class, this::configure)); |
| 35 | + } |
| 36 | + |
| 37 | + private void configure(KotlinCompile compile) { |
| 38 | + KotlinJvmOptions kotlinOptions = compile.getKotlinOptions(); |
| 39 | + kotlinOptions.setApiVersion("1.7"); |
| 40 | + kotlinOptions.setLanguageVersion("1.7"); |
| 41 | + kotlinOptions.setJvmTarget("17"); |
| 42 | + kotlinOptions.setJavaParameters(true); |
| 43 | + kotlinOptions.setAllWarningsAsErrors(true); |
| 44 | + List<String> freeCompilerArgs = new ArrayList<>(compile.getKotlinOptions().getFreeCompilerArgs()); |
| 45 | + freeCompilerArgs.addAll(List.of("-Xsuppress-version-warnings", "-Xjsr305=strict", "-opt-in=kotlin.RequiresOptIn")); |
| 46 | + compile.getKotlinOptions().setFreeCompilerArgs(freeCompilerArgs); |
| 47 | + } |
| 48 | + |
| 49 | +} |
0 commit comments