mirror of
https://gitee.com/dcren/initializr.git
synced 2026-02-25 21:22:58 +08:00
Harmonize how Spring Boot plugin is configured with Gradle
Closes gh-980
This commit is contained in:
@@ -101,9 +101,10 @@ public class GradleProjectGenerationConfiguration {
|
||||
|
||||
@Bean
|
||||
@ConditionalOnPlatformVersion("2.0.0.M1")
|
||||
@ConditionalOnBuildSystem(id = GradleBuildSystem.ID, dialect = GradleBuildSystem.DIALECT_GROOVY)
|
||||
public BuildCustomizer<GradleBuild> applyDependencyManagementPluginContributor() {
|
||||
return (build) -> build.plugins().apply("io.spring.dependency-management");
|
||||
BuildCustomizer<GradleBuild> springBootPluginContributor(ResolvedProjectDescription projectDescription,
|
||||
ObjectProvider<DependencyManagementPluginVersionResolver> versionResolver, InitializrMetadata metadata) {
|
||||
return new SpringBootPluginBuildCustomizer(projectDescription, versionResolver
|
||||
.getIfAvailable(() -> new InitializrDependencyManagementPluginVersionResolver(metadata)));
|
||||
}
|
||||
|
||||
@Bean
|
||||
@@ -243,20 +244,6 @@ public class GradleProjectGenerationConfiguration {
|
||||
new KotlinDslGradleSettingsWriter(), "settings.gradle.kts");
|
||||
}
|
||||
|
||||
@Bean
|
||||
BuildCustomizer<GradleBuild> springBootPluginContributor(ResolvedProjectDescription projectDescription,
|
||||
ObjectProvider<DependencyManagementPluginVersionResolver> versionResolver,
|
||||
InitializrMetadata metadata) {
|
||||
return (build) -> {
|
||||
build.plugins().add("org.springframework.boot",
|
||||
(plugin) -> plugin.setVersion(projectDescription.getPlatformVersion().toString()));
|
||||
build.plugins().add("io.spring.dependency-management",
|
||||
(plugin) -> plugin.setVersion(versionResolver
|
||||
.getIfAvailable(() -> new InitializrDependencyManagementPluginVersionResolver(metadata))
|
||||
.resolveDependencyManagementPluginVersion(projectDescription)));
|
||||
};
|
||||
}
|
||||
|
||||
@Bean
|
||||
@ConditionalOnPlatformVersion("2.2.0.M3")
|
||||
BuildCustomizer<GradleBuild> testTaskContributor() {
|
||||
|
||||
@@ -0,0 +1,60 @@
|
||||
/*
|
||||
* Copyright 2012-2019 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.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package io.spring.initializr.generator.spring.build.gradle;
|
||||
|
||||
import io.spring.initializr.generator.buildsystem.gradle.GradleBuild;
|
||||
import io.spring.initializr.generator.project.ResolvedProjectDescription;
|
||||
import io.spring.initializr.generator.spring.build.BuildCustomizer;
|
||||
|
||||
/**
|
||||
* A {@link BuildCustomizer} to configure the Spring Boot plugin and dependency management
|
||||
* feature for a {@link GradleBuild}.
|
||||
*
|
||||
* @author Stephane Nicoll
|
||||
*/
|
||||
public final class SpringBootPluginBuildCustomizer implements BuildCustomizer<GradleBuild> {
|
||||
|
||||
/**
|
||||
* Order of this customizer. Runs before default customizers so that these plugins are
|
||||
* added at the beginning of the {@code plugins} block.
|
||||
*/
|
||||
public static final int ORDER = -100;
|
||||
|
||||
private final ResolvedProjectDescription projectDescription;
|
||||
|
||||
private final DependencyManagementPluginVersionResolver versionResolver;
|
||||
|
||||
public SpringBootPluginBuildCustomizer(ResolvedProjectDescription projectDescription,
|
||||
DependencyManagementPluginVersionResolver versionResolver) {
|
||||
this.projectDescription = projectDescription;
|
||||
this.versionResolver = versionResolver;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void customize(GradleBuild build) {
|
||||
build.plugins().add("org.springframework.boot",
|
||||
(plugin) -> plugin.setVersion(this.projectDescription.getPlatformVersion().toString()));
|
||||
build.plugins().add("io.spring.dependency-management", (plugin) -> plugin
|
||||
.setVersion(this.versionResolver.resolveDependencyManagementPluginVersion(this.projectDescription)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getOrder() {
|
||||
return ORDER;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -120,7 +120,7 @@ class GradleProjectGenerationConfigurationTests {
|
||||
assertThat(relativePaths).contains("build.gradle");
|
||||
List<String> lines = projectStructure.readAllLines("build.gradle");
|
||||
assertThat(lines).containsExactly("plugins {", " id 'org.springframework.boot' version '2.1.0.RELEASE'",
|
||||
" id 'java'", "}", "", "apply plugin: 'io.spring.dependency-management'", "",
|
||||
" id 'io.spring.dependency-management' version '1.0.6.RELEASE'", " id 'java'", "}", "",
|
||||
"group = 'com.example'", "version = '0.0.1-SNAPSHOT'", "sourceCompatibility = '11'", "",
|
||||
"repositories {", " mavenCentral()", "}", "", "dependencies {",
|
||||
" implementation 'org.springframework.boot:spring-boot-starter'",
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
plugins {
|
||||
id 'org.springframework.boot' version '2.1.1.RELEASE'
|
||||
id 'io.spring.dependency-management' version '1.0.6.RELEASE'
|
||||
id 'java'
|
||||
}
|
||||
|
||||
apply plugin: 'io.spring.dependency-management'
|
||||
|
||||
group = 'com.example'
|
||||
version = '0.0.1-SNAPSHOT'
|
||||
sourceCompatibility = '1.8'
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
plugins {
|
||||
id 'org.springframework.boot' version '2.1.1.RELEASE'
|
||||
id 'io.spring.dependency-management' version '1.0.6.RELEASE'
|
||||
id 'java'
|
||||
}
|
||||
|
||||
apply plugin: 'io.spring.dependency-management'
|
||||
|
||||
group = 'com.example'
|
||||
version = '0.0.1-SNAPSHOT'
|
||||
sourceCompatibility = '1.8'
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
plugins {
|
||||
id 'org.springframework.boot' version '2.1.1.RELEASE'
|
||||
id 'io.spring.dependency-management' version '1.0.6.RELEASE'
|
||||
id 'java'
|
||||
}
|
||||
|
||||
apply plugin: 'io.spring.dependency-management'
|
||||
|
||||
group = 'com.example'
|
||||
version = '0.0.1-SNAPSHOT'
|
||||
sourceCompatibility = '1.8'
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
plugins {
|
||||
id 'org.springframework.boot' version '2.1.1.RELEASE'
|
||||
id 'io.spring.dependency-management' version '1.0.6.RELEASE'
|
||||
id 'java'
|
||||
}
|
||||
|
||||
apply plugin: 'io.spring.dependency-management'
|
||||
|
||||
group = 'com.example'
|
||||
version = '0.0.1-SNAPSHOT'
|
||||
sourceCompatibility = '1.8'
|
||||
|
||||
@@ -2,12 +2,11 @@ import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
|
||||
|
||||
plugins {
|
||||
id 'org.springframework.boot' version '2.1.1.RELEASE'
|
||||
id 'io.spring.dependency-management' version '1.0.6.RELEASE'
|
||||
id 'org.jetbrains.kotlin.jvm' version '1.1.1'
|
||||
id 'org.jetbrains.kotlin.plugin.spring' version '1.1.1'
|
||||
}
|
||||
|
||||
apply plugin: 'io.spring.dependency-management'
|
||||
|
||||
group = 'com.example'
|
||||
version = '0.0.1-SNAPSHOT'
|
||||
sourceCompatibility = '11'
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
plugins {
|
||||
id 'org.springframework.boot' version '2.1.1.RELEASE'
|
||||
id 'io.spring.dependency-management' version '1.0.6.RELEASE'
|
||||
id 'java'
|
||||
}
|
||||
|
||||
apply plugin: 'io.spring.dependency-management'
|
||||
|
||||
group = 'com.example'
|
||||
version = '0.0.1-SNAPSHOT'
|
||||
sourceCompatibility = '1.8'
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
plugins {
|
||||
id 'org.springframework.boot' version '2.2.0.M1'
|
||||
id 'io.spring.dependency-management' version '1.0.6.RELEASE'
|
||||
id 'java'
|
||||
}
|
||||
|
||||
apply plugin: 'io.spring.dependency-management'
|
||||
|
||||
group = 'com.example'
|
||||
version = '0.0.1-SNAPSHOT'
|
||||
sourceCompatibility = '1.8'
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
plugins {
|
||||
id 'org.springframework.boot' version '2.1.1.RELEASE'
|
||||
id 'io.spring.dependency-management' version '1.0.6.RELEASE'
|
||||
id 'java'
|
||||
}
|
||||
|
||||
apply plugin: 'io.spring.dependency-management'
|
||||
|
||||
group = 'com.example'
|
||||
version = '0.0.1-SNAPSHOT'
|
||||
sourceCompatibility = '1.8'
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
plugins {
|
||||
id 'org.springframework.boot' version '2.2.0.RELEASE'
|
||||
id 'io.spring.dependency-management' version '1.0.6.RELEASE'
|
||||
id 'groovy'
|
||||
}
|
||||
|
||||
apply plugin: 'io.spring.dependency-management'
|
||||
|
||||
group = 'com.example'
|
||||
version = '0.0.1-SNAPSHOT'
|
||||
sourceCompatibility = '1.8'
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
plugins {
|
||||
id 'org.springframework.boot' version '2.1.1.RELEASE'
|
||||
id 'io.spring.dependency-management' version '1.0.6.RELEASE'
|
||||
id 'groovy'
|
||||
}
|
||||
|
||||
apply plugin: 'io.spring.dependency-management'
|
||||
|
||||
group = 'com.example'
|
||||
version = '0.0.1-SNAPSHOT'
|
||||
sourceCompatibility = '1.8'
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
plugins {
|
||||
id 'org.springframework.boot' version '2.1.1.RELEASE'
|
||||
id 'io.spring.dependency-management' version '1.0.6.RELEASE'
|
||||
id 'war'
|
||||
id 'groovy'
|
||||
}
|
||||
|
||||
apply plugin: 'io.spring.dependency-management'
|
||||
|
||||
group = 'com.example'
|
||||
version = '0.0.1-SNAPSHOT'
|
||||
sourceCompatibility = '1.8'
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
plugins {
|
||||
id 'org.springframework.boot' version '2.2.0.RELEASE'
|
||||
id 'io.spring.dependency-management' version '1.0.6.RELEASE'
|
||||
id 'java'
|
||||
}
|
||||
|
||||
apply plugin: 'io.spring.dependency-management'
|
||||
|
||||
group = 'com.example'
|
||||
version = '0.0.1-SNAPSHOT'
|
||||
sourceCompatibility = '1.8'
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
plugins {
|
||||
id 'org.springframework.boot' version '2.1.1.RELEASE'
|
||||
id 'io.spring.dependency-management' version '1.0.6.RELEASE'
|
||||
id 'java'
|
||||
}
|
||||
|
||||
apply plugin: 'io.spring.dependency-management'
|
||||
|
||||
group = 'com.example'
|
||||
version = '0.0.1-SNAPSHOT'
|
||||
sourceCompatibility = '1.8'
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
plugins {
|
||||
id 'org.springframework.boot' version '2.1.1.RELEASE'
|
||||
id 'io.spring.dependency-management' version '1.0.6.RELEASE'
|
||||
id 'java'
|
||||
id 'war'
|
||||
}
|
||||
|
||||
apply plugin: 'io.spring.dependency-management'
|
||||
|
||||
group = 'com.example'
|
||||
version = '0.0.1-SNAPSHOT'
|
||||
sourceCompatibility = '1.8'
|
||||
|
||||
@@ -2,12 +2,11 @@ import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
|
||||
|
||||
plugins {
|
||||
id 'org.springframework.boot' version '2.2.0.RELEASE'
|
||||
id 'io.spring.dependency-management' version '1.0.6.RELEASE'
|
||||
id 'org.jetbrains.kotlin.jvm' version '1.1.1'
|
||||
id 'org.jetbrains.kotlin.plugin.spring' version '1.1.1'
|
||||
}
|
||||
|
||||
apply plugin: 'io.spring.dependency-management'
|
||||
|
||||
group = 'com.example'
|
||||
version = '0.0.1-SNAPSHOT'
|
||||
sourceCompatibility = '1.8'
|
||||
|
||||
@@ -2,12 +2,11 @@ import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
|
||||
|
||||
plugins {
|
||||
id 'org.springframework.boot' version '2.1.1.RELEASE'
|
||||
id 'io.spring.dependency-management' version '1.0.6.RELEASE'
|
||||
id 'org.jetbrains.kotlin.jvm' version '1.1.1'
|
||||
id 'org.jetbrains.kotlin.plugin.spring' version '1.1.1'
|
||||
}
|
||||
|
||||
apply plugin: 'io.spring.dependency-management'
|
||||
|
||||
group = 'com.example'
|
||||
version = '0.0.1-SNAPSHOT'
|
||||
sourceCompatibility = '1.8'
|
||||
|
||||
@@ -2,13 +2,12 @@ import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
|
||||
|
||||
plugins {
|
||||
id 'org.springframework.boot' version '2.1.1.RELEASE'
|
||||
id 'io.spring.dependency-management' version '1.0.6.RELEASE'
|
||||
id 'war'
|
||||
id 'org.jetbrains.kotlin.jvm' version '1.1.1'
|
||||
id 'org.jetbrains.kotlin.plugin.spring' version '1.1.1'
|
||||
}
|
||||
|
||||
apply plugin: 'io.spring.dependency-management'
|
||||
|
||||
group = 'com.example'
|
||||
version = '0.0.1-SNAPSHOT'
|
||||
sourceCompatibility = '1.8'
|
||||
|
||||
Reference in New Issue
Block a user