Skip to content
This repository has been archived by the owner on Feb 23, 2023. It is now read-only.

Commit

Permalink
Generate runtime sources in a distinct directory
Browse files Browse the repository at this point in the history
Directories like target/generated-sources/ with Maven and
build/generated/sources with Gradle are automatically imported
by IDEs like IntelliJ IDEA and are assuming a compile classpath.

The code generated by Spring AOT is generated with the runtime
classpath, so this commit moves the generation to a dedicated
directory not imported automatically.

Maven does not differentiate compile and runtime test classpaths
but experimentation in IDEA has shown bogus behavior in debugger
when target/generated-test-sources is kept to this commit
change it to target/generated-runtime-test-sources.

Debugging those generated files now require adding them explicitly
to the classpath but our assumption is that's not a very common
need.

Closes gh-1093
  • Loading branch information
sdeleuze committed Jan 18, 2022
1 parent 4e6b095 commit a6e807d
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion scripts/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ done
if [ -f pom.xml ]; then
EXECUTABLE_DIR=target
JAR_DIR=target
GENERATED_DIR=target/generated-sources/spring-aot/src/main/resources
GENERATED_DIR=target/generated-runtime-sources/spring-aot/src/main/resources
REPORT_DIR=target/native
else
EXECUTABLE_DIR=build/native/nativeCompile
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ private Path createGeneratedSourcesFolder(Project project) {
}

private SourceSet createAotMainSourceSet(SourceSetContainer sourceSets, ConfigurationContainer configurations, Path generatedFilesPath) {
File aotSourcesDirectory = generatedFilesPath.resolve("sources").resolve(AOT_MAIN_SOURCE_SET_NAME).toFile();
File aotSourcesDirectory = generatedFilesPath.resolve("runtimeSources").resolve(AOT_MAIN_SOURCE_SET_NAME).toFile();
File aotResourcesDirectory = generatedFilesPath.resolve("resources").resolve(AOT_MAIN_SOURCE_SET_NAME).toFile();
SourceSet aotMainSourceSet = sourceSets.create(AOT_MAIN_SOURCE_SET_NAME);
FileCollection aotCompileClasspath = sourceSets.findByName(SourceSet.MAIN_SOURCE_SET_NAME).getRuntimeClasspath()
Expand Down Expand Up @@ -272,7 +272,7 @@ private Configuration createAotGenerationConfiguration(Project project) {
}

private SourceSet createAotTestSourceSet(SourceSetContainer sourceSets, ConfigurationContainer configurations, Path generatedFilesPath) {
File aotTestSourcesDirectory = generatedFilesPath.resolve("sources").resolve(AOT_TEST_SOURCE_SET_NAME).toFile();
File aotTestSourcesDirectory = generatedFilesPath.resolve("runtimeSources").resolve(AOT_TEST_SOURCE_SET_NAME).toFile();
File aotTestResourcesDirectory = generatedFilesPath.resolve("resources").resolve(AOT_TEST_SOURCE_SET_NAME).toFile();
SourceSet aotTestSourceSet = sourceSets.create(AOT_TEST_SOURCE_SET_NAME);
FileCollection aotTestCompileClasspath = sourceSets.findByName(SourceSet.TEST_SOURCE_SET_NAME).getRuntimeClasspath()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ void pluginRegistersAotSourceSet() {
assertThat(aotSourceSet.getJava().getSourceDirectories())
.hasSize(1)
.allMatch(file -> file.getAbsolutePath().endsWith(File.separator + "build" + File.separator + "generated"
+ File.separator + "sources" + File.separator + SpringAotGradlePlugin.AOT_MAIN_SOURCE_SET_NAME));
+ File.separator + "runtimeSources" + File.separator + SpringAotGradlePlugin.AOT_MAIN_SOURCE_SET_NAME));
assertThat(aotSourceSet.getResources().getSourceDirectories())
.hasSize(1)
.allMatch(file -> file.getAbsolutePath().endsWith(File.separator + "build" + File.separator + "generated"
Expand Down Expand Up @@ -98,7 +98,7 @@ void pluginRegistersAotTestSourceSet() {
assertThat(aotTestSourceSet.getJava().getSourceDirectories())
.hasSize(1)
.allMatch(file -> file.getAbsolutePath().endsWith(File.separator + "build" + File.separator + "generated"
+ File.separator + "sources" + File.separator + SpringAotGradlePlugin.AOT_TEST_SOURCE_SET_NAME));
+ File.separator + "runtimeSources" + File.separator + SpringAotGradlePlugin.AOT_TEST_SOURCE_SET_NAME));
assertThat(aotTestSourceSet.getResources().getSourceDirectories())
.hasSize(1)
.allMatch(file -> file.getAbsolutePath().endsWith(File.separator + "build" + File.separator + "generated"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public class GenerateMojo extends AbstractBootstrapMojo {
/**
* Location of generated source files created by Spring AOT to bootstrap the application.
*/
@Parameter(defaultValue = "${project.build.directory}/generated-sources/spring-aot/")
@Parameter(defaultValue = "${project.build.directory}/generated-runtime-sources/spring-aot/")
private File generatedSourcesDirectory;


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public class TestGenerateMojo extends AbstractBootstrapMojo {
/**
* Location of generated source files created by Spring AOT to bootstrap the test context.
*/
@Parameter(defaultValue = "${project.build.directory}/generated-test-sources/spring-aot/")
@Parameter(defaultValue = "${project.build.directory}/generated-runtime-test-sources/spring-aot/")
private File generatedTestSourcesDirectory;

@Override
Expand Down
4 changes: 2 additions & 2 deletions spring-native-docs/src/main/asciidoc/build-setup.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ The plugin should be declared in your `pom.xml` file:

Maven goals `spring-aot:generate` (`prepare-package` phase) and `spring-aot:test-generate` (`process-test-classes` phase) are automatically invoked in the Maven lifecycle when using the `mvn verify` or `mvn package` commands.
The `spring-aot:*` goals are not meant to be called directly since they rely on other parts of the lifecycle.
Sources are generated in `target/generated-sources/spring-aot/` and test sources in `target/generated-test-sources/spring-aot/`.
Sources are generated in `target/generated-runtime-sources/spring-aot/` and test sources in `target/generated-runtime-test-sources/spring-aot/`.

Configuration can be performed if needed within the `<configuration>` element, for example to remove SpEL support at build-time if your application does not use it in order to optimize the footprint:

Expand Down Expand Up @@ -106,7 +106,7 @@ The plugin creates two `SourceSets` for testing and running the application: "ao
The resulting classes and resources are automatically added to the runtime classpath of the application when running the `test`, `bootRun` and `bootJar` tasks.
You can also call directly `generateAot` and `generateTestAot` tasks to perform only the generation.

Sources are generated in `build/generated/sources/aot/`, `build/generated/resources/aot/` and test sources in `build/generated/sources/aotTest/`, `build/generated/resources/aotTest/`.
Sources are generated in `build/generated/runtimeSources/aotMain/`, `build/generated/resources/aotMain/` and test sources in `build/generated/runtimeSources/aotTest/`, `build/generated/resources/aotTest/`.

Configuration can be performed if needed using the `springAot` DSL extension, for example to remove SpEL support at build-time if your application does not use it in order to optimize the footprint:

Expand Down

0 comments on commit a6e807d

Please sign in to comment.