diff --git a/CHANGELOG.adoc b/CHANGELOG.adoc index 499f3604..abeaac8a 100644 --- a/CHANGELOG.adoc +++ b/CHANGELOG.adoc @@ -7,6 +7,7 @@ order. === Release 1.0.0 (In progress) +* https://github.com/spring-io/initializr/issues/82[#82]: fix version support for gradle build * https://github.com/spring-io/initializr/issues/88[#88]: expose service meta-data so that another service can use that as a base configuration. * https://github.com/spring-io/initializr/issues/87[#87]: more flexible meta-data. diff --git a/initializr/src/main/resources/templates/starter-build.gradle b/initializr/src/main/resources/templates/starter-build.gradle index 255af5e8..7744d503 100644 --- a/initializr/src/main/resources/templates/starter-build.gradle +++ b/initializr/src/main/resources/templates/starter-build.gradle @@ -40,13 +40,13 @@ repositories { } <% } %> dependencies {<% compileDependencies.each { %> - compile("${it.groupId}:${it.artifactId}")<% } %><% if (language=='groovy') { %> - compile("org.codehaus.groovy:groovy")<% } %><% runtimeDependencies.each { %> - runtime("${it.groupId}:${it.artifactId}")<% } %><% if (packaging=='war') { %> + compile("${it.groupId}:${it.artifactId}${it.version ? ":$it.version" : ""}")<% } %><% if (language=='groovy') { %> + compile("org.codehaus.groovy:groovy")<% } %><% runtimeDependencies.each { %> + runtime("${it.groupId}:${it.artifactId}${it.version ? ":$it.version" : ""}")<% } %><% if (packaging=='war') { %> providedRuntime("org.springframework.boot:spring-boot-starter-tomcat")<% } %><% providedDependencies.each { %> - providedRuntime("${it.groupId}:${it.artifactId}")<% } %> + providedRuntime("${it.groupId}:${it.artifactId}${it.version ? ":$it.version" : ""}")<% } %> testCompile("org.springframework.boot:spring-boot-starter-test") <% testDependencies.each { %> - testCompile("${it.groupId}:${it.artifactId}")<% } %> + testCompile("${it.groupId}:${it.artifactId}${it.version ? ":$it.version" : ""}")<% } %> } eclipse { diff --git a/initializr/src/test/groovy/io/spring/initializr/generator/ProjectGeneratorTests.groovy b/initializr/src/test/groovy/io/spring/initializr/generator/ProjectGeneratorTests.groovy index 92ac46b4..7f5f9dc8 100644 --- a/initializr/src/test/groovy/io/spring/initializr/generator/ProjectGeneratorTests.groovy +++ b/initializr/src/test/groovy/io/spring/initializr/generator/ProjectGeneratorTests.groovy @@ -232,6 +232,33 @@ class ProjectGeneratorTests { generateProject(request).isGradleProject().isGroovyProject() } + @Test + void mavenPomWithCustomVersion() { + def whatever = new Dependency(id: 'whatever', groupId: 'org.acme', artifactId: 'whatever', version: '1.2.3') + def metadata = InitializrMetadataTestBuilder.withDefaults() + .addDependencyGroup('core', 'web', 'security', 'data-jpa') + .addDependencyGroup('foo', whatever).build() + projectGenerator.metadata = metadata + def request = createProjectRequest('whatever', 'data-jpa', 'web') + generateMavenPom(request).hasDependency(whatever) + .hasSpringBootStarterDependency('data-jpa') + .hasSpringBootStarterDependency('web') + } + + @Test + void gradleBuildWithCustomVersion() { + def whatever = new Dependency(id: 'whatever', groupId: 'org.acme', artifactId: 'whatever', version: '1.2.3') + def metadata = InitializrMetadataTestBuilder.withDefaults() + .addDependencyGroup('core', 'web', 'security', 'data-jpa') + .addDependencyGroup('foo', whatever).build() + projectGenerator.metadata = metadata + def request = createProjectRequest('whatever', 'data-jpa', 'web') + generateGradleBuild(request) + .contains("compile(\"org.springframework.boot:spring-boot-starter-web\")") + .contains("compile(\"org.springframework.boot:spring-boot-starter-data-jpa\")") + .contains("compile(\"org.acme:whatever:1.2.3\")") + } + @Test void mavenPomWithCustomScope() { def h2 = new Dependency(id: 'h2', groupId: 'org.h2', artifactId: 'h2', scope: 'runtime')