From 3f1e44b7d3a6aa7cd1d7848f332016a47c7a0569 Mon Sep 17 00:00:00 2001 From: KotlinIsland Date: Wed, 22 Feb 2023 14:05:16 +1000 Subject: [PATCH] Don't include kotlin stdlib for gradle builds See gh-1376 --- .../code/kotlin/KotlinDependenciesConfigurer.java | 2 -- .../code/kotlin/KotlinMavenBuildCustomizer.java | 4 ++++ .../kotlin/KotlinDependenciesConfigurerTests.java | 15 ++------------- .../kotlin/KotlinMavenBuildCustomizerTests.java | 13 +++++++++++++ .../project/gradle/kotlin-java11-build.gradle.gen | 1 - .../gradle/kotlin-java11-build.gradle.kts.gen | 1 - .../project/kotlin/standard/build.gradle.gen | 1 - .../project/kotlin/standard/build.gradle.kts.gen | 1 - .../project/kotlin/standard/war-build.gradle.gen | 1 - .../kotlin/standard/war-build.gradle.kts.gen | 1 - 10 files changed, 19 insertions(+), 21 deletions(-) diff --git a/initializr-generator-spring/src/main/java/io/spring/initializr/generator/spring/code/kotlin/KotlinDependenciesConfigurer.java b/initializr-generator-spring/src/main/java/io/spring/initializr/generator/spring/code/kotlin/KotlinDependenciesConfigurer.java index 0bcf6662a8..46359ffb7b 100644 --- a/initializr-generator-spring/src/main/java/io/spring/initializr/generator/spring/code/kotlin/KotlinDependenciesConfigurer.java +++ b/initializr-generator-spring/src/main/java/io/spring/initializr/generator/spring/code/kotlin/KotlinDependenciesConfigurer.java @@ -31,8 +31,6 @@ class KotlinDependenciesConfigurer implements BuildCustomizer { @Override public void customize(Build build) { - build.dependencies().add("kotlin-stdlib", Dependency - .withCoordinates("org.jetbrains.kotlin", "kotlin-stdlib-jdk8").scope(DependencyScope.COMPILE)); build.dependencies().add("kotlin-reflect", Dependency.withCoordinates("org.jetbrains.kotlin", "kotlin-reflect").scope(DependencyScope.COMPILE)); } diff --git a/initializr-generator-spring/src/main/java/io/spring/initializr/generator/spring/code/kotlin/KotlinMavenBuildCustomizer.java b/initializr-generator-spring/src/main/java/io/spring/initializr/generator/spring/code/kotlin/KotlinMavenBuildCustomizer.java index faa9965d7e..b106e2521b 100644 --- a/initializr-generator-spring/src/main/java/io/spring/initializr/generator/spring/code/kotlin/KotlinMavenBuildCustomizer.java +++ b/initializr-generator-spring/src/main/java/io/spring/initializr/generator/spring/code/kotlin/KotlinMavenBuildCustomizer.java @@ -16,6 +16,8 @@ package io.spring.initializr.generator.spring.code.kotlin; +import io.spring.initializr.generator.buildsystem.Dependency; +import io.spring.initializr.generator.buildsystem.DependencyScope; import io.spring.initializr.generator.buildsystem.maven.MavenBuild; import io.spring.initializr.generator.spring.build.BuildCustomizer; @@ -50,6 +52,8 @@ public void customize(MavenBuild build) { }); kotlinMavenPlugin.dependency("org.jetbrains.kotlin", "kotlin-maven-allopen", "${kotlin.version}"); }); + build.dependencies().add("kotlin-stdlib", Dependency + .withCoordinates("org.jetbrains.kotlin", "kotlin-stdlib-jdk8").scope(DependencyScope.COMPILE)); } } diff --git a/initializr-generator-spring/src/test/java/io/spring/initializr/generator/spring/code/kotlin/KotlinDependenciesConfigurerTests.java b/initializr-generator-spring/src/test/java/io/spring/initializr/generator/spring/code/kotlin/KotlinDependenciesConfigurerTests.java index d25946b9c2..b0cb518f5b 100644 --- a/initializr-generator-spring/src/test/java/io/spring/initializr/generator/spring/code/kotlin/KotlinDependenciesConfigurerTests.java +++ b/initializr-generator-spring/src/test/java/io/spring/initializr/generator/spring/code/kotlin/KotlinDependenciesConfigurerTests.java @@ -17,7 +17,6 @@ package io.spring.initializr.generator.spring.code.kotlin; import io.spring.initializr.generator.buildsystem.Dependency; -import io.spring.initializr.generator.buildsystem.DependencyScope; import io.spring.initializr.generator.buildsystem.gradle.GradleBuild; import io.spring.initializr.generator.buildsystem.maven.MavenBuild; import org.junit.jupiter.api.Test; @@ -35,12 +34,7 @@ class KotlinDependenciesConfigurerTests { void configuresDependenciesForGradleBuild() { GradleBuild build = new GradleBuild(); new KotlinDependenciesConfigurer().customize(build); - assertThat(build.dependencies().ids()).containsOnly("kotlin-stdlib", "kotlin-reflect"); - Dependency kotlinStdlib = build.dependencies().get("kotlin-stdlib"); - assertThat(kotlinStdlib.getGroupId()).isEqualTo("org.jetbrains.kotlin"); - assertThat(kotlinStdlib.getArtifactId()).isEqualTo("kotlin-stdlib-jdk8"); - assertThat(kotlinStdlib.getVersion()).isNull(); - assertThat(kotlinStdlib.getScope()).isEqualTo(DependencyScope.COMPILE); + assertThat(build.dependencies().ids()).containsOnly("kotlin-reflect"); Dependency kotlinReflect = build.dependencies().get("kotlin-reflect"); assertThat(kotlinReflect.getGroupId()).isEqualTo("org.jetbrains.kotlin"); assertThat(kotlinReflect.getArtifactId()).isEqualTo("kotlin-reflect"); @@ -51,12 +45,7 @@ void configuresDependenciesForGradleBuild() { void configuresDependenciesForMavenBuild() { MavenBuild build = new MavenBuild(); new KotlinDependenciesConfigurer().customize(build); - assertThat(build.dependencies().ids()).containsOnly("kotlin-stdlib", "kotlin-reflect"); - Dependency kotlinStdlib = build.dependencies().get("kotlin-stdlib"); - assertThat(kotlinStdlib.getGroupId()).isEqualTo("org.jetbrains.kotlin"); - assertThat(kotlinStdlib.getArtifactId()).isEqualTo("kotlin-stdlib-jdk8"); - assertThat(kotlinStdlib.getVersion()).isNull(); - assertThat(kotlinStdlib.getScope()).isEqualTo(DependencyScope.COMPILE); + assertThat(build.dependencies().ids()).containsOnly("kotlin-reflect"); Dependency kotlinReflect = build.dependencies().get("kotlin-reflect"); assertThat(kotlinReflect.getGroupId()).isEqualTo("org.jetbrains.kotlin"); assertThat(kotlinReflect.getArtifactId()).isEqualTo("kotlin-reflect"); diff --git a/initializr-generator-spring/src/test/java/io/spring/initializr/generator/spring/code/kotlin/KotlinMavenBuildCustomizerTests.java b/initializr-generator-spring/src/test/java/io/spring/initializr/generator/spring/code/kotlin/KotlinMavenBuildCustomizerTests.java index acd3a94f83..2656b1bc67 100644 --- a/initializr-generator-spring/src/test/java/io/spring/initializr/generator/spring/code/kotlin/KotlinMavenBuildCustomizerTests.java +++ b/initializr-generator-spring/src/test/java/io/spring/initializr/generator/spring/code/kotlin/KotlinMavenBuildCustomizerTests.java @@ -19,6 +19,7 @@ import java.util.Arrays; import java.util.List; +import io.spring.initializr.generator.buildsystem.DependencyScope; import io.spring.initializr.generator.buildsystem.maven.MavenBuild; import io.spring.initializr.generator.buildsystem.maven.MavenPlugin.Configuration; import io.spring.initializr.generator.buildsystem.maven.MavenPlugin.Dependency; @@ -98,6 +99,18 @@ void kotlinMavenPluginWithSeveralArgs() { }); } + @Test + void kotlinMavenKotlinStdlibIsConfigured() { + MavenBuild build = new MavenBuild(); + new KotlinMavenBuildCustomizer(new TestKotlinProjectSettings()).customize(build); + assertThat(build.dependencies().ids()).containsOnly("kotlin-stdlib"); + io.spring.initializr.generator.buildsystem.Dependency kotlinStdlib = build.dependencies().get("kotlin-stdlib"); + assertThat(kotlinStdlib.getGroupId()).isEqualTo("org.jetbrains.kotlin"); + assertThat(kotlinStdlib.getArtifactId()).isEqualTo("kotlin-stdlib-jdk8"); + assertThat(kotlinStdlib.getVersion()).isNull(); + assertThat(kotlinStdlib.getScope()).isEqualTo(DependencyScope.COMPILE); + } + private static class TestKotlinProjectSettings extends SimpleKotlinProjectSettings { TestKotlinProjectSettings() { diff --git a/initializr-generator-spring/src/test/resources/project/gradle/kotlin-java11-build.gradle.gen b/initializr-generator-spring/src/test/resources/project/gradle/kotlin-java11-build.gradle.gen index 6d8089d3ec..38fcf07c19 100644 --- a/initializr-generator-spring/src/test/resources/project/gradle/kotlin-java11-build.gradle.gen +++ b/initializr-generator-spring/src/test/resources/project/gradle/kotlin-java11-build.gradle.gen @@ -18,7 +18,6 @@ repositories { dependencies { implementation 'org.springframework.boot:spring-boot-starter' implementation 'org.jetbrains.kotlin:kotlin-reflect' - implementation 'org.jetbrains.kotlin:kotlin-stdlib-jdk8' testImplementation 'org.springframework.boot:spring-boot-starter-test' } diff --git a/initializr-generator-spring/src/test/resources/project/gradle/kotlin-java11-build.gradle.kts.gen b/initializr-generator-spring/src/test/resources/project/gradle/kotlin-java11-build.gradle.kts.gen index 39b99025ab..b0b1d17765 100644 --- a/initializr-generator-spring/src/test/resources/project/gradle/kotlin-java11-build.gradle.kts.gen +++ b/initializr-generator-spring/src/test/resources/project/gradle/kotlin-java11-build.gradle.kts.gen @@ -18,7 +18,6 @@ repositories { dependencies { implementation("org.springframework.boot:spring-boot-starter") implementation("org.jetbrains.kotlin:kotlin-reflect") - implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8") testImplementation("org.springframework.boot:spring-boot-starter-test") } diff --git a/initializr-generator-spring/src/test/resources/project/kotlin/standard/build.gradle.gen b/initializr-generator-spring/src/test/resources/project/kotlin/standard/build.gradle.gen index 1ed61a30e7..e0cb72eeaf 100644 --- a/initializr-generator-spring/src/test/resources/project/kotlin/standard/build.gradle.gen +++ b/initializr-generator-spring/src/test/resources/project/kotlin/standard/build.gradle.gen @@ -18,7 +18,6 @@ repositories { dependencies { implementation 'org.springframework.boot:spring-boot-starter' implementation 'org.jetbrains.kotlin:kotlin-reflect' - implementation 'org.jetbrains.kotlin:kotlin-stdlib-jdk8' testImplementation 'org.springframework.boot:spring-boot-starter-test' } diff --git a/initializr-generator-spring/src/test/resources/project/kotlin/standard/build.gradle.kts.gen b/initializr-generator-spring/src/test/resources/project/kotlin/standard/build.gradle.kts.gen index e420ac35d2..1477f21a4e 100644 --- a/initializr-generator-spring/src/test/resources/project/kotlin/standard/build.gradle.kts.gen +++ b/initializr-generator-spring/src/test/resources/project/kotlin/standard/build.gradle.kts.gen @@ -18,7 +18,6 @@ repositories { dependencies { implementation("org.springframework.boot:spring-boot-starter") implementation("org.jetbrains.kotlin:kotlin-reflect") - implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8") testImplementation("org.springframework.boot:spring-boot-starter-test") } diff --git a/initializr-generator-spring/src/test/resources/project/kotlin/standard/war-build.gradle.gen b/initializr-generator-spring/src/test/resources/project/kotlin/standard/war-build.gradle.gen index f25522953c..e71a201cdf 100644 --- a/initializr-generator-spring/src/test/resources/project/kotlin/standard/war-build.gradle.gen +++ b/initializr-generator-spring/src/test/resources/project/kotlin/standard/war-build.gradle.gen @@ -19,7 +19,6 @@ repositories { dependencies { implementation 'org.springframework.boot:spring-boot-starter-web' implementation 'org.jetbrains.kotlin:kotlin-reflect' - implementation 'org.jetbrains.kotlin:kotlin-stdlib-jdk8' providedRuntime 'org.springframework.boot:spring-boot-starter-tomcat' testImplementation 'org.springframework.boot:spring-boot-starter-test' } diff --git a/initializr-generator-spring/src/test/resources/project/kotlin/standard/war-build.gradle.kts.gen b/initializr-generator-spring/src/test/resources/project/kotlin/standard/war-build.gradle.kts.gen index a7efd02142..225eaf0317 100644 --- a/initializr-generator-spring/src/test/resources/project/kotlin/standard/war-build.gradle.kts.gen +++ b/initializr-generator-spring/src/test/resources/project/kotlin/standard/war-build.gradle.kts.gen @@ -19,7 +19,6 @@ repositories { dependencies { implementation("org.springframework.boot:spring-boot-starter-web") implementation("org.jetbrains.kotlin:kotlin-reflect") - implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8") providedRuntime("org.springframework.boot:spring-boot-starter-tomcat") testImplementation("org.springframework.boot:spring-boot-starter-test") }