Skip to content

Commit 1c94f83

Browse files
committed
Copy AOT-generated classes
Closes spring-projectsgh-31245
1 parent 11cbb25 commit 1c94f83

File tree

1 file changed

+10
-8
lines changed
  • spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven

1 file changed

+10
-8
lines changed

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

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import java.nio.file.Path;
2424
import java.nio.file.StandardCopyOption;
2525
import java.util.ArrayList;
26+
import java.util.Collections;
2627
import java.util.List;
2728
import java.util.Locale;
2829
import java.util.Map;
@@ -82,7 +83,9 @@ protected void run(File workingDirectory, String startClassName, Map<String, Str
8283
try {
8384
generateAotAssets(workingDirectory, startClassName, environmentVariables);
8485
compileSourceFiles();
85-
copyNativeConfiguration(this.generatedResources.toPath());
86+
copyAll(this.generatedResources.toPath().resolve("META-INF/native-image"),
87+
this.classesDirectory.toPath().resolve("META-INF/native-image"));
88+
copyAll(this.generatedClasses.toPath(), this.classesDirectory.toPath());
8689
}
8790
catch (Exception ex) {
8891
throw new MojoExecutionException(ex.getMessage(), ex);
@@ -158,14 +161,13 @@ private void compileSourceFiles() throws IOException, MojoExecutionException {
158161
}
159162
}
160163

161-
private void copyNativeConfiguration(Path generatedResources) throws IOException {
162-
Path targetDirectory = this.classesDirectory.toPath().resolve("META-INF/native-image");
163-
Path sourceDirectory = generatedResources.resolve("META-INF/native-image");
164-
List<Path> files = Files.walk(sourceDirectory).filter(Files::isRegularFile).toList();
164+
private void copyAll(Path from, Path to) throws IOException {
165+
List<Path> files = (Files.exists(from)) ? Files.walk(from).filter(Files::isRegularFile).toList()
166+
: Collections.emptyList();
165167
for (Path file : files) {
166-
String relativeFileName = file.subpath(sourceDirectory.getNameCount(), file.getNameCount()).toString();
167-
getLog().debug("Copying '" + relativeFileName + "' to " + targetDirectory);
168-
Path target = targetDirectory.resolve(relativeFileName);
168+
String relativeFileName = file.subpath(from.getNameCount(), file.getNameCount()).toString();
169+
getLog().debug("Copying '" + relativeFileName + "' to " + to);
170+
Path target = to.resolve(relativeFileName);
169171
Files.createDirectories(target.getParent());
170172
Files.copy(file, target, StandardCopyOption.REPLACE_EXISTING);
171173
}

0 commit comments

Comments
 (0)