Allow jars to be marked as a development-tool to exclude from uber-jar

Closes gh-47320
This commit is contained in:
Phillip Webb
2025-09-24 16:38:44 -07:00
parent d27aedf92a
commit 27715dee20
4 changed files with 13 additions and 4 deletions
@@ -17,7 +17,6 @@
package org.springframework.boot.gradle.plugin;
import java.io.File;
import java.util.Collections;
import java.util.Set;
import java.util.jar.JarFile;
@@ -33,7 +32,7 @@ import org.gradle.api.specs.Spec;
*/
class JarTypeFileSpec implements Spec<File> {
private static final Set<String> EXCLUDED_JAR_TYPES = Collections.singleton("dependencies-starter");
private static final Set<String> EXCLUDED_JAR_TYPES = Set.of("dependencies-starter", "development-tool");
@Override
public boolean isSatisfiedBy(File file) {
@@ -283,6 +283,7 @@ abstract class AbstractBootArchiveIntegrationTests {
void jarTypeFilteringIsApplied() throws IOException {
File flatDirRepository = new File(this.gradleBuild.getProjectDir(), "repository");
createDependenciesStarterJar(new File(flatDirRepository, "starter.jar"));
createDependenciesDeveloperToolsJar(new File(flatDirRepository, "devonly.jar"));
createStandardJar(new File(flatDirRepository, "standard.jar"));
assertThat(this.gradleBuild.build(this.taskName).task(":" + this.taskName).getOutcome())
.isEqualTo(TaskOutcome.SUCCESS);
@@ -659,6 +660,10 @@ abstract class AbstractBootArchiveIntegrationTests {
createJar(location, (attributes) -> attributes.putValue("Spring-Boot-Jar-Type", "dependencies-starter"));
}
private void createDependenciesDeveloperToolsJar(File location) throws IOException {
createJar(location, (attributes) -> attributes.putValue("Spring-Boot-Jar-Type", "development-tool"));
}
private void createJar(File location, Consumer<Attributes> attributesConfigurer) throws IOException {
location.getParentFile().mkdirs();
Manifest manifest = new Manifest();
@@ -34,8 +34,8 @@ import org.apache.maven.artifact.Artifact;
*/
class JarTypeFilter extends DependencyFilter {
private static final Set<String> EXCLUDED_JAR_TYPES = Collections
.unmodifiableSet(new HashSet<>(Arrays.asList("annotation-processor", "dependencies-starter")));
private static final Set<String> EXCLUDED_JAR_TYPES = Collections.unmodifiableSet(
new HashSet<>(Arrays.asList("annotation-processor", "dependencies-starter", "development-tool")));
JarTypeFilter() {
super(Collections.emptyList());
@@ -60,6 +60,11 @@ class JarTypeFilterTests {
assertThat(new JarTypeFilter().filter(createArtifact("annotation-processor"))).isTrue();
}
@Test
void whenArtifactHasDevelopmentToolJarTypeThenItIsExcluded() {
assertThat(new JarTypeFilter().filter(createArtifact("development-tool"))).isTrue();
}
@Test
void whenArtifactHasNoManifestFileThenItIsIncluded() {
assertThat(new JarTypeFilter().filter(createArtifactWithNoManifest())).isFalse();