diff --git a/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/intTest/java/org/springframework/boot/maven/AotTests.java b/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/intTest/java/org/springframework/boot/maven/AotTests.java
index 33295022b53..3a6469ab532 100644
--- a/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/intTest/java/org/springframework/boot/maven/AotTests.java
+++ b/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/intTest/java/org/springframework/boot/maven/AotTests.java
@@ -16,6 +16,7 @@
package org.springframework.boot.maven;
+import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
@@ -25,12 +26,14 @@ import org.junit.jupiter.api.TestTemplate;
import org.junit.jupiter.api.extension.ExtendWith;
import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.contentOf;
/**
* Integration tests for the Maven plugin's AOT support.
*
* @author Stephane Nicoll
* @author Andy Wilkinson
+ * @author Scott Frederick
*/
@ExtendWith(MavenBuildExtension.class)
public class AotTests {
@@ -102,6 +105,21 @@ public class AotTests {
});
}
+ @TestTemplate
+ void whenAotRunsWithJvmArgumentsSourcesAreGenerated(MavenBuild mavenBuild) {
+ mavenBuild.project("aot-jvm-arguments").goals("package").execute((project) -> {
+ Path aotDirectory = project.toPath().resolve("target/spring-aot/main");
+ assertThat(collectRelativePaths(aotDirectory.resolve("sources")))
+ .contains(Path.of("org", "test", "TestProfileConfiguration__BeanDefinitions.java"));
+ });
+ }
+
+ @TestTemplate
+ void whenAotRunsWithInvalidCompilerArgumentsCompileFails(MavenBuild mavenBuild) {
+ mavenBuild.project("aot-compiler-arguments").goals("package").executeAndFail(
+ (project) -> assertThat(buildLog(project)).contains("invalid flag: --invalid-compiler-arg"));
+ }
+
@TestTemplate
void whenAotRunsSourcesAreCompiled(MavenBuild mavenBuild) {
mavenBuild.project("aot").goals("package").execute((project) -> {
@@ -156,4 +174,8 @@ public class AotTests {
}
}
+ protected String buildLog(File project) {
+ return contentOf(new File(project, "target/build.log"));
+ }
+
}
diff --git a/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/intTest/projects/aot-compiler-arguments/pom.xml b/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/intTest/projects/aot-compiler-arguments/pom.xml
new file mode 100644
index 00000000000..6b0d97eab91
--- /dev/null
+++ b/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/intTest/projects/aot-compiler-arguments/pom.xml
@@ -0,0 +1,45 @@
+
+
+ 4.0.0
+ org.springframework.boot.maven.it
+ aot
+ 0.0.1.BUILD-SNAPSHOT
+
+ UTF-8
+ @java.version@
+ @java.version@
+
+
+
+
+ @project.groupId@
+ @project.artifactId@
+ @project.version@
+
+
+
+ process-aot
+
+
+ -verbose --invalid-compiler-arg
+
+
+
+
+
+
+
+
+ org.springframework.boot
+ spring-boot
+ @project.version@
+
+
+ jakarta.servlet
+ jakarta.servlet-api
+ @jakarta-servlet.version@
+ provided
+
+
+
diff --git a/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/intTest/projects/aot-compiler-arguments/src/main/java/org/test/SampleApplication.java b/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/intTest/projects/aot-compiler-arguments/src/main/java/org/test/SampleApplication.java
new file mode 100644
index 00000000000..d8ccd2df1c4
--- /dev/null
+++ b/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/intTest/projects/aot-compiler-arguments/src/main/java/org/test/SampleApplication.java
@@ -0,0 +1,30 @@
+/*
+ * Copyright 2012-2022 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
+ *
+ * https://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;
+
+import org.springframework.boot.SpringApplication;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.context.annotation.Import;
+
+@Configuration(proxyBeanMethods = false)
+public class SampleApplication {
+
+ public static void main(String[] args) {
+ SpringApplication.run(SampleApplication.class, args);
+ }
+
+}
diff --git a/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/intTest/projects/aot-jvm-arguments/pom.xml b/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/intTest/projects/aot-jvm-arguments/pom.xml
new file mode 100644
index 00000000000..64d042d210e
--- /dev/null
+++ b/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/intTest/projects/aot-jvm-arguments/pom.xml
@@ -0,0 +1,45 @@
+
+
+ 4.0.0
+ org.springframework.boot.maven.it
+ aot
+ 0.0.1.BUILD-SNAPSHOT
+
+ UTF-8
+ @java.version@
+ @java.version@
+
+
+
+
+ @project.groupId@
+ @project.artifactId@
+ @project.version@
+
+
+
+ process-aot
+
+
+ -Dspring.profiles.active=abc
+
+
+
+
+
+
+
+
+ org.springframework.boot
+ spring-boot
+ @project.version@
+
+
+ jakarta.servlet
+ jakarta.servlet-api
+ @jakarta-servlet.version@
+ provided
+
+
+
diff --git a/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/intTest/projects/aot-jvm-arguments/src/main/java/org/test/SampleApplication.java b/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/intTest/projects/aot-jvm-arguments/src/main/java/org/test/SampleApplication.java
new file mode 100644
index 00000000000..31a0749604e
--- /dev/null
+++ b/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/intTest/projects/aot-jvm-arguments/src/main/java/org/test/SampleApplication.java
@@ -0,0 +1,31 @@
+/*
+ * Copyright 2012-2022 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
+ *
+ * https://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;
+
+import org.springframework.boot.SpringApplication;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.context.annotation.Import;
+
+@Configuration(proxyBeanMethods = false)
+@Import(TestProfileConfiguration.class)
+public class SampleApplication {
+
+ public static void main(String[] args) {
+ SpringApplication.run(SampleApplication.class, args);
+ }
+
+}
diff --git a/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/intTest/projects/aot-jvm-arguments/src/main/java/org/test/TestProfileConfiguration.java b/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/intTest/projects/aot-jvm-arguments/src/main/java/org/test/TestProfileConfiguration.java
new file mode 100644
index 00000000000..acad93e303f
--- /dev/null
+++ b/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/intTest/projects/aot-jvm-arguments/src/main/java/org/test/TestProfileConfiguration.java
@@ -0,0 +1,32 @@
+/*
+ * Copyright 2012-2022 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
+ *
+ * https://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;
+
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.context.annotation.Profile;
+
+@Configuration(proxyBeanMethods = false)
+@Profile("abc")
+class TestProfileConfiguration {
+
+ @Bean
+ public String abc() {
+ return "abc";
+ }
+
+}
diff --git a/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/AbstractAotMojo.java b/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/AbstractAotMojo.java
index 8e1dd17aa35..95ac339482f 100644
--- a/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/AbstractAotMojo.java
+++ b/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/AbstractAotMojo.java
@@ -51,6 +51,7 @@ import org.springframework.boot.maven.CommandLineBuilder.ClasspathBuilder;
* Abstract base class for AOT processing MOJOs.
*
* @author Phillip Webb
+ * @author Scott Frederick
* @since 3.0.0
*/
public abstract class AbstractAotMojo extends AbstractDependencyFilterMojo {
@@ -86,6 +87,13 @@ public abstract class AbstractAotMojo extends AbstractDependencyFilterMojo {
@Parameter(property = "spring-boot.aot.jvmArguments")
private String jvmArguments;
+ /**
+ * Arguments that should be provided to the AOT compile process. On command line, make
+ * sure to wrap multiple values between quotes.
+ */
+ @Parameter(property = "spring-boot.aot.compilerArguments")
+ private String compilerArguments;
+
@Override
public void execute() throws MojoExecutionException, MojoFailureException {
if (this.skip) {
@@ -127,6 +135,7 @@ public abstract class AbstractAotMojo extends AbstractDependencyFilterMojo {
options.add(ClasspathBuilder.build(Arrays.asList(classPath)));
options.add("-d");
options.add(outputDirectory.toPath().toAbsolutePath().toString());
+ options.addAll(new RunArguments(this.compilerArguments).getArgs());
Iterable extends JavaFileObject> compilationUnits = fileManager.getJavaFileObjectsFromPaths(sourceFiles);
Errors errors = new Errors();
CompilationTask task = compiler.getTask(null, fileManager, errors, options, null, compilationUnits);
@@ -169,10 +178,12 @@ public abstract class AbstractAotMojo extends AbstractDependencyFilterMojo {
if (diagnostic.getKind() == Diagnostic.Kind.ERROR) {
this.message.append("\n");
this.message.append(diagnostic.getMessage(Locale.getDefault()));
- this.message.append(" ");
- this.message.append(diagnostic.getSource().getName());
- this.message.append(" ");
- this.message.append(diagnostic.getLineNumber()).append(":").append(diagnostic.getColumnNumber());
+ if (diagnostic.getSource() != null) {
+ this.message.append(" ");
+ this.message.append(diagnostic.getSource().getName());
+ this.message.append(" ");
+ this.message.append(diagnostic.getLineNumber()).append(":").append(diagnostic.getColumnNumber());
+ }
}
}