mirror of
https://gitee.com/dcren/initializr.git
synced 2026-09-19 06:17:42 +08:00
Make kotlin version mandatory only if Kotlin is enabled
Closes gh-617
This commit is contained in:
@@ -45,7 +45,7 @@ generation uses one of these names, the default is used instead.
|
|||||||
* `googleAnalyticsTrackingCode`: the Google Analytics code to use. If this is set,
|
* `googleAnalyticsTrackingCode`: the Google Analytics code to use. If this is set,
|
||||||
Google analytics is automatically enabled.
|
Google analytics is automatically enabled.
|
||||||
* `kotlin`: kotlin-specific settings. For now, only the kotlin version to use can be
|
* `kotlin`: kotlin-specific settings. For now, only the kotlin version to use can be
|
||||||
configured.
|
configured and is a mandatory option if Kotlin is enabled.
|
||||||
* `maven`: maven-specified settings. A custom maven parent POM can be defined and
|
* `maven`: maven-specified settings. A custom maven parent POM can be defined and
|
||||||
whether or not the `spring-boot-dependencies` BOM should be automatically added to
|
whether or not the `spring-boot-dependencies` BOM should be automatically added to
|
||||||
the project.
|
the project.
|
||||||
|
|||||||
+2
-2
@@ -431,9 +431,9 @@ public class ProjectGenerator {
|
|||||||
// Add various versions
|
// Add various versions
|
||||||
model.put("dependencyManagementPluginVersion", metadata.getConfiguration()
|
model.put("dependencyManagementPluginVersion", metadata.getConfiguration()
|
||||||
.getEnv().getGradle().getDependencyManagementPluginVersion());
|
.getEnv().getGradle().getDependencyManagementPluginVersion());
|
||||||
model.put("kotlinVersion", metadata.getConfiguration().getEnv().getKotlin()
|
|
||||||
.resolveKotlinVersion(bootVersion));
|
|
||||||
if ("kotlin".equals(request.getLanguage())) {
|
if ("kotlin".equals(request.getLanguage())) {
|
||||||
|
model.put("kotlinVersion", metadata.getConfiguration().getEnv().getKotlin()
|
||||||
|
.resolveKotlinVersion(bootVersion));
|
||||||
model.put("kotlin", true);
|
model.put("kotlin", true);
|
||||||
}
|
}
|
||||||
if ("groovy".equals(request.getLanguage())) {
|
if ("groovy".equals(request.getLanguage())) {
|
||||||
|
|||||||
+4
-4
@@ -20,6 +20,7 @@ import java.util.ArrayList;
|
|||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.function.Supplier;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import io.spring.initializr.metadata.BillOfMaterials;
|
import io.spring.initializr.metadata.BillOfMaterials;
|
||||||
@@ -228,14 +229,13 @@ public class ProjectRequest extends BasicProjectRequest {
|
|||||||
|
|
||||||
protected void initializeProperties(InitializrMetadata metadata,
|
protected void initializeProperties(InitializrMetadata metadata,
|
||||||
Version requestedVersion) {
|
Version requestedVersion) {
|
||||||
String kotlinVersion = metadata.getConfiguration().getEnv().getKotlin()
|
Supplier<String> kotlinVersion = () -> metadata.getConfiguration().getEnv().getKotlin()
|
||||||
.resolveKotlinVersion(requestedVersion);
|
.resolveKotlinVersion(requestedVersion);
|
||||||
if ("gradle".equals(this.build)) {
|
if ("gradle".equals(this.build)) {
|
||||||
this.buildProperties.getGradle().put("springBootVersion",
|
this.buildProperties.getGradle().put("springBootVersion",
|
||||||
this::getBootVersion);
|
this::getBootVersion);
|
||||||
if ("kotlin".equals(getLanguage())) {
|
if ("kotlin".equals(getLanguage())) {
|
||||||
this.buildProperties.getGradle().put("kotlinVersion",
|
this.buildProperties.getGradle().put("kotlinVersion", kotlinVersion);
|
||||||
() -> kotlinVersion);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@@ -247,7 +247,7 @@ public class ProjectRequest extends BasicProjectRequest {
|
|||||||
this::getJavaVersion);
|
this::getJavaVersion);
|
||||||
if ("kotlin".equals(getLanguage())) {
|
if ("kotlin".equals(getLanguage())) {
|
||||||
this.buildProperties.getVersions()
|
this.buildProperties.getVersions()
|
||||||
.put(new VersionProperty("kotlin.version"), () -> kotlinVersion);
|
.put(new VersionProperty("kotlin.version"), kotlinVersion);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+5
-1
@@ -65,7 +65,7 @@ public abstract class AbstractProjectGeneratorTests {
|
|||||||
public void setup() throws IOException {
|
public void setup() throws IOException {
|
||||||
Dependency web = Dependency.withId("web");
|
Dependency web = Dependency.withId("web");
|
||||||
web.getFacets().add("web");
|
web.getFacets().add("web");
|
||||||
InitializrMetadata metadata = InitializrMetadataTestBuilder.withDefaults()
|
InitializrMetadata metadata = initializeTestMetadataBuilder()
|
||||||
.addDependencyGroup("web", web).addDependencyGroup("test", "security",
|
.addDependencyGroup("web", web).addDependencyGroup("test", "security",
|
||||||
"data-jpa", "aop", "batch", "integration")
|
"data-jpa", "aop", "batch", "integration")
|
||||||
.build();
|
.build();
|
||||||
@@ -76,6 +76,10 @@ public abstract class AbstractProjectGeneratorTests {
|
|||||||
this.projectGenerator.setTmpdir(this.folder.newFolder().getAbsolutePath());
|
this.projectGenerator.setTmpdir(this.folder.newFolder().getAbsolutePath());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected InitializrMetadataTestBuilder initializeTestMetadataBuilder() {
|
||||||
|
return InitializrMetadataTestBuilder.withDefaults();
|
||||||
|
}
|
||||||
|
|
||||||
protected PomAssert generateMavenPom(ProjectRequest request) {
|
protected PomAssert generateMavenPom(ProjectRequest request) {
|
||||||
request.setType("maven-build");
|
request.setType("maven-build");
|
||||||
String content = new String(this.projectGenerator.generateMavenPom(request));
|
String content = new String(this.projectGenerator.generateMavenPom(request));
|
||||||
|
|||||||
+11
@@ -48,6 +48,11 @@ public class ProjectGeneratorTests extends AbstractProjectGeneratorTests {
|
|||||||
@Rule
|
@Rule
|
||||||
public final ExpectedException thrown = ExpectedException.none();
|
public final ExpectedException thrown = ExpectedException.none();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected InitializrMetadataTestBuilder initializeTestMetadataBuilder() {
|
||||||
|
return InitializrMetadataTestBuilder.withBasicDefaults();
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void defaultMavenPom() {
|
public void defaultMavenPom() {
|
||||||
ProjectRequest request = createProjectRequest("web");
|
ProjectRequest request = createProjectRequest("web");
|
||||||
@@ -348,6 +353,9 @@ public class ProjectGeneratorTests extends AbstractProjectGeneratorTests {
|
|||||||
request.setBootVersion("1.1.9.RELEASE");
|
request.setBootVersion("1.1.9.RELEASE");
|
||||||
request.setName("MyDemo");
|
request.setName("MyDemo");
|
||||||
request.setPackageName("foo");
|
request.setPackageName("foo");
|
||||||
|
|
||||||
|
applyMetadata(initializeTestMetadataBuilder().addDependencyGroup("core", "web")
|
||||||
|
.setKotlinEnv("1.0.0").build());
|
||||||
generateProject(request)
|
generateProject(request)
|
||||||
.sourceCodeAssert("src/main/kotlin/foo/MyDemoApplication.kt")
|
.sourceCodeAssert("src/main/kotlin/foo/MyDemoApplication.kt")
|
||||||
.hasImports(EnableAutoConfiguration.class.getName(),
|
.hasImports(EnableAutoConfiguration.class.getName(),
|
||||||
@@ -364,6 +372,9 @@ public class ProjectGeneratorTests extends AbstractProjectGeneratorTests {
|
|||||||
request.setBootVersion("1.2.0.RC1");
|
request.setBootVersion("1.2.0.RC1");
|
||||||
request.setName("MyDemo");
|
request.setName("MyDemo");
|
||||||
request.setPackageName("foo");
|
request.setPackageName("foo");
|
||||||
|
|
||||||
|
applyMetadata(initializeTestMetadataBuilder().addDependencyGroup("core", "web")
|
||||||
|
.setKotlinEnv("1.0.0").build());
|
||||||
generateProject(request)
|
generateProject(request)
|
||||||
.sourceCodeAssert("src/main/kotlin/foo/MyDemoApplication.kt")
|
.sourceCodeAssert("src/main/kotlin/foo/MyDemoApplication.kt")
|
||||||
.hasImports(SpringBootApplication.class.getName())
|
.hasImports(SpringBootApplication.class.getName())
|
||||||
|
|||||||
+13
-5
@@ -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");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with 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();
|
private final InitializrMetadataBuilder builder = InitializrMetadataBuilder.create();
|
||||||
|
|
||||||
public static InitializrMetadataTestBuilder withDefaults() {
|
public static InitializrMetadataTestBuilder withDefaults() {
|
||||||
return new InitializrMetadataTestBuilder().addDefaults();
|
return new InitializrMetadataTestBuilder().addAllDefaults();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static InitializrMetadataTestBuilder withBasicDefaults() {
|
||||||
|
return new InitializrMetadataTestBuilder().addBasicDefaults();
|
||||||
}
|
}
|
||||||
|
|
||||||
public InitializrMetadata build() {
|
public InitializrMetadata build() {
|
||||||
@@ -75,12 +79,16 @@ public class InitializrMetadataTestBuilder {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public InitializrMetadataTestBuilder addDefaults() {
|
public InitializrMetadataTestBuilder addAllDefaults() {
|
||||||
return addDefaultTypes().addDefaultPackagings().addDefaultJavaVersions()
|
return addBasicDefaults()
|
||||||
.addDefaultLanguages().addDefaultBootVersions()
|
|
||||||
.setGradleEnv("0.5.1.RELEASE").setKotlinEnv("1.1.1");
|
.setGradleEnv("0.5.1.RELEASE").setKotlinEnv("1.1.1");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public InitializrMetadataTestBuilder addBasicDefaults() {
|
||||||
|
return addDefaultTypes().addDefaultPackagings().addDefaultJavaVersions()
|
||||||
|
.addDefaultLanguages().addDefaultBootVersions();
|
||||||
|
}
|
||||||
|
|
||||||
public InitializrMetadataTestBuilder addDefaultTypes() {
|
public InitializrMetadataTestBuilder addDefaultTypes() {
|
||||||
return addType("maven-build", false, "/pom.xml", "maven", "build")
|
return addType("maven-build", false, "/pom.xml", "maven", "build")
|
||||||
.addType("maven-project", true, "/starter.zip", "maven", "project")
|
.addType("maven-project", true, "/starter.zip", "maven", "project")
|
||||||
|
|||||||
Reference in New Issue
Block a user