Add build.gradle samples and docs for deployable WAR

Fixes gh-518
This commit is contained in:
Dave Syer 2014-03-18 09:29:35 +00:00
parent 9f532b653f
commit a8ba80bbf4
3 changed files with 98 additions and 1 deletions

View File

@ -125,6 +125,31 @@ To build and run a project artifact, you can type the following:
$ java -jar target/mymodule-0.0.1-SNAPSHOT.jar
----
To build a war file that is both executable and deployable into an external container
you need to mark the embedded container dependencies as "provided", e.g.
[source,xml,indent=0,subs="verbatim,attributes"]
----
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<!-- ... -->
<packaging>war</packaging>
<!-- ... -->
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
<!-- ... -->
</dependencies>
</project>
----
[[build-tool-plugins-maven-packaging-configuration]]
@ -347,6 +372,35 @@ To build and run a project artifact, you can type the following:
$ java -jar build/libs/mymodule-0.0.1-SNAPSHOT.jar
----
To build a war file that is both executable and deployable into an external container,
you need to mark the embedded container dependencies as belonging to a configuration
named "providedRuntime", e.g.
[source,groovy,indent=0,subs="verbatim,attributes"]
----
...
apply plugin: 'war'
war {
baseName = 'myapp'
version = '0.5.0'
}
repositories {
mavenCentral()
maven { url "http://repo.spring.io/libs-snapshot" }
}
configurations {
providedRuntime
}
dependencies {
compile("org.springframework.boot:spring-boot-starter-web")
providedRuntime("org.springframework.boot:spring-boot-starter-tomcat")
...
}
----
[[build-tool-plugins-gradle-running-applications]]

View File

@ -0,0 +1,43 @@
buildscript {
ext {
springBootVersion = '1.0.0.BUILD-SNAPSHOT'
}
repositories {
mavenLocal()
maven { url "http://repo.spring.io/libs-snapshot" }
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
}
}
apply plugin: 'java'
apply plugin: 'eclipse-wtp'
apply plugin: 'idea'
apply plugin: 'spring-boot'
apply plugin: 'war'
mainClassName = "sample.ui.SampleWebStaticApplication"
war {
baseName = 'spring-boot-sample-web-static'
version = '0.5.0'
}
repositories {
mavenCentral()
maven { url "http://repo.spring.io/libs-snapshot" }
}
configurations {
providedRuntime
}
dependencies {
compile("org.springframework.boot:spring-boot-starter-web")
providedRuntime("org.springframework.boot:spring-boot-starter-tomcat")
testCompile("org.springframework.boot:spring-boot-starter-test")
}
task wrapper(type: Wrapper) { gradleVersion = '1.6' }

View File

@ -22,7 +22,7 @@ apply plugin: 'spring-boot'
mainClassName = "sample.ui.SampleWebUiApplication"
jar {
baseName = 'spring-boot-sample-simple'
baseName = 'spring-boot-sample-web-ui'
version = '0.5.0'
}