Skip to content

Commit c2961a1

Browse files
committed
Exclude docker-compose and devtools during AOT processing
Update `ProcessAotMojo` so that `spring-boot-docker-compose` and `spring-boot-devtools` are not included on the classpath. Fixes gh-35548
1 parent f63f9c5 commit c2961a1

File tree

6 files changed

+118
-13
lines changed

6 files changed

+118
-13
lines changed

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

+9
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,15 @@ void whenAotTestRunsSourcesAndResourcesAreGenerated(MavenBuild mavenBuild) {
176176
});
177177
}
178178

179+
@TestTemplate
180+
void whenAotWithDevelopmentOnlyExclusions(MavenBuild mavenBuild) {
181+
mavenBuild.project("aot-development-only-exclusions").goals("package").execute((project) -> {
182+
Path aotDirectory = project.toPath().resolve("target/spring-aot/main");
183+
assertThat(collectRelativePaths(aotDirectory.resolve("sources")))
184+
.contains(Path.of("org", "test", "SampleApplication__ApplicationContextInitializer.java"));
185+
});
186+
}
187+
179188
List<Path> collectRelativePaths(Path sourceDirectory) {
180189
try (Stream<Path> pathStream = Files.walk(sourceDirectory)) {
181190
return pathStream.filter(Files::isRegularFile)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
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>aot-development-only-exclusions</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>process-aot</goal>
23+
</goals>
24+
</execution>
25+
</executions>
26+
</plugin>
27+
</plugins>
28+
</build>
29+
<dependencies>
30+
<dependency>
31+
<groupId>org.springframework.boot</groupId>
32+
<artifactId>spring-boot</artifactId>
33+
<version>@project.version@</version>
34+
</dependency>
35+
<dependency>
36+
<groupId>jakarta.servlet</groupId>
37+
<artifactId>jakarta.servlet-api</artifactId>
38+
<version>@jakarta-servlet.version@</version>
39+
<scope>provided</scope>
40+
</dependency>
41+
<dependency>
42+
<groupId>org.springframework.boot</groupId>
43+
<artifactId>spring-boot-devtools</artifactId>
44+
<version>@project.version@</version>
45+
<optional>true</optional>
46+
</dependency>
47+
<dependency>
48+
<groupId>org.springframework.boot</groupId>
49+
<artifactId>spring-boot-docker-compose</artifactId>
50+
<version>@project.version@</version>
51+
<optional>true</optional>
52+
</dependency>
53+
</dependencies>
54+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
* Copyright 2012-2023 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+
import org.springframework.boot.SpringApplication;
20+
import org.springframework.context.annotation.Configuration;
21+
import org.springframework.util.Assert;
22+
import org.springframework.util.ClassUtils;
23+
24+
@Configuration(proxyBeanMethods = false)
25+
public class SampleApplication {
26+
27+
public static void main(String[] args) {
28+
Assert.state(!ClassUtils.isPresent("org.springframework.boot.devtools.autoconfigure.DevToolsProperties", null), "Should not have devtools");
29+
Assert.state(!ClassUtils.isPresent("org.springframework.boot.docker.compose.core.DockerCompose", null), "Should not have docker-compose");
30+
SpringApplication.run(SampleApplication.class, args);
31+
}
32+
33+
}

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

+17-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2022 the original author or authors.
2+
* Copyright 2012-2023 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.
@@ -46,6 +46,22 @@
4646
*/
4747
public abstract class AbstractDependencyFilterMojo extends AbstractMojo {
4848

49+
static final ExcludeFilter DEVTOOLS_EXCLUDE_FILTER;
50+
static {
51+
Exclude exclude = new Exclude();
52+
exclude.setGroupId("org.springframework.boot");
53+
exclude.setArtifactId("spring-boot-devtools");
54+
DEVTOOLS_EXCLUDE_FILTER = new ExcludeFilter(exclude);
55+
}
56+
57+
static final ExcludeFilter DOCKER_COMPOSE_EXCLUDE_FILTER;
58+
static {
59+
Exclude exclude = new Exclude();
60+
exclude.setGroupId("org.springframework.boot");
61+
exclude.setArtifactId("spring-boot-docker-compose");
62+
DOCKER_COMPOSE_EXCLUDE_FILTER = new ExcludeFilter(exclude);
63+
}
64+
4965
/**
5066
* The Maven project.
5167
* @since 3.0.0

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

+2-10
Original file line numberDiff line numberDiff line change
@@ -198,18 +198,10 @@ protected final Libraries getLibraries(Collection<Dependency> unpacks) throws Mo
198198
private ArtifactsFilter[] getAdditionalFilters() {
199199
List<ArtifactsFilter> filters = new ArrayList<>();
200200
if (this.excludeDevtools) {
201-
Exclude exclude = new Exclude();
202-
exclude.setGroupId("org.springframework.boot");
203-
exclude.setArtifactId("spring-boot-devtools");
204-
ExcludeFilter filter = new ExcludeFilter(exclude);
205-
filters.add(filter);
201+
filters.add(DEVTOOLS_EXCLUDE_FILTER);
206202
}
207203
if (this.excludeDockerCompose) {
208-
Exclude exclude = new Exclude();
209-
exclude.setGroupId("org.springframework.boot");
210-
exclude.setArtifactId("spring-boot-docker-compose");
211-
ExcludeFilter filter = new ExcludeFilter(exclude);
212-
filters.add(filter);
204+
filters.add(DOCKER_COMPOSE_EXCLUDE_FILTER);
213205
}
214206
if (!this.includeSystemScope) {
215207
filters.add(new ScopeFilter(null, Artifact.SCOPE_SYSTEM));

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

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2022 the original author or authors.
2+
* Copyright 2012-2023 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.
@@ -111,7 +111,8 @@ private String[] getAotArguments(String applicationClass) {
111111

112112
private URL[] getClassPath() throws Exception {
113113
File[] directories = new File[] { this.classesDirectory, this.generatedClasses };
114-
return getClassPath(directories, new ExcludeTestScopeArtifactFilter());
114+
return getClassPath(directories, new ExcludeTestScopeArtifactFilter(), DEVTOOLS_EXCLUDE_FILTER,
115+
DOCKER_COMPOSE_EXCLUDE_FILTER);
115116
}
116117

117118
private RunArguments resolveArguments() {

0 commit comments

Comments
 (0)