mirror of
https://gitee.com/dcren/initializr.git
synced 2025-12-26 22:25:51 +08:00
Support for dependency management plugin
Add support for the dependency management plugin for Gradle so that BOMs can be added to the project if needed. Also, the Gradle plugin as from Spring Boot 1.3 has changed and this commit brings a transparent support for it. Closes gh-98
This commit is contained in:
@@ -39,6 +39,8 @@ class ProjectGenerator {
|
||||
|
||||
private static final VERSION_1_2_0_RC1 = Version.parse('1.2.0.RC1')
|
||||
|
||||
private static final VERSION_1_3_0_M1 = Version.parse('1.3.0.M1')
|
||||
|
||||
@Autowired
|
||||
InitializrMetadata metadata
|
||||
|
||||
@@ -183,6 +185,11 @@ class ProjectGenerator {
|
||||
// @SpringBootApplication available as from 1.2.0.RC1
|
||||
model['useSpringBootApplication'] = VERSION_1_2_0_RC1
|
||||
.compareTo(Version.safeParse(request.bootVersion)) <= 0
|
||||
|
||||
// Gradle plugin has changed as from 1.3.0
|
||||
model['bootOneThreeAvailable'] = VERSION_1_3_0_M1
|
||||
.compareTo(Version.safeParse(request.bootVersion)) <= 0
|
||||
|
||||
model
|
||||
}
|
||||
|
||||
|
||||
@@ -5,19 +5,21 @@ buildscript {
|
||||
repositories {
|
||||
mavenCentral()<% if (!bootVersion.contains("RELEASE")) { %>
|
||||
maven { url "https://repo.spring.io/snapshot" }
|
||||
maven { url "https://repo.spring.io/milestone" }
|
||||
<% } %>
|
||||
maven { url "https://repo.spring.io/milestone" }<% } %>
|
||||
}
|
||||
dependencies {
|
||||
classpath("org.springframework.boot:spring-boot-gradle-plugin:\${springBootVersion}")
|
||||
classpath("org.springframework.boot:spring-boot-gradle-plugin:\${springBootVersion}") <% if (!bootOneThreeAvailable) { %>
|
||||
classpath("io.spring.gradle:dependency-management-plugin:0.4.1.RELEASE")<% } %>
|
||||
}
|
||||
}
|
||||
|
||||
apply plugin: '${language}'<% if (packaging=='war') { %>
|
||||
apply plugin: 'eclipse-wtp'<% } else { %>
|
||||
apply plugin: 'eclipse'<% } %>
|
||||
apply plugin: 'idea'
|
||||
apply plugin: 'spring-boot' <% if (packaging=='war') { %>
|
||||
apply plugin: 'idea' <% if (bootOneThreeAvailable) { %>
|
||||
apply plugin: 'org.springframework.boot.spring-boot' <% } else { %>
|
||||
apply plugin: 'spring-boot'
|
||||
apply plugin: 'io.spring.dependency-management'<% } %><% if (packaging=='war') { %>
|
||||
apply plugin: 'war'
|
||||
<% } %>
|
||||
|
||||
@@ -31,8 +33,7 @@ targetCompatibility = ${javaVersion}
|
||||
repositories {
|
||||
mavenCentral()<% if (!bootVersion.contains("RELEASE")) { %>
|
||||
maven { url "https://repo.spring.io/snapshot" }
|
||||
maven { url "https://repo.spring.io/milestone" }
|
||||
<% } %>
|
||||
maven { url "https://repo.spring.io/milestone" }<% } %>
|
||||
}
|
||||
|
||||
<% if (packaging=='war') { %>configurations {
|
||||
|
||||
@@ -168,7 +168,7 @@ class ProjectGenerationMetricsListenerTests {
|
||||
def request = initialize()
|
||||
request.resolve(metadata)
|
||||
listener.onGeneratedProject(request)
|
||||
metricsAssert.hasValue(1, 'initializr.boot_version.1_1_5_RELEASE')
|
||||
metricsAssert.hasValue(1, 'initializr.boot_version.1_2_3_RELEASE')
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -31,7 +31,9 @@ import org.springframework.boot.autoconfigure.SpringBootApplication
|
||||
import org.springframework.context.annotation.ComponentScan
|
||||
import org.springframework.context.annotation.Configuration
|
||||
|
||||
import static org.mockito.Mockito.*
|
||||
import static org.mockito.Mockito.mock
|
||||
import static org.mockito.Mockito.times
|
||||
import static org.mockito.Mockito.verify
|
||||
|
||||
/**
|
||||
* @author Stephane Nicoll
|
||||
@@ -300,6 +302,30 @@ class ProjectGeneratorTests {
|
||||
.contains("testCompile(\"org.hamcrest:hamcrest\")")
|
||||
}
|
||||
|
||||
@Test
|
||||
void gradleBuildBeforeWithSpringBoot13() {
|
||||
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.4.1.RELEASE")')
|
||||
.contains("apply plugin: 'spring-boot'")
|
||||
.contains("apply plugin: 'io.spring.dependency-management'")
|
||||
.doesNotContain("apply plugin: 'org.springframework.boot.spring-boot'")
|
||||
}
|
||||
|
||||
@Test
|
||||
void gradleBuildAsFromSpringBoot13() {
|
||||
def request = createProjectRequest('web')
|
||||
request.bootVersion = '1.3.0.BUILD-SNAPSHOT'
|
||||
generateGradleBuild(request)
|
||||
.contains("springBootVersion = '1.3.0.BUILD-SNAPSHOT'")
|
||||
.contains("apply plugin: 'org.springframework.boot.spring-boot'")
|
||||
.doesNotContain('classpath("io.spring.gradle:dependency-management-plugin:0.4.1.RELEASE")')
|
||||
.doesNotContain("apply plugin: 'spring-boot'")
|
||||
.doesNotContain("apply plugin: 'io.spring.dependency-management'")
|
||||
}
|
||||
|
||||
PomAssert generateMavenPom(ProjectRequest request) {
|
||||
def content = new String(projectGenerator.generateMavenPom(request))
|
||||
new PomAssert(content).validateProjectRequest(request)
|
||||
|
||||
@@ -18,6 +18,7 @@ package io.spring.initializr.test
|
||||
|
||||
import io.spring.initializr.generator.ProjectRequest
|
||||
|
||||
import static org.junit.Assert.assertFalse
|
||||
import static org.junit.Assert.assertTrue
|
||||
|
||||
/**
|
||||
@@ -63,4 +64,9 @@ class GradleBuildAssert {
|
||||
assertTrue "$expression has not been found in gradle build $content", content.contains(expression)
|
||||
this
|
||||
}
|
||||
|
||||
GradleBuildAssert doesNotContain(String expression) {
|
||||
assertFalse "$expression is not expected in gradle build $content", content.contains(expression)
|
||||
this
|
||||
}
|
||||
}
|
||||
|
||||
@@ -128,8 +128,8 @@ class InitializrMetadataTestBuilder {
|
||||
}
|
||||
|
||||
InitializrMetadataTestBuilder addDefaultBootVersions() {
|
||||
addBootVersion('1.0.2.RELEASE', false).addBootVersion('1.1.5.RELEASE', true)
|
||||
.addBootVersion('1.2.0.BUILD-SNAPSHOT', false)
|
||||
addBootVersion('1.1.2.RELEASE', false).addBootVersion('1.2.3.RELEASE', true)
|
||||
.addBootVersion('1.3.0.BUILD-SNAPSHOT', false)
|
||||
}
|
||||
|
||||
InitializrMetadataTestBuilder addBootVersion(String id, boolean defaultValue) {
|
||||
|
||||
Reference in New Issue
Block a user