Add build.gradle samples and rename runJar->bootRun

This commit is contained in:
Dave Syer 2013-12-10 11:06:59 +00:00
parent 4c9c2b8dcf
commit e55e8f9863
6 changed files with 135 additions and 2 deletions

View File

@ -0,0 +1,21 @@
# Spring Boot Actuator Sample
You can build this sample using Maven (>3) or Gradle (1.6).
With Maven:
```
$ mvn package
$ java -jar target/*.jar
```
Then access the app via a browser (or curl) on http://localhost:8080 (the user name is "user" and look at the INFO log output for the password to login).
With gradle:
```
$ gradle build
$ java -jar build/libs/*.jar
```
The gradle build contains an intentionally odd configuration to exclude the security dependencies from the executable JAR. So the app run like this behaves differently than the one run from the Maven-built JAR file. See comments in the `build.gradle` for details.

View File

@ -0,0 +1,49 @@
buildscript {
repositories {
mavenLocal()
maven { url "http://repo.springsource.org/libs-snapshot" }
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:0.5.0.BUILD-SNAPSHOT")
}
}
ext {
springBootVersion = '0.5.0.BUILD-SNAPSHOT'
}
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'spring-boot'
jar {
baseName = 'spring-boot-sample-actuator'
version = '0.5.0'
}
repositories {
mavenCentral()
maven { url "http://repo.springsource.org/libs-snapshot" }
}
dependencies {
configurations {
insecure.exclude module: 'spring-boot-starter-security'
}
compile("org.springframework.boot:spring-boot-starter-web:${springBootVersion}")
compile("org.springframework.boot:spring-boot-starter-actuator:${springBootVersion}")
compile("org.springframework.boot:spring-boot-starter-security:${springBootVersion}")
testCompile("junit:junit:4.11")
insecure configurations.runtime
}
// Slightly odd requirement (package a jar file as an insecure app, exlcuding Spring Security)
// just to demonstrate the "customConfiguration" feature of the Boot gradle plugin.
springBoot {
customConfiguration = "insecure"
}
task wrapper(type: Wrapper) {
gradleVersion = '1.6'
}

View File

@ -0,0 +1,19 @@
# Spring Boot Simple Sample
You can build this sample using Maven (>3) or Gradle (1.6).
With Maven:
```
$ mvn package
$ java -jar target/*.jar
```
The app prints a Hello message on the console.
With gradle:
```
$ gradle build
$ java -jar build/libs/*.jar
```

View File

@ -0,0 +1,37 @@
buildscript {
repositories {
mavenLocal()
maven { url "http://repo.springsource.org/libs-snapshot" }
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:0.5.0.BUILD-SNAPSHOT")
}
}
ext {
springBootVersion = '0.5.0.BUILD-SNAPSHOT'
}
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'spring-boot'
jar {
baseName = 'spring-boot-sample-simple'
version = '0.5.0'
}
repositories {
mavenCentral()
maven { url "http://repo.springsource.org/libs-snapshot" }
}
dependencies {
compile("org.springframework.boot:spring-boot-starter:${springBootVersion}")
testCompile("org.springframework.boot:spring-boot-starter-test:${springBootVersion}")
}
task wrapper(type: Wrapper) {
gradleVersion = '1.6'
}

View File

@ -44,6 +44,13 @@ $ gradle build
$ java -jar build/libs/mymodule-0.0.1-SNAPSHOT.jar
```
### Running a Project in Place
To run a project in place without building a jar first you can use the "bootRun" task:
```
$ gradle bootRun
```
### Repackage configuration
The gradle plugin automatically extends your build script DSL with a `springBoot` element

View File

@ -25,7 +25,7 @@ import org.springframework.boot.gradle.task.Repackage;
import org.springframework.boot.gradle.task.RunJar;
/**
* Gradle 'Spring Boot' {@link Plugin}.
* Gradle 'Spring Boot' {@link Plugin}. Provides 2 tasks (bootRepackge and bootRun).
*
* @author Phillip Webb
*/
@ -33,7 +33,7 @@ public class SpringBootPlugin implements Plugin<Project> {
private static final String REPACKAGE_TASK_NAME = "bootRepackage";
private static final String RUN_JAR_TASK_NAME = "runJar";
private static final String RUN_JAR_TASK_NAME = "bootRun";
@Override
public void apply(Project project) {