mirror of
https://gitee.com/dcren/initializr.git
synced 2025-12-02 11:24:04 +08:00
Remove explicit references to Java versions in the generator
Closes gh-543
This commit is contained in:
@@ -447,10 +447,11 @@ public class ProjectGenerator {
|
||||
model.put("servletInitializrImport", new Imports(request.getLanguage()).add(
|
||||
getServletInitializrClass(request)).toString());
|
||||
|
||||
// Kotlin-specific dep
|
||||
model.put("kotlinStdlibArtifactId", getKotlinStdlibArtifactId(request));
|
||||
|
||||
// Java versions
|
||||
model.put("isJava6", isJavaVersion(request, "1.6"));
|
||||
model.put("isJava7", isJavaVersion(request, "1.7"));
|
||||
model.put("isJava8", isJavaVersion(request, "1.8"));
|
||||
model.put("java8OrLater", isJava8OrLater(request));
|
||||
|
||||
// Append the project request to the model
|
||||
BeanWrapperImpl bean = new BeanWrapperImpl(request);
|
||||
@@ -549,6 +550,22 @@ public class ProjectGenerator {
|
||||
}
|
||||
}
|
||||
|
||||
protected String getKotlinStdlibArtifactId(ProjectRequest request) {
|
||||
String javaVersion = request.getJavaVersion();
|
||||
if ("1.6".equals(javaVersion)) {
|
||||
return "kotlin-stdlib";
|
||||
}
|
||||
else if ("1.7".equals(javaVersion)) {
|
||||
return "kotlin-stdlib-jre7";
|
||||
}
|
||||
return "kotlin-stdlib-jre8";
|
||||
}
|
||||
|
||||
private static boolean isJava8OrLater(ProjectRequest request) {
|
||||
return !request.getJavaVersion().equals("1.6")
|
||||
&& !request.getJavaVersion().equals("1.7");
|
||||
}
|
||||
|
||||
private static boolean isGradleBuild(ProjectRequest request) {
|
||||
return "gradle".equals(request.getBuild());
|
||||
}
|
||||
@@ -574,10 +591,6 @@ public class ProjectGenerator {
|
||||
return VERSION_2_0_0_M3.compareTo(bootVersion) < 0;
|
||||
}
|
||||
|
||||
private static boolean isJavaVersion(ProjectRequest request, String version) {
|
||||
return request.getJavaVersion().equals(version);
|
||||
}
|
||||
|
||||
private byte[] doGenerateMavenPom(Map<String, Object> model) {
|
||||
return templateRenderer.process("starter-pom.xml", model).getBytes();
|
||||
}
|
||||
|
||||
@@ -46,13 +46,13 @@ apply plugin: 'war'
|
||||
|
||||
group = '{{groupId}}'
|
||||
version = '{{version}}'
|
||||
sourceCompatibility = {{javaVersion}}{{#kotlin}}{{#isJava8}}
|
||||
sourceCompatibility = {{javaVersion}}{{#kotlin}}{{#java8OrLater}}
|
||||
compileKotlin {
|
||||
kotlinOptions.jvmTarget = "1.8"
|
||||
}
|
||||
compileTestKotlin {
|
||||
kotlinOptions.jvmTarget = "1.8"
|
||||
}{{/isJava8}}{{/kotlin}}
|
||||
}{{/java8OrLater}}{{/kotlin}}
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
@@ -83,15 +83,7 @@ dependencies {
|
||||
compile('org.codehaus.groovy:groovy')
|
||||
{{/groovy}}
|
||||
{{#kotlin}}
|
||||
{{#isJava6}}
|
||||
compile("org.jetbrains.kotlin:kotlin-stdlib:${kotlinVersion}")
|
||||
{{/isJava6}}
|
||||
{{#isJava7}}
|
||||
compile("org.jetbrains.kotlin:kotlin-stdlib-jre7{{^kotlinSupport}}:${kotlinVersion}{{/kotlinSupport}}")
|
||||
{{/isJava7}}
|
||||
{{#isJava8}}
|
||||
compile("org.jetbrains.kotlin:kotlin-stdlib-jre8{{^kotlinSupport}}:${kotlinVersion}{{/kotlinSupport}}")
|
||||
{{/isJava8}}
|
||||
compile("org.jetbrains.kotlin:{{kotlinStdlibArtifactId}}{{^kotlinSupport}}:${kotlinVersion}{{/kotlinSupport}}")
|
||||
compile("org.jetbrains.kotlin:kotlin-reflect{{^kotlinSupport}}:${kotlinVersion}{{/kotlinSupport}}")
|
||||
{{/kotlin}}
|
||||
{{#runtimeDependencies}}
|
||||
|
||||
@@ -46,18 +46,10 @@
|
||||
<artifactId>groovy</artifactId>
|
||||
</dependency>
|
||||
{{/groovy}}
|
||||
{{#kotlin}}
|
||||
{{#kotlin}}
|
||||
<dependency>
|
||||
<groupId>org.jetbrains.kotlin</groupId>
|
||||
{{#isJava6}}
|
||||
<artifactId>kotlin-stdlib</artifactId>
|
||||
{{/isJava6}}
|
||||
{{#isJava7}}
|
||||
<artifactId>kotlin-stdlib-jre7</artifactId>
|
||||
{{/isJava7}}
|
||||
{{#isJava8}}
|
||||
<artifactId>kotlin-stdlib-jre8</artifactId>
|
||||
{{/isJava8}}
|
||||
<artifactId>{{kotlinStdlibArtifactId}}</artifactId>
|
||||
{{^kotlinSupport}}
|
||||
<version>${kotlin.version}</version>
|
||||
{{/kotlinSupport}}
|
||||
@@ -189,9 +181,9 @@
|
||||
<plugin>spring</plugin>
|
||||
</compilerPlugins>
|
||||
{{^kotlinSupport}}
|
||||
{{#isJava8}}
|
||||
{{#java8OrLater}}
|
||||
<jvmTarget>1.8</jvmTarget>
|
||||
{{/isJava8}}
|
||||
{{/java8OrLater}}
|
||||
{{/kotlinSupport}}
|
||||
</configuration>
|
||||
{{^kotlinSupport}}
|
||||
|
||||
@@ -215,6 +215,17 @@ public class ProjectGeneratorBuildTests extends AbstractProjectGeneratorTests {
|
||||
"project/" + build + "/kotlin-springboot2-" + assertFileName));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void kotlinJava9() {
|
||||
ProjectRequest request = createProjectRequest();
|
||||
request.setLanguage("kotlin");
|
||||
request.setBootVersion("2.0.0.M6");
|
||||
request.setJavaVersion("9");
|
||||
ProjectAssert project = generateProject(request);
|
||||
project.sourceCodeAssert(fileName).equalsTo(new ClassPathResource(
|
||||
"project/" + build + "/kotlin-java9-" + assertFileName));
|
||||
}
|
||||
|
||||
@Override
|
||||
public ProjectRequest createProjectRequest(String... styles) {
|
||||
ProjectRequest request = super.createProjectRequest(styles);
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
buildscript {
|
||||
ext {
|
||||
kotlinVersion = '1.1.1'
|
||||
springBootVersion = '2.0.0.M6'
|
||||
}
|
||||
repositories {
|
||||
mavenCentral()
|
||||
maven { url "https://repo.spring.io/snapshot" }
|
||||
maven { url "https://repo.spring.io/milestone" }
|
||||
}
|
||||
dependencies {
|
||||
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
|
||||
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:${kotlinVersion}")
|
||||
classpath("org.jetbrains.kotlin:kotlin-allopen:${kotlinVersion}")
|
||||
}
|
||||
}
|
||||
|
||||
apply plugin: 'kotlin'
|
||||
apply plugin: 'kotlin-spring'
|
||||
apply plugin: 'eclipse'
|
||||
apply plugin: 'org.springframework.boot'
|
||||
apply plugin: 'io.spring.dependency-management'
|
||||
|
||||
group = 'com.example'
|
||||
version = '0.0.1-SNAPSHOT'
|
||||
sourceCompatibility = 9
|
||||
compileKotlin {
|
||||
kotlinOptions.jvmTarget = "1.8"
|
||||
}
|
||||
compileTestKotlin {
|
||||
kotlinOptions.jvmTarget = "1.8"
|
||||
}
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
maven { url "https://repo.spring.io/snapshot" }
|
||||
maven { url "https://repo.spring.io/milestone" }
|
||||
}
|
||||
|
||||
|
||||
dependencies {
|
||||
compile('org.springframework.boot:spring-boot-starter')
|
||||
compile("org.jetbrains.kotlin:kotlin-stdlib-jre8")
|
||||
compile("org.jetbrains.kotlin:kotlin-reflect")
|
||||
testCompile('org.springframework.boot:spring-boot-starter-test')
|
||||
}
|
||||
@@ -0,0 +1,115 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>com.example</groupId>
|
||||
<artifactId>demo</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>demo</name>
|
||||
<description>Demo project for Spring Boot</description>
|
||||
|
||||
<parent>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-parent</artifactId>
|
||||
<version>2.0.0.M6</version>
|
||||
<relativePath/> <!-- lookup parent from repository -->
|
||||
</parent>
|
||||
|
||||
<properties>
|
||||
<kotlin.compiler.incremental>true</kotlin.compiler.incremental>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
|
||||
<java.version>9</java.version>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.jetbrains.kotlin</groupId>
|
||||
<artifactId>kotlin-stdlib-jre8</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.jetbrains.kotlin</groupId>
|
||||
<artifactId>kotlin-reflect</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<sourceDirectory>${project.basedir}/src/main/kotlin</sourceDirectory>
|
||||
<testSourceDirectory>${project.basedir}/src/test/kotlin</testSourceDirectory>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>kotlin-maven-plugin</artifactId>
|
||||
<groupId>org.jetbrains.kotlin</groupId>
|
||||
<configuration>
|
||||
<compilerPlugins>
|
||||
<plugin>spring</plugin>
|
||||
</compilerPlugins>
|
||||
</configuration>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.jetbrains.kotlin</groupId>
|
||||
<artifactId>kotlin-maven-allopen</artifactId>
|
||||
<version>${kotlin.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>spring-snapshots</id>
|
||||
<name>Spring Snapshots</name>
|
||||
<url>https://repo.spring.io/snapshot</url>
|
||||
<snapshots>
|
||||
<enabled>true</enabled>
|
||||
</snapshots>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>spring-milestones</id>
|
||||
<name>Spring Milestones</name>
|
||||
<url>https://repo.spring.io/milestone</url>
|
||||
<snapshots>
|
||||
<enabled>false</enabled>
|
||||
</snapshots>
|
||||
</repository>
|
||||
</repositories>
|
||||
|
||||
<pluginRepositories>
|
||||
<pluginRepository>
|
||||
<id>spring-snapshots</id>
|
||||
<name>Spring Snapshots</name>
|
||||
<url>https://repo.spring.io/snapshot</url>
|
||||
<snapshots>
|
||||
<enabled>true</enabled>
|
||||
</snapshots>
|
||||
</pluginRepository>
|
||||
<pluginRepository>
|
||||
<id>spring-milestones</id>
|
||||
<name>Spring Milestones</name>
|
||||
<url>https://repo.spring.io/milestone</url>
|
||||
<snapshots>
|
||||
<enabled>false</enabled>
|
||||
</snapshots>
|
||||
</pluginRepository>
|
||||
</pluginRepositories>
|
||||
|
||||
|
||||
</project>
|
||||
Reference in New Issue
Block a user