Skip to content

Commit 27715de

Browse files
committed
Allow jars to be marked as a development-tool to exclude from uber-jar
Closes gh-47320
1 parent d27aedf commit 27715de

File tree

4 files changed

+13
-4
lines changed

4 files changed

+13
-4
lines changed

build-plugin/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/plugin/JarTypeFileSpec.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
package org.springframework.boot.gradle.plugin;
1818

1919
import java.io.File;
20-
import java.util.Collections;
2120
import java.util.Set;
2221
import java.util.jar.JarFile;
2322

@@ -33,7 +32,7 @@
3332
*/
3433
class JarTypeFileSpec implements Spec<File> {
3534

36-
private static final Set<String> EXCLUDED_JAR_TYPES = Collections.singleton("dependencies-starter");
35+
private static final Set<String> EXCLUDED_JAR_TYPES = Set.of("dependencies-starter", "development-tool");
3736

3837
@Override
3938
public boolean isSatisfiedBy(File file) {

build-plugin/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/tasks/bundling/AbstractBootArchiveIntegrationTests.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,7 @@ void testAndDevelopmentOnlyDependenciesCanBeIncludedInTheArchive() throws IOExce
283283
void jarTypeFilteringIsApplied() throws IOException {
284284
File flatDirRepository = new File(this.gradleBuild.getProjectDir(), "repository");
285285
createDependenciesStarterJar(new File(flatDirRepository, "starter.jar"));
286+
createDependenciesDeveloperToolsJar(new File(flatDirRepository, "devonly.jar"));
286287
createStandardJar(new File(flatDirRepository, "standard.jar"));
287288
assertThat(this.gradleBuild.build(this.taskName).task(":" + this.taskName).getOutcome())
288289
.isEqualTo(TaskOutcome.SUCCESS);
@@ -659,6 +660,10 @@ private void createDependenciesStarterJar(File location) throws IOException {
659660
createJar(location, (attributes) -> attributes.putValue("Spring-Boot-Jar-Type", "dependencies-starter"));
660661
}
661662

663+
private void createDependenciesDeveloperToolsJar(File location) throws IOException {
664+
createJar(location, (attributes) -> attributes.putValue("Spring-Boot-Jar-Type", "development-tool"));
665+
}
666+
662667
private void createJar(File location, Consumer<Attributes> attributesConfigurer) throws IOException {
663668
location.getParentFile().mkdirs();
664669
Manifest manifest = new Manifest();

build-plugin/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/JarTypeFilter.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@
3434
*/
3535
class JarTypeFilter extends DependencyFilter {
3636

37-
private static final Set<String> EXCLUDED_JAR_TYPES = Collections
38-
.unmodifiableSet(new HashSet<>(Arrays.asList("annotation-processor", "dependencies-starter")));
37+
private static final Set<String> EXCLUDED_JAR_TYPES = Collections.unmodifiableSet(
38+
new HashSet<>(Arrays.asList("annotation-processor", "dependencies-starter", "development-tool")));
3939

4040
JarTypeFilter() {
4141
super(Collections.emptyList());

build-plugin/spring-boot-maven-plugin/src/test/java/org/springframework/boot/maven/JarTypeFilterTests.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,11 @@ void whenArtifactHasAnnotationProcessorJarTypeThenItIsExcluded() {
6060
assertThat(new JarTypeFilter().filter(createArtifact("annotation-processor"))).isTrue();
6161
}
6262

63+
@Test
64+
void whenArtifactHasDevelopmentToolJarTypeThenItIsExcluded() {
65+
assertThat(new JarTypeFilter().filter(createArtifact("development-tool"))).isTrue();
66+
}
67+
6368
@Test
6469
void whenArtifactHasNoManifestFileThenItIsIncluded() {
6570
assertThat(new JarTypeFilter().filter(createArtifactWithNoManifest())).isFalse();

0 commit comments

Comments
 (0)