Skip to content

Commit 6ed63a6

Browse files
committed
Add support of system-scoped dependencies
In Maven land, provided and system-scope dependencies are very similar, the latter being an special kind that allows you to specify the path to the artifact rather than using the repository to locate it. Prior to this commit, the repackage goal of the maven plugin was inconsistent as it would repackage provided-scope dependencies but would ignore the system-scoped ones. This commit adds an extra boolean flag, `includeSystemScope` to control this behaviour. For backward compatibility reasons, its default value is `false`. Closes spring-projectsgh-2224
1 parent 98a039e commit 6ed63a6

File tree

8 files changed

+240
-3
lines changed

8 files changed

+240
-3
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
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-system-scope-default</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+
</execution>
23+
</executions>
24+
</plugin>
25+
<plugin>
26+
<groupId>org.apache.maven.plugins</groupId>
27+
<artifactId>maven-jar-plugin</artifactId>
28+
<version>2.4</version>
29+
<configuration>
30+
<archive>
31+
<manifestEntries>
32+
<Not-Used>Foo</Not-Used>
33+
</manifestEntries>
34+
</archive>
35+
</configuration>
36+
</plugin>
37+
</plugins>
38+
</build>
39+
<dependencies>
40+
<dependency>
41+
<groupId>org.springframework</groupId>
42+
<artifactId>spring-context</artifactId>
43+
<version>@spring.version@</version>
44+
</dependency>
45+
<dependency>
46+
<groupId>javax.servlet</groupId>
47+
<artifactId>javax.servlet-api</artifactId>
48+
<version>@servlet-api.version@</version>
49+
<scope>provided</scope>
50+
</dependency>
51+
<dependency>
52+
<groupId>com.example</groupId>
53+
<artifactId>sample</artifactId>
54+
<version>1.0.0</version>
55+
<scope>system</scope>
56+
<systemPath>${project.basedir}/sample-1.0.0.jar</systemPath>
57+
</dependency>
58+
</dependencies>
59+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
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+
package org.test;
18+
19+
public class SampleApplication {
20+
21+
public static void main(String[] args) {
22+
}
23+
24+
}
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-system-scope-default-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("BOOT-INF/lib/sample-1.0.0.jar")
26+
}
27+
}.verify();
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
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-system-scope</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+
<includeSystemScope>true</includeSystemScope>
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>@spring.version@</version>
47+
</dependency>
48+
<dependency>
49+
<groupId>javax.servlet</groupId>
50+
<artifactId>javax.servlet-api</artifactId>
51+
<version>@servlet-api.version@</version>
52+
<scope>provided</scope>
53+
</dependency>
54+
<dependency>
55+
<groupId>com.example</groupId>
56+
<artifactId>sample</artifactId>
57+
<version>1.0.0</version>
58+
<scope>system</scope>
59+
<systemPath>${project.basedir}/sample-1.0.0.jar</systemPath>
60+
</dependency>
61+
</dependencies>
62+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
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+
package org.test;
18+
19+
public class SampleApplication {
20+
21+
public static void main(String[] args) {
22+
}
23+
24+
}
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-system-scope-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.assertHasEntryNameStartingWith("BOOT-INF/lib/sample-1.0.0.jar")
26+
}
27+
}.verify();

Diff for: spring-boot-tools/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/ArtifactsLibraries.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2014 the original author or authors.
2+
* Copyright 2012-2016 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -48,6 +48,7 @@ public class ArtifactsLibraries implements Libraries {
4848
scopes.put(Artifact.SCOPE_COMPILE, LibraryScope.COMPILE);
4949
scopes.put(Artifact.SCOPE_RUNTIME, LibraryScope.RUNTIME);
5050
scopes.put(Artifact.SCOPE_PROVIDED, LibraryScope.PROVIDED);
51+
scopes.put(Artifact.SCOPE_SYSTEM, LibraryScope.PROVIDED);
5152
SCOPES = Collections.unmodifiableMap(scopes);
5253
}
5354

Diff for: spring-boot-tools/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/RepackageMojo.java

+15-2
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
import java.io.File;
2020
import java.io.IOException;
21+
import java.util.ArrayList;
2122
import java.util.List;
2223
import java.util.Properties;
2324
import java.util.Set;
@@ -37,6 +38,7 @@
3738
import org.apache.maven.project.MavenProject;
3839
import org.apache.maven.project.MavenProjectHelper;
3940
import org.apache.maven.shared.artifact.filter.collection.ArtifactsFilter;
41+
import org.apache.maven.shared.artifact.filter.collection.ScopeFilter;
4042

4143
import org.springframework.boot.loader.tools.DefaultLaunchScript;
4244
import org.springframework.boot.loader.tools.LaunchScript;
@@ -171,6 +173,13 @@ public class RepackageMojo extends AbstractDependencyFilterMojo {
171173
@Parameter(defaultValue = "false")
172174
private boolean excludeDevtools;
173175

176+
/**
177+
* Include system scoped dependencies.
178+
* @since 1.4
179+
*/
180+
@Parameter(defaultValue = "false")
181+
public boolean includeSystemScope;
182+
174183
@Override
175184
public void execute() throws MojoExecutionException, MojoFailureException {
176185
if (this.project.getPackaging().equals("pom")) {
@@ -225,14 +234,18 @@ private Repackager getRepackager(File source) {
225234
}
226235

227236
private ArtifactsFilter[] getAdditionalFilters() {
237+
List<ArtifactsFilter> filters = new ArrayList<ArtifactsFilter>();
228238
if (this.excludeDevtools) {
229239
Exclude exclude = new Exclude();
230240
exclude.setGroupId("org.springframework.boot");
231241
exclude.setArtifactId("spring-boot-devtools");
232242
ExcludeFilter filter = new ExcludeFilter(exclude);
233-
return new ArtifactsFilter[] { filter };
243+
filters.add(filter);
244+
}
245+
if (!this.includeSystemScope) {
246+
filters.add(new ScopeFilter(null, Artifact.SCOPE_SYSTEM));
234247
}
235-
return new ArtifactsFilter[] {};
248+
return filters.toArray(new ArtifactsFilter[filters.size()]);
236249
}
237250

238251
private LaunchScript getLaunchScript() throws IOException {

0 commit comments

Comments
 (0)