mirror of
https://gitee.com/dcren/initializr.git
synced 2025-07-15 14:04:30 +08:00
Externalize dependency management plugin version
Closes gh-253
This commit is contained in:
parent
1fd8e2c047
commit
6099a1c6bc
@ -225,7 +225,8 @@ class ProjectGenerator {
|
||||
model['providedDependencies'] = filterDependencies(dependencies, Dependency.SCOPE_PROVIDED)
|
||||
model['testDependencies'] = filterDependencies(dependencies, Dependency.SCOPE_TEST)
|
||||
|
||||
// Add kotlinVersion
|
||||
// Add various versions
|
||||
model['dependencyManagementPluginVersion'] = metadata.configuration.env.gradle.dependencyManagementPluginVersion
|
||||
model['kotlinVersion'] = metadata.configuration.env.kotlin.version
|
||||
|
||||
// @SpringBootApplication available as from 1.2.0.RC1
|
||||
|
@ -165,6 +165,11 @@ class InitializrConfiguration {
|
||||
*/
|
||||
final Map<String, Repository> repositories = [:]
|
||||
|
||||
/**
|
||||
* Gradle-specific settings.
|
||||
*/
|
||||
final Gradle gradle = new Gradle()
|
||||
|
||||
/**
|
||||
* Kotlin-specific settings.
|
||||
*/
|
||||
@ -203,6 +208,7 @@ class InitializrConfiguration {
|
||||
fallbackApplicationName = other.fallbackApplicationName
|
||||
invalidApplicationNames = other.invalidApplicationNames
|
||||
forceSsl = other.forceSsl
|
||||
gradle.merge(other.gradle)
|
||||
kotlin.version = other.kotlin.version
|
||||
maven.merge(other.maven)
|
||||
other.boms.each { id, bom ->
|
||||
@ -217,6 +223,19 @@ class InitializrConfiguration {
|
||||
}
|
||||
}
|
||||
|
||||
static class Gradle {
|
||||
|
||||
/**
|
||||
* Version of the "dependency-management-plugin" to use.
|
||||
*/
|
||||
String dependencyManagementPluginVersion
|
||||
|
||||
private void merge(Gradle other) {
|
||||
dependencyManagementPluginVersion = other.dependencyManagementPluginVersion
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
static class Kotlin {
|
||||
|
||||
/**
|
||||
|
@ -23,6 +23,12 @@
|
||||
"sourceType": "io.spring.initializr.metadata.InitializrProperties",
|
||||
"sourceMethod": "getEnv()"
|
||||
},
|
||||
{
|
||||
"name": "initializr.env.gradle",
|
||||
"type": "io.spring.initializr.metadata.InitializrConfiguration$Env$Gradle",
|
||||
"sourceType": "io.spring.initializr.metadata.InitializrConfiguration$Env",
|
||||
"sourceMethod": "getGradle()"
|
||||
},
|
||||
{
|
||||
"name": "initializr.env.kotlin",
|
||||
"type": "io.spring.initializr.metadata.InitializrConfiguration$Env$Kotlin",
|
||||
@ -175,6 +181,12 @@
|
||||
"org.springframework"
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "initializr.env.gradle.dependency-management-plugin-version",
|
||||
"type": "java.lang.String",
|
||||
"description": "Version of the \"dependency-management-plugin\" to use.",
|
||||
"sourceType": "io.spring.initializr.metadata.InitializrConfiguration$Env$Gradle"
|
||||
},
|
||||
{
|
||||
"name": "initializr.env.kotlin.version",
|
||||
"type": "java.lang.String",
|
||||
|
@ -9,8 +9,8 @@ buildscript {
|
||||
maven { url "https://repo.spring.io/milestone" }<% } %>
|
||||
}
|
||||
dependencies {
|
||||
classpath("org.springframework.boot:spring-boot-gradle-plugin:\${springBootVersion}") <% if (!bootOneThreeAvailable) { %>
|
||||
classpath('io.spring.gradle:dependency-management-plugin:0.6.0.RELEASE')<% } %><% if (language=='kotlin') { %>
|
||||
classpath("org.springframework.boot:spring-boot-gradle-plugin:\${springBootVersion}")<% if (!bootOneThreeAvailable) { %>
|
||||
classpath('io.spring.gradle:dependency-management-plugin:${dependencyManagementPluginVersion}')<% } %><% if (language=='kotlin') { %>
|
||||
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:\${kotlinVersion}")<% } %>
|
||||
}
|
||||
}
|
||||
@ -18,8 +18,8 @@ buildscript {
|
||||
apply plugin: '${language}'<% if (packaging=='war') { %>
|
||||
apply plugin: 'eclipse-wtp'<% } else { %>
|
||||
apply plugin: 'eclipse'<% } %>
|
||||
apply plugin: 'spring-boot' <% if (!bootOneThreeAvailable) { %>
|
||||
apply plugin: 'io.spring.dependency-management' <% } %><% if (packaging=='war') { %>
|
||||
apply plugin: 'spring-boot'<% if (!bootOneThreeAvailable) { %>
|
||||
apply plugin: 'io.spring.dependency-management'<% } %><% if (packaging=='war') { %>
|
||||
apply plugin: 'war'
|
||||
<% } %>
|
||||
|
||||
@ -45,7 +45,7 @@ dependencies {<% compileDependencies.each { %>
|
||||
compile("org.jetbrains.kotlin:kotlin-stdlib:\${kotlinVersion}")<% } %><% runtimeDependencies.each { %>
|
||||
runtime('${it.groupId}:${it.artifactId}${it.version ? ":$it.version" : ""}${it.type ? "@$it.type" : ""}')<% } %><% providedDependencies.each { %>
|
||||
providedRuntime('${it.groupId}:${it.artifactId}${it.version ? ":$it.version" : ""}${it.type ? "@$it.type" : ""}')<% } %>
|
||||
testCompile('org.springframework.boot:spring-boot-starter-test') <% testDependencies.each { %>
|
||||
testCompile('org.springframework.boot:spring-boot-starter-test')<% testDependencies.each { %>
|
||||
testCompile('${it.groupId}:${it.artifactId}${it.version ? ":$it.version" : ""}${it.type ? "@$it.type" : ""}')<% } %>
|
||||
}
|
||||
<% if (boms) { %>
|
||||
|
@ -411,23 +411,31 @@ class ProjectGeneratorTests extends AbstractProjectGeneratorTests {
|
||||
|
||||
@Test
|
||||
void gradleBuildBeforeWithSpringBoot13() {
|
||||
def metadata = InitializrMetadataTestBuilder.withDefaults()
|
||||
.addDependencyGroup('core', 'web', 'jpa')
|
||||
.setGradleEnv('0.5.9.RELEASE').build()
|
||||
applyMetadata(metadata)
|
||||
def request = createProjectRequest('web')
|
||||
request.bootVersion = '1.2.3.RELEASE'
|
||||
generateGradleBuild(request)
|
||||
.contains("springBootVersion = '1.2.3.RELEASE'")
|
||||
.contains("classpath('io.spring.gradle:dependency-management-plugin:0.6.0.RELEASE')")
|
||||
.contains("classpath('io.spring.gradle:dependency-management-plugin:0.5.9.RELEASE')")
|
||||
.contains("apply plugin: 'spring-boot'")
|
||||
.contains("apply plugin: 'io.spring.dependency-management'")
|
||||
}
|
||||
|
||||
@Test
|
||||
void gradleBuildAsFromSpringBoot13() {
|
||||
def metadata = InitializrMetadataTestBuilder.withDefaults()
|
||||
.addDependencyGroup('core', 'web', 'jpa')
|
||||
.setGradleEnv('0.5.9.RELEASE').build()
|
||||
applyMetadata(metadata)
|
||||
def request = createProjectRequest('web')
|
||||
request.bootVersion = '1.3.0.BUILD-SNAPSHOT'
|
||||
generateGradleBuild(request)
|
||||
.contains("springBootVersion = '1.3.0.BUILD-SNAPSHOT'")
|
||||
.contains("apply plugin: 'spring-boot'")
|
||||
.doesNotContain("classpath('io.spring.gradle:dependency-management-plugin:0.6.0.RELEASE')")
|
||||
.doesNotContain("classpath('io.spring.gradle:dependency-management-plugin:0.5.9.RELEASE')")
|
||||
.doesNotContain("apply plugin: 'io.spring.dependency-management'")
|
||||
}
|
||||
|
||||
|
@ -67,6 +67,7 @@ class InitializrMetadataTestBuilder {
|
||||
InitializrMetadataTestBuilder addDefaults() {
|
||||
addDefaultTypes().addDefaultPackagings().addDefaultJavaVersions()
|
||||
.addDefaultLanguages().addDefaultBootVersions()
|
||||
.setGradleEnv('0.5.1.RELEASE').setKotlinEnv('1.0.1')
|
||||
}
|
||||
|
||||
InitializrMetadataTestBuilder addDefaultTypes() {
|
||||
@ -152,6 +153,20 @@ class InitializrMetadataTestBuilder {
|
||||
this
|
||||
}
|
||||
|
||||
InitializrMetadataTestBuilder setGradleEnv(String dependencyManagementPluginVersion) {
|
||||
builder.withCustomizer {
|
||||
it.configuration.env.gradle.dependencyManagementPluginVersion = dependencyManagementPluginVersion
|
||||
}
|
||||
this
|
||||
}
|
||||
|
||||
InitializrMetadataTestBuilder setKotlinEnv(String kotlinVersion) {
|
||||
builder.withCustomizer {
|
||||
it.configuration.env.kotlin.version = kotlinVersion
|
||||
}
|
||||
this
|
||||
}
|
||||
|
||||
InitializrMetadataTestBuilder setMavenParent(String groupId, String artifactId,
|
||||
String version, boolean includeSpringBootBom) {
|
||||
builder.withCustomizer {
|
||||
|
@ -46,6 +46,8 @@ initializr:
|
||||
artifactId: spring-cloud-services-dependencies
|
||||
version: 1.1.0.RELEASE
|
||||
additionalBoms: [cloud-bom]
|
||||
gradle:
|
||||
dependency-management-plugin-version: 0.6.0.RELEASE
|
||||
kotlin:
|
||||
version: 1.0.2
|
||||
dependencies:
|
||||
|
Loading…
Reference in New Issue
Block a user