Skip to content

Commit a417c94

Browse files
committed
Merge pull request #39837 from mstahv
* gh-39837: Make includes configurable via a property Polish "Make excludes configurable via property" Make excludes configurable via property Closes gh-39837
2 parents 2f3cf56 + baf5a7f commit a417c94

File tree

6 files changed

+147
-9
lines changed

6 files changed

+147
-9
lines changed

spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/intTest/java/org/springframework/boot/maven/JarIntegrationTests.java

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,48 @@ void whenAnEntryIsExcludedItDoesNotAppearInTheRepackagedJar(MavenBuild mavenBuil
179179
});
180180
}
181181

182+
@TestTemplate
183+
void whenAnEntryIsExcludedWithPropertyItDoesNotAppearInTheRepackagedJar(MavenBuild mavenBuild) {
184+
mavenBuild.project("jar")
185+
.systemProperty("spring-boot.excludes", "jakarta.servlet:jakarta.servlet-api")
186+
.goals("install")
187+
.execute((project) -> {
188+
File repackaged = new File(project, "target/jar-0.0.1.BUILD-SNAPSHOT.jar");
189+
assertThat(jar(repackaged)).hasEntryWithNameStartingWith("BOOT-INF/classes/")
190+
.hasEntryWithNameStartingWith("BOOT-INF/lib/spring-context")
191+
.hasEntryWithNameStartingWith("BOOT-INF/lib/spring-core")
192+
.hasEntryWithNameStartingWith("BOOT-INF/lib/spring-jcl")
193+
.doesNotHaveEntryWithNameStartingWith("BOOT-INF/lib/jakarta.servlet-api-");
194+
});
195+
}
196+
197+
@TestTemplate
198+
void whenAnEntryIsIncludedOnlyIncludedEntriesAppearInTheRepackagedJar(MavenBuild mavenBuild) {
199+
mavenBuild.project("jar-include-entry").goals("install").execute((project) -> {
200+
File repackaged = new File(project, "target/jar-include-entry-0.0.1.BUILD-SNAPSHOT.jar");
201+
assertThat(jar(repackaged)).hasEntryWithNameStartingWith("BOOT-INF/classes/")
202+
.hasEntryWithNameStartingWith("BOOT-INF/lib/jakarta.servlet-api-")
203+
.doesNotHaveEntryWithNameStartingWith("BOOT-INF/lib/spring-context")
204+
.doesNotHaveEntryWithNameStartingWith("BOOT-INF/lib/spring-core")
205+
.doesNotHaveEntryWithNameStartingWith("BOOT-INF/lib/spring-jcl");
206+
});
207+
}
208+
209+
@TestTemplate
210+
void whenAnIncludeIsSpecifiedAsAPropertyOnlyIncludedEntriesAppearInTheRepackagedJar(MavenBuild mavenBuild) {
211+
mavenBuild.project("jar")
212+
.systemProperty("spring-boot.includes", "jakarta.servlet:jakarta.servlet-api")
213+
.goals("install")
214+
.execute((project) -> {
215+
File repackaged = new File(project, "target/jar-0.0.1.BUILD-SNAPSHOT.jar");
216+
assertThat(jar(repackaged)).hasEntryWithNameStartingWith("BOOT-INF/classes/")
217+
.hasEntryWithNameStartingWith("BOOT-INF/lib/jakarta.servlet-api-")
218+
.doesNotHaveEntryWithNameStartingWith("BOOT-INF/lib/spring-context")
219+
.doesNotHaveEntryWithNameStartingWith("BOOT-INF/lib/spring-core")
220+
.doesNotHaveEntryWithNameStartingWith("BOOT-INF/lib/spring-jcl");
221+
});
222+
}
223+
182224
@TestTemplate
183225
void whenAGroupIsExcludedNoEntriesInThatGroupAppearInTheRepackagedJar(MavenBuild mavenBuild) {
184226
mavenBuild.project("jar-exclude-group").goals("install").execute((project) -> {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
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 https://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-include-entry</artifactId>
7+
<version>0.0.1.BUILD-SNAPSHOT</version>
8+
<properties>
9+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
10+
<maven.compiler.source>@java.version@</maven.compiler.source>
11+
<maven.compiler.target>@java.version@</maven.compiler.target>
12+
</properties>
13+
<build>
14+
<plugins>
15+
<plugin>
16+
<groupId>@project.groupId@</groupId>
17+
<artifactId>@project.artifactId@</artifactId>
18+
<version>@project.version@</version>
19+
<executions>
20+
<execution>
21+
<goals>
22+
<goal>repackage</goal>
23+
</goals>
24+
<configuration>
25+
<includes>
26+
<include>
27+
<groupId>jakarta.servlet</groupId>
28+
<artifactId>jakarta.servlet-api</artifactId>
29+
</include>
30+
</includes>
31+
</configuration>
32+
</execution>
33+
</executions>
34+
</plugin>
35+
</plugins>
36+
</build>
37+
<dependencies>
38+
<dependency>
39+
<groupId>org.springframework</groupId>
40+
<artifactId>spring-context</artifactId>
41+
<version>@spring-framework.version@</version>
42+
</dependency>
43+
<dependency>
44+
<groupId>jakarta.servlet</groupId>
45+
<artifactId>jakarta.servlet-api</artifactId>
46+
<version>@jakarta-servlet.version@</version>
47+
<scope>provided</scope>
48+
</dependency>
49+
</dependencies>
50+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/*
2+
* Copyright 2012-2024 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+
* https://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+
}

spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/AbstractDependencyFilterMojo.java

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2023 the original author or authors.
2+
* Copyright 2012-2024 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.
@@ -71,18 +71,21 @@ public abstract class AbstractDependencyFilterMojo extends AbstractMojo {
7171

7272
/**
7373
* Collection of artifact definitions to include. The {@link Include} element defines
74-
* mandatory {@code groupId} and {@code artifactId} properties and an optional
75-
* mandatory {@code groupId} and {@code artifactId} properties and an optional
76-
* {@code classifier} property.
74+
* mandatory {@code groupId} and {@code artifactId} components and an optional
75+
* {@code classifier} component. When configured as a property, values should be
76+
* comma-separated with colon-separated components:
77+
* {@code groupId:artifactId,groupId:artifactId:classifier}
7778
* @since 1.2.0
7879
*/
7980
@Parameter(property = "spring-boot.includes")
8081
private List<Include> includes;
8182

8283
/**
8384
* Collection of artifact definitions to exclude. The {@link Exclude} element defines
84-
* mandatory {@code groupId} and {@code artifactId} properties and an optional
85-
* {@code classifier} property.
85+
* mandatory {@code groupId} and {@code artifactId} components and an optional
86+
* {@code classifier} component. When configured as a property, values should be
87+
* comma-separated with colon-separated components:
88+
* {@code groupId:artifactId,groupId:artifactId:classifier}
8689
* @since 1.1.0
8790
*/
8891
@Parameter(property = "spring-boot.excludes")

spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/Exclude.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2019 the original author or authors.
2+
* Copyright 2012-2024 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.

spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/FilterableDependency.java

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2019 the original author or authors.
2+
* Copyright 2012-2024 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.
@@ -18,13 +18,16 @@
1818

1919
import org.apache.maven.plugins.annotations.Parameter;
2020

21+
import org.springframework.util.Assert;
22+
2123
/**
2224
* A model for a dependency to include or exclude.
2325
*
2426
* @author Stephane Nicoll
2527
* @author David Turanski
28+
* @since 3.1.11
2629
*/
27-
abstract class FilterableDependency {
30+
public abstract class FilterableDependency {
2831

2932
/**
3033
* The groupId of the artifact to exclude.
@@ -68,4 +71,20 @@ void setClassifier(String classifier) {
6871
this.classifier = classifier;
6972
}
7073

74+
/**
75+
* Configures the include or exclude using a user-provided property in the form
76+
* {@code groupId:artifactId} or {@code groupId:artifactId:classifier}.
77+
* @param property the user-provided property
78+
*/
79+
public void set(String property) {
80+
String[] parts = property.split(":");
81+
Assert.isTrue(parts.length == 2 || parts.length == 3, getClass().getSimpleName()
82+
+ " must be in the form groupId:artifactId or groupId:artifactId:classifier");
83+
setGroupId(parts[0]);
84+
setArtifactId(parts[1]);
85+
if (parts.length == 3) {
86+
setClassifier(parts[2]);
87+
}
88+
}
89+
7190
}

0 commit comments

Comments
 (0)