mirror of
https://gitee.com/dcren/initializr.git
synced 2025-09-19 01:58:16 +08:00
Make kotlin version mandatory only if Kotlin is enabled
Closes gh-617
This commit is contained in:
@@ -431,9 +431,9 @@ public class ProjectGenerator {
|
||||
// Add various versions
|
||||
model.put("dependencyManagementPluginVersion", metadata.getConfiguration()
|
||||
.getEnv().getGradle().getDependencyManagementPluginVersion());
|
||||
model.put("kotlinVersion", metadata.getConfiguration().getEnv().getKotlin()
|
||||
.resolveKotlinVersion(bootVersion));
|
||||
if ("kotlin".equals(request.getLanguage())) {
|
||||
model.put("kotlinVersion", metadata.getConfiguration().getEnv().getKotlin()
|
||||
.resolveKotlinVersion(bootVersion));
|
||||
model.put("kotlin", true);
|
||||
}
|
||||
if ("groovy".equals(request.getLanguage())) {
|
||||
|
@@ -20,6 +20,7 @@ import java.util.ArrayList;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.function.Supplier;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import io.spring.initializr.metadata.BillOfMaterials;
|
||||
@@ -228,14 +229,13 @@ public class ProjectRequest extends BasicProjectRequest {
|
||||
|
||||
protected void initializeProperties(InitializrMetadata metadata,
|
||||
Version requestedVersion) {
|
||||
String kotlinVersion = metadata.getConfiguration().getEnv().getKotlin()
|
||||
Supplier<String> kotlinVersion = () -> metadata.getConfiguration().getEnv().getKotlin()
|
||||
.resolveKotlinVersion(requestedVersion);
|
||||
if ("gradle".equals(this.build)) {
|
||||
this.buildProperties.getGradle().put("springBootVersion",
|
||||
this::getBootVersion);
|
||||
if ("kotlin".equals(getLanguage())) {
|
||||
this.buildProperties.getGradle().put("kotlinVersion",
|
||||
() -> kotlinVersion);
|
||||
this.buildProperties.getGradle().put("kotlinVersion", kotlinVersion);
|
||||
}
|
||||
}
|
||||
else {
|
||||
@@ -247,7 +247,7 @@ public class ProjectRequest extends BasicProjectRequest {
|
||||
this::getJavaVersion);
|
||||
if ("kotlin".equals(getLanguage())) {
|
||||
this.buildProperties.getVersions()
|
||||
.put(new VersionProperty("kotlin.version"), () -> kotlinVersion);
|
||||
.put(new VersionProperty("kotlin.version"), kotlinVersion);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -65,7 +65,7 @@ public abstract class AbstractProjectGeneratorTests {
|
||||
public void setup() throws IOException {
|
||||
Dependency web = Dependency.withId("web");
|
||||
web.getFacets().add("web");
|
||||
InitializrMetadata metadata = InitializrMetadataTestBuilder.withDefaults()
|
||||
InitializrMetadata metadata = initializeTestMetadataBuilder()
|
||||
.addDependencyGroup("web", web).addDependencyGroup("test", "security",
|
||||
"data-jpa", "aop", "batch", "integration")
|
||||
.build();
|
||||
@@ -76,6 +76,10 @@ public abstract class AbstractProjectGeneratorTests {
|
||||
this.projectGenerator.setTmpdir(this.folder.newFolder().getAbsolutePath());
|
||||
}
|
||||
|
||||
protected InitializrMetadataTestBuilder initializeTestMetadataBuilder() {
|
||||
return InitializrMetadataTestBuilder.withDefaults();
|
||||
}
|
||||
|
||||
protected PomAssert generateMavenPom(ProjectRequest request) {
|
||||
request.setType("maven-build");
|
||||
String content = new String(this.projectGenerator.generateMavenPom(request));
|
||||
|
@@ -48,6 +48,11 @@ public class ProjectGeneratorTests extends AbstractProjectGeneratorTests {
|
||||
@Rule
|
||||
public final ExpectedException thrown = ExpectedException.none();
|
||||
|
||||
@Override
|
||||
protected InitializrMetadataTestBuilder initializeTestMetadataBuilder() {
|
||||
return InitializrMetadataTestBuilder.withBasicDefaults();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void defaultMavenPom() {
|
||||
ProjectRequest request = createProjectRequest("web");
|
||||
@@ -348,6 +353,9 @@ public class ProjectGeneratorTests extends AbstractProjectGeneratorTests {
|
||||
request.setBootVersion("1.1.9.RELEASE");
|
||||
request.setName("MyDemo");
|
||||
request.setPackageName("foo");
|
||||
|
||||
applyMetadata(initializeTestMetadataBuilder().addDependencyGroup("core", "web")
|
||||
.setKotlinEnv("1.0.0").build());
|
||||
generateProject(request)
|
||||
.sourceCodeAssert("src/main/kotlin/foo/MyDemoApplication.kt")
|
||||
.hasImports(EnableAutoConfiguration.class.getName(),
|
||||
@@ -364,6 +372,9 @@ public class ProjectGeneratorTests extends AbstractProjectGeneratorTests {
|
||||
request.setBootVersion("1.2.0.RC1");
|
||||
request.setName("MyDemo");
|
||||
request.setPackageName("foo");
|
||||
|
||||
applyMetadata(initializeTestMetadataBuilder().addDependencyGroup("core", "web")
|
||||
.setKotlinEnv("1.0.0").build());
|
||||
generateProject(request)
|
||||
.sourceCodeAssert("src/main/kotlin/foo/MyDemoApplication.kt")
|
||||
.hasImports(SpringBootApplication.class.getName())
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2017 the original author or authors.
|
||||
* Copyright 2012-2018 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.
|
||||
@@ -43,7 +43,11 @@ public class InitializrMetadataTestBuilder {
|
||||
private final InitializrMetadataBuilder builder = InitializrMetadataBuilder.create();
|
||||
|
||||
public static InitializrMetadataTestBuilder withDefaults() {
|
||||
return new InitializrMetadataTestBuilder().addDefaults();
|
||||
return new InitializrMetadataTestBuilder().addAllDefaults();
|
||||
}
|
||||
|
||||
public static InitializrMetadataTestBuilder withBasicDefaults() {
|
||||
return new InitializrMetadataTestBuilder().addBasicDefaults();
|
||||
}
|
||||
|
||||
public InitializrMetadata build() {
|
||||
@@ -75,12 +79,16 @@ public class InitializrMetadataTestBuilder {
|
||||
return this;
|
||||
}
|
||||
|
||||
public InitializrMetadataTestBuilder addDefaults() {
|
||||
return addDefaultTypes().addDefaultPackagings().addDefaultJavaVersions()
|
||||
.addDefaultLanguages().addDefaultBootVersions()
|
||||
public InitializrMetadataTestBuilder addAllDefaults() {
|
||||
return addBasicDefaults()
|
||||
.setGradleEnv("0.5.1.RELEASE").setKotlinEnv("1.1.1");
|
||||
}
|
||||
|
||||
public InitializrMetadataTestBuilder addBasicDefaults() {
|
||||
return addDefaultTypes().addDefaultPackagings().addDefaultJavaVersions()
|
||||
.addDefaultLanguages().addDefaultBootVersions();
|
||||
}
|
||||
|
||||
public InitializrMetadataTestBuilder addDefaultTypes() {
|
||||
return addType("maven-build", false, "/pom.xml", "maven", "build")
|
||||
.addType("maven-project", true, "/starter.zip", "maven", "project")
|
||||
|
Reference in New Issue
Block a user