Support for non-executable JAR in addition to the repackaged one

Stretches the Gradle boot plugin a bit, so there's a sample build
in the "profile" sample. Howto docs give examples.

Fixes gh-1135
This commit is contained in:
Dave Syer
2014-06-23 11:00:03 +01:00
parent 1b97e8d921
commit 542896b28f
6 changed files with 259 additions and 29 deletions

View File

@@ -404,6 +404,10 @@ The following configuration options are available:
|===
|Name |Description
|`enabled`
|Boolean flag to switch the repackager off (sometimes useful if you
want the other Boot features but not this one)
|`mainClass`
|The main class that should be run. If not specified the `mainClassName` project property
will be used or, if the no `mainClassName` id defined the archive will be searched for a
@@ -419,9 +423,10 @@ The following configuration options are available:
the original jar as a dependency in another project, it's best to use an extension to
define the executable archive.
|`withJarTask`
|The name of the `Jar` task (defaults to all) which is used to locate the archive to
repackage.
|`withJarTask`
|The name or value of the `Jar` task (defaults to all
tasks of type `Jar`) which is used to locate the archive to
repackage.
|`customConfiguration`
|The name of the custom configuration whuch is used to populate the nested lib directory

View File

@@ -1579,6 +1579,122 @@ See the {spring-boot-maven-plugin-site}/usage.html[plugin documentation] for ful
details.
[[howto-create-an-additional-executable-jar]]
=== Create an additional executable JAR
If you want to use your project as a library jar for other projects to
depend on, and in addition have an executable (e.g. demo) version of
it, you will want to configure the build in a slightly different way.
For Maven the normal JAR plugin and the Spring Boot plugin both have a
"classifier" configuration that you can add to create an additional JAR.
Example (using the Spring Boot Starter Parent to manage the plugin
versions and other configuration defaults):
[source,xml,indent=0,subs="verbatim,quotes,attributes"]
----
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<classifier>exec</classifier>
</configuration>
</plugin>
</plugins>
</build>
----
Two jars are produced, the default one, and an executable one using
the Boot plugin with classifier "exec".
For Gradle users the steps are similar. Example:
[source,groovy,indent=0,subs="verbatim,attributes"]
----
bootRepackage {
classifier = 'exec'
}
----
[[howto-create-a-nonexecutable-jar]]
=== Create a non-executable JAR with exclusions
Often if you have an executable and a non-executable jar
as biuld products, the executable version will have additional
configuration files that ar enot needed in a library jar. E.g. the
`application.yml` configuration file might excluded from the
non-executable JAR.
Here's how to do that in Maven
[source,xml,indent=0,subs="verbatim,quotes,attributes"]
----
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<classifier>exec</classifier>
</configuration>
</plugin>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<executions>
<execution>
<id>exec</id>
<phase>package</phase>
<goals>
<goal>jar</goal>
</goals>
<configuration>
<classifier>exec</classifier>
</configuration>
</execution>
<execution>
<phase>package</phase>
<goals>
<goal>jar</goal>
</goals>
<configuration>
<!-- Need this to ensure application.yml is excluded -->
<forceCreation>true</forceCreation>
<excludes>
<exclude>application.yml</exclude>
</excludes>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
----
In Gradle you can create a new JAR archive with standard task DSL
features, and then have the `bootRepackage` task depend on that one
using its `withJarTask` property:
[source,groovy,indent=0,subs="verbatim,attributes"]
----
jar {
baseName = 'spring-boot-sample-profile'
version = '0.0.0'
excludes = ['**/application.yml']
}
task('execJar', type:Jar, dependsOn: 'jar') {
baseName = 'spring-boot-sample-profile'
version = '0.0.0'
classifier = 'exec'
from sourceSets.main.output
}
bootRepackage {
withJarTask = tasks['execJar']
}
----
[[howto-remote-debug-maven-run]]
=== Remote debug a Spring Boot application started with Maven