Skip to content

Commit

Permalink
Remove Kotlin jvmTarget option
Browse files Browse the repository at this point in the history
This is obsolete when using toolchains. The Kotlin plugin automatically
sets the jvmTarget to the used toolchain.

See gh-1227
  • Loading branch information
mhalbritter committed Jun 5, 2024
1 parent 2d65df4 commit be6fb64
Show file tree
Hide file tree
Showing 8 changed files with 0 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ public void customize(GradleBuild build) {

private void customizeCompilerOptions(GradleBuild build) {
build.extensions().customize("kotlin", (kotlin) -> kotlin.nested("compilerOptions", (compilerOptions) -> {
compilerOptions.attributeWithType("jvmTarget", getJvmTarget(), "org.jetbrains.kotlin.gradle.dsl.JvmTarget");
if (!CollectionUtils.isEmpty(this.settings.getCompilerArgs())) {
compilerOptions.invoke("freeCompilerArgs.addAll", quote(this.settings.getCompilerArgs()));
}
Expand All @@ -62,11 +61,4 @@ private List<String> quote(List<String> compilerArgs) {
return compilerArgs.stream().map((element) -> this.quote + element + this.quote).toList();
}

private String getJvmTarget() {
if ("1.8".equals(this.settings.getJvmTarget())) {
return "JvmTarget.JVM_1_8";
}
return "JvmTarget.JVM_" + this.settings.getJvmTarget();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,9 @@

package io.spring.initializr.generator.spring.code.kotlin;

import io.spring.initializr.generator.buildsystem.gradle.Attribute;
import io.spring.initializr.generator.buildsystem.gradle.GradleBuild;
import org.assertj.core.groups.Tuple;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.CsvSource;

import static org.assertj.core.api.Assertions.assertThat;

Expand All @@ -47,13 +44,10 @@ void kotlinPluginsAreConfigured() {
void shouldCustomizeCompilerOptions() {
GradleBuild build = new GradleBuild();
new KotlinGradleBuildCustomizer(new SimpleKotlinProjectSettings("1.2.70"), '\'').customize(build);
assertThat(build.extensions().importedTypes()).contains("org.jetbrains.kotlin.gradle.dsl.JvmTarget");
assertThat(build.extensions().values()).singleElement().satisfies((kotlin) -> {
assertThat(kotlin.getName()).isEqualTo("kotlin");
assertThat(kotlin.getNested().values()).singleElement().satisfies((compilerOptions) -> {
assertThat(compilerOptions.getName()).isEqualTo("compilerOptions");
assertThat(compilerOptions.getAttributes()).singleElement()
.isEqualTo(Attribute.set("jvmTarget", "JvmTarget.JVM_1_8"));
assertThat(compilerOptions.getInvocations()).singleElement().satisfies((freeCompilerArgs) -> {
assertThat(freeCompilerArgs.getTarget()).isEqualTo("freeCompilerArgs.addAll");
assertThat(freeCompilerArgs.getArguments()).containsExactly("'-Xjsr305=strict'");
Expand All @@ -62,19 +56,4 @@ void shouldCustomizeCompilerOptions() {
});
}

@ParameterizedTest
@CsvSource(textBlock = """
1.8, JvmTarget.JVM_1_8
17, JvmTarget.JVM_17
21, JvmTarget.JVM_21
""")
void shouldSetJvmTarget(String jvmTarget, String constant) {
GradleBuild build = new GradleBuild();
new KotlinGradleBuildCustomizer(new SimpleKotlinProjectSettings("1.2.70", jvmTarget), '\'').customize(build);
assertThat(build.extensions().values()).singleElement()
.satisfies((kotlin) -> assertThat(kotlin.getNested().values()).singleElement()
.satisfies((compilerOptions) -> assertThat(compilerOptions.getAttributes()).singleElement()
.isEqualTo(Attribute.set("jvmTarget", constant))));
}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import org.jetbrains.kotlin.gradle.dsl.JvmTarget

plugins {
id 'org.springframework.boot' version '2.4.1'
id 'io.spring.dependency-management' version '1.0.6.RELEASE'
Expand Down Expand Up @@ -30,7 +28,6 @@ dependencies {
kotlin {
compilerOptions {
freeCompilerArgs.addAll '-Xjsr305=strict'
jvmTarget = JvmTarget.JVM_11
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import org.jetbrains.kotlin.gradle.dsl.JvmTarget

plugins {
id("org.springframework.boot") version "2.4.1"
id("io.spring.dependency-management") version "1.0.6.RELEASE"
Expand Down Expand Up @@ -30,7 +28,6 @@ dependencies {
kotlin {
compilerOptions {
freeCompilerArgs.addAll("-Xjsr305=strict")
jvmTarget = JvmTarget.JVM_11
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import org.jetbrains.kotlin.gradle.dsl.JvmTarget

plugins {
id 'org.springframework.boot' version '2.4.1'
id 'io.spring.dependency-management' version '1.0.6.RELEASE'
Expand Down Expand Up @@ -30,7 +28,6 @@ dependencies {
kotlin {
compilerOptions {
freeCompilerArgs.addAll '-Xjsr305=strict'
jvmTarget = JvmTarget.JVM_1_8
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import org.jetbrains.kotlin.gradle.dsl.JvmTarget

plugins {
id("org.springframework.boot") version "2.4.1"
id("io.spring.dependency-management") version "1.0.6.RELEASE"
Expand Down Expand Up @@ -30,7 +28,6 @@ dependencies {
kotlin {
compilerOptions {
freeCompilerArgs.addAll("-Xjsr305=strict")
jvmTarget = JvmTarget.JVM_1_8
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import org.jetbrains.kotlin.gradle.dsl.JvmTarget

plugins {
id 'war'
id 'org.springframework.boot' version '2.4.1'
Expand Down Expand Up @@ -32,7 +30,6 @@ dependencies {
kotlin {
compilerOptions {
freeCompilerArgs.addAll '-Xjsr305=strict'
jvmTarget = JvmTarget.JVM_1_8
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import org.jetbrains.kotlin.gradle.dsl.JvmTarget

plugins {
war
id("org.springframework.boot") version "2.4.1"
Expand Down Expand Up @@ -32,7 +30,6 @@ dependencies {
kotlin {
compilerOptions {
freeCompilerArgs.addAll("-Xjsr305=strict")
jvmTarget = JvmTarget.JVM_1_8
}
}

Expand Down

0 comments on commit be6fb64

Please sign in to comment.