From 4f772e4a997ca2c92a860a28aefc1f6235b08020 Mon Sep 17 00:00:00 2001 From: Dave Syer Date: Wed, 4 Jun 2014 15:31:11 +0100 Subject: [PATCH] Add provided scope to war --- templates/ServletInitializer.java | 2 +- templates/starter-build.gradle | 17 ++++++---- templates/starter-pom.xml | 53 +++++++++++++++++-------------- test/integration.groovy | 10 +++++- 4 files changed, 50 insertions(+), 32 deletions(-) diff --git a/templates/ServletInitializer.java b/templates/ServletInitializer.java index 20ace458..f21b7a25 100644 --- a/templates/ServletInitializer.java +++ b/templates/ServletInitializer.java @@ -3,7 +3,7 @@ package ${packageName}; import org.springframework.boot.builder.SpringApplicationBuilder; import org.springframework.boot.context.web.SpringBootServletInitializer; -public class ServletInitializer extends SpringBootServletInitializer { +public class ServletInitializer extends SpringBootServletInitializer { @Override protected SpringApplicationBuilder configure(SpringApplicationBuilder application) { diff --git a/templates/starter-build.gradle b/templates/starter-build.gradle index ec242d33..678aab59 100644 --- a/templates/starter-build.gradle +++ b/templates/starter-build.gradle @@ -1,9 +1,9 @@ buildscript { - ext { - springBootVersion = '${bootVersion}' - } + ext { + springBootVersion = '${bootVersion}' + } repositories { - mavenCentral()<% if (!bootVersion.contains("RELEASE")) { %> + mavenCentral()<% if (!bootVersion.contains("RELEASE")) { %> maven { url "http://repo.spring.io/snapshot" } maven { url "http://repo.spring.io/milestone" } <% } %> @@ -34,9 +34,14 @@ repositories { <% } %> } +<% if (packaging=='war') { %>configurations { + providedRuntime +} +<% } %> dependencies {<% styles.each { %> - compile("org.springframework.boot:spring-boot-starter${it}")<% } %> - <% if (language=='groovy') { %>compile("org.codehaus.groovy:groovy")<% } %> + compile("org.springframework.boot:spring-boot-starter${it}")<% } %><% if (language=='groovy') { %> + compile("org.codehaus.groovy:groovy")<% } %><% if (packaging=='war') { %> + providedRuntime("org.springframework.boot:spring-boot-starter-tomcat")<% } %> testCompile("org.springframework.boot:spring-boot-starter-test") } diff --git a/templates/starter-pom.xml b/templates/starter-pom.xml index 6ebe1e75..741de40f 100644 --- a/templates/starter-pom.xml +++ b/templates/starter-pom.xml @@ -26,6 +26,11 @@ org.codehaus.groovy groovy + <% } %><% if (packaging=='war') { %> + + org.springframework.boot + spring-boot-starter-tomcat + provided <% } %> org.springframework.boot @@ -46,30 +51,30 @@ org.springframework.boot spring-boot-maven-plugin <% if (language=='groovy') { %> - - maven-compiler-plugin - - groovy-eclipse-compiler - - - - org.codehaus.groovy - groovy-eclipse-compiler - 2.8.0-01 - - - org.codehaus.groovy - groovy-eclipse-batch - 2.1.8-01 - - - - - org.codehaus.groovy - groovy-eclipse-compiler - 2.8.0-01 - true - <% } %> + + maven-compiler-plugin + + groovy-eclipse-compiler + + + + org.codehaus.groovy + groovy-eclipse-compiler + 2.8.0-01 + + + org.codehaus.groovy + groovy-eclipse-batch + 2.1.8-01 + + + + + org.codehaus.groovy + groovy-eclipse-compiler + 2.8.0-01 + true + <% } %> <% if (!bootVersion.contains("RELEASE")) { %> diff --git a/test/integration.groovy b/test/integration.groovy index 336df66a..d284c8f3 100644 --- a/test/integration.groovy +++ b/test/integration.groovy @@ -28,9 +28,17 @@ class IntegrationTests { } @Test - void webIsAdded() { + void webIsAddedPom() { String body = new TestRestTemplate().getForObject('http://localhost:' + port + '/pom.xml?packaging=war', String) assertTrue('Wrong body:\n' + body, body.contains('spring-boot-starter-web')) + assertTrue('Wrong body:\n' + body, body.contains('provided')) + } + + @Test + void webIsAddedGradle() { + String body = new TestRestTemplate().getForObject('http://localhost:' + port + '/build.gradle?packaging=war', String) + assertTrue('Wrong body:\n' + body, body.contains('spring-boot-starter-web')) + assertTrue('Wrong body:\n' + body, body.contains('providedRuntime')) } @Test