From 6ed63a6eff7c35a2b90211c618bc242a3cfd9b0e Mon Sep 17 00:00:00 2001 From: Stephane Nicoll Date: Tue, 24 May 2016 16:25:54 +0200 Subject: [PATCH] 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 gh-2224 --- .../src/it/jar-system-scope-default/pom.xml | 59 ++++++++++++++++++ .../main/java/org/test/SampleApplication.java | 24 +++++++ .../it/jar-system-scope-default/verify.groovy | 27 ++++++++ .../src/it/jar-system-scope/pom.xml | 62 +++++++++++++++++++ .../main/java/org/test/SampleApplication.java | 24 +++++++ .../src/it/jar-system-scope/verify.groovy | 27 ++++++++ .../boot/maven/ArtifactsLibraries.java | 3 +- .../boot/maven/RepackageMojo.java | 17 ++++- 8 files changed, 240 insertions(+), 3 deletions(-) create mode 100644 spring-boot-tools/spring-boot-maven-plugin/src/it/jar-system-scope-default/pom.xml create mode 100644 spring-boot-tools/spring-boot-maven-plugin/src/it/jar-system-scope-default/src/main/java/org/test/SampleApplication.java create mode 100644 spring-boot-tools/spring-boot-maven-plugin/src/it/jar-system-scope-default/verify.groovy create mode 100644 spring-boot-tools/spring-boot-maven-plugin/src/it/jar-system-scope/pom.xml create mode 100644 spring-boot-tools/spring-boot-maven-plugin/src/it/jar-system-scope/src/main/java/org/test/SampleApplication.java create mode 100644 spring-boot-tools/spring-boot-maven-plugin/src/it/jar-system-scope/verify.groovy diff --git a/spring-boot-tools/spring-boot-maven-plugin/src/it/jar-system-scope-default/pom.xml b/spring-boot-tools/spring-boot-maven-plugin/src/it/jar-system-scope-default/pom.xml new file mode 100644 index 0000000000..10229883bf --- /dev/null +++ b/spring-boot-tools/spring-boot-maven-plugin/src/it/jar-system-scope-default/pom.xml @@ -0,0 +1,59 @@ + + + 4.0.0 + org.springframework.boot.maven.it + jar-system-scope-default + 0.0.1.BUILD-SNAPSHOT + + UTF-8 + + + + + @project.groupId@ + @project.artifactId@ + @project.version@ + + + + repackage + + + + + + org.apache.maven.plugins + maven-jar-plugin + 2.4 + + + + Foo + + + + + + + + + org.springframework + spring-context + @spring.version@ + + + javax.servlet + javax.servlet-api + @servlet-api.version@ + provided + + + com.example + sample + 1.0.0 + system + ${project.basedir}/sample-1.0.0.jar + + + diff --git a/spring-boot-tools/spring-boot-maven-plugin/src/it/jar-system-scope-default/src/main/java/org/test/SampleApplication.java b/spring-boot-tools/spring-boot-maven-plugin/src/it/jar-system-scope-default/src/main/java/org/test/SampleApplication.java new file mode 100644 index 0000000000..e8784d4593 --- /dev/null +++ b/spring-boot-tools/spring-boot-maven-plugin/src/it/jar-system-scope-default/src/main/java/org/test/SampleApplication.java @@ -0,0 +1,24 @@ +/* + * Copyright 2012-2014 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.test; + +public class SampleApplication { + + public static void main(String[] args) { + } + +} diff --git a/spring-boot-tools/spring-boot-maven-plugin/src/it/jar-system-scope-default/verify.groovy b/spring-boot-tools/spring-boot-maven-plugin/src/it/jar-system-scope-default/verify.groovy new file mode 100644 index 0000000000..aa22640dfd --- /dev/null +++ b/spring-boot-tools/spring-boot-maven-plugin/src/it/jar-system-scope-default/verify.groovy @@ -0,0 +1,27 @@ +/* + * Copyright 2012-2014 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import java.io.*; +import org.springframework.boot.maven.*; + +File f = new File( basedir, "target/jar-system-scope-default-0.0.1.BUILD-SNAPSHOT.jar"); +new Verify.JarArchiveVerification(f, Verify.SAMPLE_APP) { + @Override + protected void verifyZipEntries(Verify.ArchiveVerifier verifier) throws Exception { + super.verifyZipEntries(verifier) + verifier.assertHasNoEntryNameStartingWith("BOOT-INF/lib/sample-1.0.0.jar") + } +}.verify(); diff --git a/spring-boot-tools/spring-boot-maven-plugin/src/it/jar-system-scope/pom.xml b/spring-boot-tools/spring-boot-maven-plugin/src/it/jar-system-scope/pom.xml new file mode 100644 index 0000000000..04a99d4e39 --- /dev/null +++ b/spring-boot-tools/spring-boot-maven-plugin/src/it/jar-system-scope/pom.xml @@ -0,0 +1,62 @@ + + + 4.0.0 + org.springframework.boot.maven.it + jar-system-scope + 0.0.1.BUILD-SNAPSHOT + + UTF-8 + + + + + @project.groupId@ + @project.artifactId@ + @project.version@ + + + + repackage + + + true + + + + + + org.apache.maven.plugins + maven-jar-plugin + 2.4 + + + + Foo + + + + + + + + + org.springframework + spring-context + @spring.version@ + + + javax.servlet + javax.servlet-api + @servlet-api.version@ + provided + + + com.example + sample + 1.0.0 + system + ${project.basedir}/sample-1.0.0.jar + + + diff --git a/spring-boot-tools/spring-boot-maven-plugin/src/it/jar-system-scope/src/main/java/org/test/SampleApplication.java b/spring-boot-tools/spring-boot-maven-plugin/src/it/jar-system-scope/src/main/java/org/test/SampleApplication.java new file mode 100644 index 0000000000..e8784d4593 --- /dev/null +++ b/spring-boot-tools/spring-boot-maven-plugin/src/it/jar-system-scope/src/main/java/org/test/SampleApplication.java @@ -0,0 +1,24 @@ +/* + * Copyright 2012-2014 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.test; + +public class SampleApplication { + + public static void main(String[] args) { + } + +} diff --git a/spring-boot-tools/spring-boot-maven-plugin/src/it/jar-system-scope/verify.groovy b/spring-boot-tools/spring-boot-maven-plugin/src/it/jar-system-scope/verify.groovy new file mode 100644 index 0000000000..534cdc7407 --- /dev/null +++ b/spring-boot-tools/spring-boot-maven-plugin/src/it/jar-system-scope/verify.groovy @@ -0,0 +1,27 @@ +/* + * Copyright 2012-2014 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import java.io.*; +import org.springframework.boot.maven.*; + +File f = new File( basedir, "target/jar-system-scope-0.0.1.BUILD-SNAPSHOT.jar"); +new Verify.JarArchiveVerification(f, Verify.SAMPLE_APP) { + @Override + protected void verifyZipEntries(Verify.ArchiveVerifier verifier) throws Exception { + super.verifyZipEntries(verifier) + verifier.assertHasEntryNameStartingWith("BOOT-INF/lib/sample-1.0.0.jar") + } +}.verify(); diff --git a/spring-boot-tools/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/ArtifactsLibraries.java b/spring-boot-tools/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/ArtifactsLibraries.java index 760c31fc32..3d478e7f65 100644 --- a/spring-boot-tools/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/ArtifactsLibraries.java +++ b/spring-boot-tools/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/ArtifactsLibraries.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2014 the original author or authors. + * Copyright 2012-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -48,6 +48,7 @@ public class ArtifactsLibraries implements Libraries { scopes.put(Artifact.SCOPE_COMPILE, LibraryScope.COMPILE); scopes.put(Artifact.SCOPE_RUNTIME, LibraryScope.RUNTIME); scopes.put(Artifact.SCOPE_PROVIDED, LibraryScope.PROVIDED); + scopes.put(Artifact.SCOPE_SYSTEM, LibraryScope.PROVIDED); SCOPES = Collections.unmodifiableMap(scopes); } diff --git a/spring-boot-tools/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/RepackageMojo.java b/spring-boot-tools/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/RepackageMojo.java index e2aa33d546..f782692e28 100644 --- a/spring-boot-tools/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/RepackageMojo.java +++ b/spring-boot-tools/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/RepackageMojo.java @@ -18,6 +18,7 @@ package org.springframework.boot.maven; import java.io.File; import java.io.IOException; +import java.util.ArrayList; import java.util.List; import java.util.Properties; import java.util.Set; @@ -37,6 +38,7 @@ import org.apache.maven.plugins.annotations.ResolutionScope; import org.apache.maven.project.MavenProject; import org.apache.maven.project.MavenProjectHelper; import org.apache.maven.shared.artifact.filter.collection.ArtifactsFilter; +import org.apache.maven.shared.artifact.filter.collection.ScopeFilter; import org.springframework.boot.loader.tools.DefaultLaunchScript; import org.springframework.boot.loader.tools.LaunchScript; @@ -171,6 +173,13 @@ public class RepackageMojo extends AbstractDependencyFilterMojo { @Parameter(defaultValue = "false") private boolean excludeDevtools; + /** + * Include system scoped dependencies. + * @since 1.4 + */ + @Parameter(defaultValue = "false") + public boolean includeSystemScope; + @Override public void execute() throws MojoExecutionException, MojoFailureException { if (this.project.getPackaging().equals("pom")) { @@ -225,14 +234,18 @@ public class RepackageMojo extends AbstractDependencyFilterMojo { } private ArtifactsFilter[] getAdditionalFilters() { + List filters = new ArrayList(); if (this.excludeDevtools) { Exclude exclude = new Exclude(); exclude.setGroupId("org.springframework.boot"); exclude.setArtifactId("spring-boot-devtools"); ExcludeFilter filter = new ExcludeFilter(exclude); - return new ArtifactsFilter[] { filter }; + filters.add(filter); + } + if (!this.includeSystemScope) { + filters.add(new ScopeFilter(null, Artifact.SCOPE_SYSTEM)); } - return new ArtifactsFilter[] {}; + return filters.toArray(new ArtifactsFilter[filters.size()]); } private LaunchScript getLaunchScript() throws IOException {