You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
spring-boot/spring-boot-tools/spring-boot-gradle-plugin
Andy Wilkinson bde98defa5 Update Gradle plugin to only repackage main jar
Previously, Repackage would attempt to repackage every jar in the
project. This would cause it to incorrectly attempt to repackage source
and javadoc jars.

This commit updates Repackage so that it ignores any jar with a
classifier. Hopefully this is a reasonable approximation for ignoring
'special' jars that should not be repackaged such as sources and
javadoc.
11 years ago
..
src/main Update Gradle plugin to only repackage main jar 11 years ago
README.md Replace 'springsource.org' with 'spring.io' 11 years ago
pom.xml Back to SNAPSHOT for dev 11 years ago

README.md

Spring Boot - Gradle Plugin

The Spring Boot Gradle Plugin provides Spring Boot support in Gradle, allowing you to package executable jar or war archives.

Including the plugin

To use the Spring Boot Gradle Plugin simply include a buildscript dependency and apply the spring-boot plugin:

buildscript {
	dependencies {
		classpath("org.springframework.boot:spring-boot-gradle-plugin:{{project.version}}")
	}
}
apply plugin: 'spring-boot'

If you are using a milestone or snapshot release you will also need to add appropriate repositories reference:

buildscript {
	repositories {
		maven.url "http://repo.spring.io/snapshot"
		maven.url "http://repo.spring.io/milestone"
	}
	// ...
}

Packaging executable jar and war files

Once the spring-boot plugin has been applied to your project it will automatically attempt to rewrite archives to make them executable using the repackage task. You should configure your project to build a jar or war (as appropriate) in the usual way.

The main class that you want to launch can either be specified using a configuration option, or by adding a Main-Class attribute to the manifest. If you don't specify a main class the plugin will search for a class with a public static void main(String[] args) method.

To build and run a project artifact, you do something like this:

$ gradle build
$ java -jar build/libs/mymodule-0.0.1-SNAPSHOT.jar

Repackage configuration

The gradle plugin automatically extends your build script DSL with a springBoot element for configuration. Simply set the appropriate properties as you would any other gradle extension:

springBoot {
	backupSource = false
}

The following configuration options are available:

Name Type Description Default Value
mainClass String The main class that should be run. If not specified the value from the manifest will be used, or if no manifest entry is the archive will be searched for a suitable class
providedConfiguration String The name of the provided configuration providedRuntime
backupSource boolean If the original source archive should be backed-up before being repackaged true

Further Reading

For more information on how Spring Boot Loader archives work, take a look at the spring-boot-loader module. If you prefer using Maven to build your projects we have a spring-boot-maven-plugin.