Exclude support in the maven plugin

This commit provides several options to exclude one or more
dependencies:

* excludes allows to specify an arbitrary number of exclude sub
  element defining the groupId and artifactId of the dependency
  to exclude
* excludedGroupIds defines the comma separated list of groupIds
  to exclude
* excludeArtifactIds defines the comma separated list of artifactIds
  to exclude

While any artifact can be excluded, this is designed to exclude
provided-scoped dependencies that should not be bundled in the
executable jar/war.

The outcome of java -jar myapp.jar should be consistent with the run
goal: these exclusions are therefore applied to the classpath that
the run goal computes to launch the application.

This commit also adds some integration tests and updates the
plugin's documentation

Fixes gh-649, gh-650 and gh-674
This commit is contained in:
Stephane Nicoll
2014-05-06 14:54:09 +02:00
parent 28bd87cbae
commit 15501eaafb
32 changed files with 1282 additions and 54 deletions

View File

@@ -0,0 +1,117 @@
-----
Exclude a dependency
-----
Stephane Nicoll
-----
2014-05-06
-----
By default, both the <<<repackage>>> and the <<<run>>> goals will include any <<<provided>>>
dependencies that are defined in the project. A boot-based project should consider
<<<provided>>> dependencies as <<container>> dependencies that are required to run
the application.
Some of these dependencies may not be required at all and should be excluded from the
executable jar. For consistency, they should not be present either when running the
application.
There are tree ways one can exclude a dependency from being packaged/used at runtime
* Exclude a specific artifact identified by <<<groupId>>> and <<<artifactId>>>
(optionnaly with a <<<classifier>>> if needed)
* Exclude any artifact matching a given <<<artifactId>>>
* Exclude any artifact belonging to a given <<<groupId>>>
[]
The following excludes <<<com.foo:bar>>> (and only that artifact)
---
<project>
...
<build>
...
<plugins>
...
<plugin>
<groupId>${project.groupId}</groupId>
<artifactId>${project.artifactId}</artifactId>
<version>${project.version}</version>
<configuration>
<excludes>
<exclude>
<groupId>com.foo</groupId>
<artifactId>bar</artifactId>
</exclude>
</excludes>
</configuration>
...
</plugin>
...
</plugins>
...
</build>
...
</project>
---
This example excludes every artifacts having the <<<my-lib>>> or <<<another-lib>>>
artifact identifiers
---
<project>
...
<build>
...
<plugins>
...
<plugin>
<groupId>${project.groupId}</groupId>
<artifactId>${project.artifactId}</artifactId>
<version>${project.version}</version>
<configuration>
<excludes>
<excludeArtifactIds>my-lib,another-lib</excludeArtifactIds>
</excludes>
</configuration>
...
</plugin>
...
</plugins>
...
</build>
...
</project>
---
Finally this example excludes any artifact belonging to the <<<com.foo>>> group
---
<project>
...
<build>
...
<plugins>
...
<plugin>
<groupId>${project.groupId}</groupId>
<artifactId>${project.artifactId}</artifactId>
<version>${project.version}</version>
<configuration>
<excludes>
<excludeGroupIds>com.foo</excludeGroupIds>
</excludes>
</configuration>
...
</plugin>
...
</plugins>
...
</build>
...
</project>
---

View File

@@ -38,6 +38,8 @@ Spring Boot Maven Plugin
* {{{./examples/repackage-classifier.html}Custom repackage classifier}}
* {{{./examples/exclude-dependency.html}Exclude a dependency}}
[]

View File

@@ -4,7 +4,7 @@
-----
Stephane Nicoll
-----
2014-05-02
2014-05-06
-----
Usage
@@ -40,9 +40,13 @@ Usage
</build>
---
The example above repackages a jar or war that is built during the package phase of the Maven lifecycle. The
original (i.e. non exectuable) artifact is renamed to <<<.original>>> by default but it is also possible to
keep the original artifact using a custom classifier.
The example above repackages a jar or war that is built during the package phase of the Maven lifecycle,
including any <<<provided>>> dependencies that are defined in the project. If some of these dependencies
need to be excluded, you can use one of the exclude options,
see {{{./examples/exclude-dependency.html}Exclude a dependency}} for more details.
The original (i.e. non exectuable) artifact is renamed to <<<.original>>> by default but it is also
possible to keep the original artifact using a custom classifier.
The plugin rewrites your manifest, and in particular it manages the <<Main-Class>> and <<Start-Class>>
entries, so if the defaults don't work you have to configure those there (not in the jar plugin). The
@@ -82,6 +86,8 @@ Usage
* {{{./examples/repackage-classifier.html}Custom repackage classifier}}
* {{{./examples/exclude-dependency.html}Exclude a dependency}}
[]
* Running the application
@@ -120,4 +126,9 @@ mvn spring-boot:run
</plugins>
...
</build>
---
---
In order to be consistent with the <<<repackage>>> goal, the <<<run>>> goal builds the classpath
in such a way that any dependency that is excluded in the plugin's configuration gets excluded
from the classpath as well. See {{{./examples/exclude-dependency.html}Exclude a dependency}} for
more details.

View File

@@ -8,6 +8,7 @@
</menu>
<menu name="Examples">
<item name="Custom repackage classifier" href="examples/repackage-classifier.html"/>
<item name="Exclude a dependency" href="examples/exclude-dependency.html"/>
</menu>
<menu ref="reports"/>
</body>