Skip to content

Commit 6565ff6

Browse files
committed
Clarify documentation on using a Spring Boot app as a dependency
Closes gh-6812
1 parent 155cfb1 commit 6565ff6

File tree

2 files changed

+21
-14
lines changed

2 files changed

+21
-14
lines changed

spring-boot-docs/src/main/asciidoc/build-tool-plugins.adoc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -373,10 +373,10 @@ want the other Boot features but not this one)
373373

374374
|`classifier`
375375
|A file name segment (before the extension) to add to the archive, so that the original is
376-
preserved in its original location. Defaults to null in which case the archive is
376+
preserved in its original location. Defaults to `null` in which case the archive is
377377
repackaged in place. The default is convenient for many purposes, but if you want to use
378-
the original jar as a dependency in another project, it's best to use an extension to
379-
define the executable archive.
378+
the original jar as a dependency in another project you must use a classifier to define
379+
the executable archive.
380380

381381
|`withJarTask`
382382
|The name or value of the `Jar` task (defaults to all tasks of type `Jar`) which is used

spring-boot-docs/src/main/asciidoc/howto.adoc

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2643,14 +2643,24 @@ details.
26432643

26442644

26452645
[[howto-create-an-additional-executable-jar]]
2646-
=== Create an additional executable JAR
2647-
If you want to use your project as a library jar for other projects to depend on, and in
2648-
addition have an executable (e.g. demo) version of it, you will want to configure the
2649-
build in a slightly different way.
2646+
=== Use a Spring Boot application as a dependency
2647+
Like a war file, a Spring Boot application is not intended to be used as a dependency. If
2648+
your application contains classes that you want to share with other projects, the
2649+
recommended approach is to move that code into a separate module. The separate module can
2650+
then be depended upon by your application and other projects.
26502651

2651-
For Maven the normal JAR plugin and the Spring Boot plugin both have a '`classifier`'
2652-
configuration that you can add to create an additional JAR. Example (using the Spring
2653-
Boot Starter Parent to manage the plugin versions and other configuration defaults):
2652+
If you cannot rearrange your code as recommended above, Spring Boot's Maven and Gradle
2653+
plugins must be configured to produce a separate artifact that is suitable for use as a
2654+
dependency. The executable archive cannot be used as a dependency as the
2655+
<<appendix-executable-jar-format.adoc#executable-jar-jar-file-structure,exectuable jar
2656+
format>> packages application classes in `BOOT-INF/classes`. This means
2657+
that they cannot be found when the executable jar is used as a dependency.
2658+
2659+
To produce the two artifacts, one that can be used as a dependency and one that is
2660+
executable, a classifier must be specified. This classifier is applied to the name of the
2661+
executable archive, leaving the default archive for use as dependency.
2662+
2663+
To configure a classifier of `exec` in Maven, the following configuration can be used:
26542664

26552665
[source,xml,indent=0,subs="verbatim,quotes,attributes"]
26562666
----
@@ -2667,10 +2677,7 @@ Boot Starter Parent to manage the plugin versions and other configuration defaul
26672677
</build>
26682678
----
26692679

2670-
Two jars are produced, the default one, and an executable one using the Boot plugin with
2671-
classifier '`exec`'.
2672-
2673-
For Gradle users the steps are similar. Example:
2680+
And when using Gradle, the following configuration can be used:
26742681

26752682
[source,groovy,indent=0,subs="verbatim,attributes"]
26762683
----

0 commit comments

Comments
 (0)