Skip to content

Commit c1e546e

Browse files
snicollmdeinum
authored andcommitted
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 spring-projectsgh-649, spring-projectsgh-650 and spring-projectsgh-674
1 parent 5dc7414 commit c1e546e

File tree

32 files changed

+1282
-54
lines changed

32 files changed

+1282
-54
lines changed

spring-boot-parent/pom.xml

+5
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,11 @@
9898
<artifactId>maven-settings-builder</artifactId>
9999
<version>${maven.version}</version>
100100
</dependency>
101+
<dependency>
102+
<groupId>org.apache.maven.shared</groupId>
103+
<artifactId>maven-common-artifact-filters</artifactId>
104+
<version>1.4</version>
105+
</dependency>
101106
<dependency>
102107
<groupId>org.apache.maven.plugins</groupId>
103108
<artifactId>maven-shade-plugin</artifactId>

spring-boot-tools/spring-boot-maven-plugin/pom.xml

+4
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,10 @@
126126
<groupId>org.apache.maven</groupId>
127127
<artifactId>maven-settings</artifactId>
128128
</dependency>
129+
<dependency>
130+
<groupId>org.apache.maven.shared</groupId>
131+
<artifactId>maven-common-artifact-filters</artifactId>
132+
</dependency>
129133
<dependency>
130134
<groupId>org.codehaus.plexus</groupId>
131135
<artifactId>plexus-archiver</artifactId>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
<groupId>org.springframework.boot.maven.it</groupId>
6+
<artifactId>jar-exclude-artifact</artifactId>
7+
<version>0.0.1.BUILD-SNAPSHOT</version>
8+
<properties>
9+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
10+
</properties>
11+
<build>
12+
<plugins>
13+
<plugin>
14+
<groupId>@project.groupId@</groupId>
15+
<artifactId>@project.artifactId@</artifactId>
16+
<version>@project.version@</version>
17+
<executions>
18+
<execution>
19+
<goals>
20+
<goal>repackage</goal>
21+
</goals>
22+
<configuration>
23+
<excludeArtifactIds>servlet-api</excludeArtifactIds>
24+
</configuration>
25+
</execution>
26+
</executions>
27+
</plugin>
28+
<plugin>
29+
<groupId>org.apache.maven.plugins</groupId>
30+
<artifactId>maven-jar-plugin</artifactId>
31+
<version>2.4</version>
32+
<configuration>
33+
<archive>
34+
<manifestEntries>
35+
<Not-Used>Foo</Not-Used>
36+
</manifestEntries>
37+
</archive>
38+
</configuration>
39+
</plugin>
40+
</plugins>
41+
</build>
42+
<dependencies>
43+
<dependency>
44+
<groupId>org.springframework</groupId>
45+
<artifactId>spring-context</artifactId>
46+
<version>3.2.3.RELEASE</version>
47+
</dependency>
48+
<dependency>
49+
<groupId>javax.servlet</groupId>
50+
<artifactId>javax.servlet-api</artifactId>
51+
<version>3.0.1</version>
52+
<scope>provided</scope>
53+
</dependency>
54+
<dependency>
55+
<groupId>javax.servlet</groupId>
56+
<artifactId>servlet-api</artifactId>
57+
<version>2.5</version>
58+
<scope>provided</scope>
59+
</dependency>
60+
</dependencies>
61+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package org.test;
2+
3+
public class SampleApplication {
4+
5+
public static void main(String[] args) {
6+
}
7+
8+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import java.io.*;
2+
import org.springframework.boot.maven.*;
3+
4+
File f = new File( basedir, "target/jar-exclude-artifact-0.0.1.BUILD-SNAPSHOT.jar");
5+
new Verify.JarArchiveVerification(f, Verify.SAMPLE_APP) {
6+
@Override
7+
protected void verifyZipEntries(Verify.ArchiveVerifier verifier) throws Exception {
8+
super.verifyZipEntries(verifier)
9+
verifier.assertHasNoEntryNameStartingWith("lib/servlet-api-2.5.jar")
10+
}
11+
}.verify();
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
~ Copyright 2012-2014 the original author or authors.
4+
~
5+
~ Licensed under the Apache License, Version 2.0 (the "License");
6+
~ you may not use this file except in compliance with the License.
7+
~ You may obtain a copy of the License at
8+
~
9+
~ http://www.apache.org/licenses/LICENSE-2.0
10+
~
11+
~ Unless required by applicable law or agreed to in writing, software
12+
~ distributed under the License is distributed on an "AS IS" BASIS,
13+
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
~ See the License for the specific language governing permissions and
15+
~ limitations under the License.
16+
-->
17+
18+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
19+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
20+
<modelVersion>4.0.0</modelVersion>
21+
<groupId>org.springframework.boot.maven.it</groupId>
22+
<artifactId>jar-exclude-entry</artifactId>
23+
<version>0.0.1.BUILD-SNAPSHOT</version>
24+
<properties>
25+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
26+
</properties>
27+
<build>
28+
<plugins>
29+
<plugin>
30+
<groupId>@project.groupId@</groupId>
31+
<artifactId>@project.artifactId@</artifactId>
32+
<version>@project.version@</version>
33+
<executions>
34+
<execution>
35+
<goals>
36+
<goal>repackage</goal>
37+
</goals>
38+
<configuration>
39+
<excludes>
40+
<exclude>
41+
<groupId>javax.servlet</groupId>
42+
<artifactId>servlet-api</artifactId>
43+
</exclude>
44+
</excludes>
45+
</configuration>
46+
</execution>
47+
</executions>
48+
</plugin>
49+
<plugin>
50+
<groupId>org.apache.maven.plugins</groupId>
51+
<artifactId>maven-jar-plugin</artifactId>
52+
<version>2.4</version>
53+
<configuration>
54+
<archive>
55+
<manifestEntries>
56+
<Not-Used>Foo</Not-Used>
57+
</manifestEntries>
58+
</archive>
59+
</configuration>
60+
</plugin>
61+
</plugins>
62+
</build>
63+
<dependencies>
64+
<dependency>
65+
<groupId>org.springframework</groupId>
66+
<artifactId>spring-context</artifactId>
67+
<version>3.2.3.RELEASE</version>
68+
</dependency>
69+
<dependency>
70+
<groupId>javax.servlet</groupId>
71+
<artifactId>javax.servlet-api</artifactId>
72+
<version>3.0.1</version>
73+
<scope>provided</scope>
74+
</dependency>
75+
<dependency>
76+
<groupId>javax.servlet</groupId>
77+
<artifactId>servlet-api</artifactId>
78+
<version>2.5</version>
79+
<scope>provided</scope>
80+
</dependency>
81+
</dependencies>
82+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package org.test;
2+
3+
public class SampleApplication {
4+
5+
public static void main(String[] args) {
6+
}
7+
8+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/*
2+
* Copyright 2012-2014 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
import java.io.*;
18+
import org.springframework.boot.maven.*;
19+
20+
File f = new File( basedir, "target/jar-exclude-entry-0.0.1.BUILD-SNAPSHOT.jar");
21+
new Verify.JarArchiveVerification(f, Verify.SAMPLE_APP) {
22+
@Override
23+
protected void verifyZipEntries(Verify.ArchiveVerifier verifier) throws Exception {
24+
super.verifyZipEntries(verifier)
25+
verifier.assertHasNoEntryNameStartingWith("lib/servlet-api-2.5.jar")
26+
}
27+
}.verify();
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
~ Copyright 2012-2014 the original author or authors.
4+
~
5+
~ Licensed under the Apache License, Version 2.0 (the "License");
6+
~ you may not use this file except in compliance with the License.
7+
~ You may obtain a copy of the License at
8+
~
9+
~ http://www.apache.org/licenses/LICENSE-2.0
10+
~
11+
~ Unless required by applicable law or agreed to in writing, software
12+
~ distributed under the License is distributed on an "AS IS" BASIS,
13+
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
~ See the License for the specific language governing permissions and
15+
~ limitations under the License.
16+
-->
17+
18+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
19+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
20+
<modelVersion>4.0.0</modelVersion>
21+
<groupId>org.springframework.boot.maven.it</groupId>
22+
<artifactId>jar-exclude-group</artifactId>
23+
<version>0.0.1.BUILD-SNAPSHOT</version>
24+
<properties>
25+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
26+
</properties>
27+
<build>
28+
<plugins>
29+
<plugin>
30+
<groupId>@project.groupId@</groupId>
31+
<artifactId>@project.artifactId@</artifactId>
32+
<version>@project.version@</version>
33+
<executions>
34+
<execution>
35+
<goals>
36+
<goal>repackage</goal>
37+
</goals>
38+
<configuration>
39+
<excludeGroupIds>log4j</excludeGroupIds>
40+
</configuration>
41+
</execution>
42+
</executions>
43+
</plugin>
44+
<plugin>
45+
<groupId>org.apache.maven.plugins</groupId>
46+
<artifactId>maven-jar-plugin</artifactId>
47+
<version>2.4</version>
48+
<configuration>
49+
<archive>
50+
<manifestEntries>
51+
<Not-Used>Foo</Not-Used>
52+
</manifestEntries>
53+
</archive>
54+
</configuration>
55+
</plugin>
56+
</plugins>
57+
</build>
58+
<dependencies>
59+
<dependency>
60+
<groupId>org.springframework</groupId>
61+
<artifactId>spring-context</artifactId>
62+
<version>3.2.3.RELEASE</version>
63+
</dependency>
64+
<dependency>
65+
<groupId>javax.servlet</groupId>
66+
<artifactId>javax.servlet-api</artifactId>
67+
<version>3.0.1</version>
68+
<scope>provided</scope>
69+
</dependency>
70+
<dependency>
71+
<groupId>log4j</groupId>
72+
<artifactId>log4j</artifactId>
73+
<version>1.2.17</version>
74+
</dependency>
75+
</dependencies>
76+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package org.test;
2+
3+
public class SampleApplication {
4+
5+
public static void main(String[] args) {
6+
}
7+
8+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/*
2+
* Copyright 2012-2014 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
import java.io.*;
18+
import org.springframework.boot.maven.*;
19+
20+
File f = new File( basedir, "target/jar-exclude-group-0.0.1.BUILD-SNAPSHOT.jar");
21+
new Verify.JarArchiveVerification(f, Verify.SAMPLE_APP) {
22+
@Override
23+
protected void verifyZipEntries(Verify.ArchiveVerifier verifier) throws Exception {
24+
super.verifyZipEntries(verifier)
25+
verifier.assertHasNoEntryNameStartingWith("lib/log4j-1.2.17.jar")
26+
}
27+
}.verify();

0 commit comments

Comments
 (0)