Skip to content

Commit

Permalink
Harmonize AOT goal/task names
Browse files Browse the repository at this point in the history
Closes gh-31918
  • Loading branch information
philwebb committed Aug 25, 2022
2 parents 973e23d + c0b3d36 commit ed42823
Show file tree
Hide file tree
Showing 15 changed files with 40 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -233,9 +233,9 @@ publishing.publications.withType(MavenPublication) {
delegate.artifactId('spring-boot-maven-plugin')
executions {
execution {
delegate.id('aot-generate')
delegate.id('process-aot')
goals {
delegate.goal('aot-generate')
delegate.goal('process-aot')
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ When Gradle's {application-plugin}[`application` plugin] is applied to a project
When the {nbt-gradle-plugin}[GraalVM Native Image plugin] is applied to a project, the Spring Boot plugin:

. Applies the `org.springframework.boot.aot` plugin that:
.. Registers a `GenerateAotSources` task named `generateAotSources` that will generate AOT-optimized source code for the application.
.. Configures the Java compilation and process resources tasks for the `aot` source set to depend upon `generateAotSources`.
.. Registers a `ProcessAot` task named `processAot` that will generate AOT-optimized source code for the application.
.. Configures the Java compilation and process resources tasks for the `aot` source set to depend upon `processAot`.
. Adds the output of the `aot` source set to the classpath of the `nativeCompile` task.
. Configures the GraalVM extension to disable Toolchain detection.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
import org.gradle.api.tasks.SourceSetContainer;
import org.gradle.api.tasks.TaskProvider;

import org.springframework.boot.gradle.tasks.aot.GenerateAotSources;
import org.springframework.boot.gradle.tasks.aot.ProcessAot;

/**
* Gradle plugin for Spring Boot AOT.
Expand All @@ -50,17 +50,17 @@ public class SpringBootAotPlugin implements Plugin<Project> {
public static final String AOT_SOURCE_SET_NAME = "aot";

/**
* Name of the default {@link GenerateAotSources} task.
* Name of the default {@link ProcessAot} task.
*/
public static final String GENERATE_AOT_SOURCES_TASK_NAME = "generateAotSources";
public static final String PROCESS_AOT_TASK_NAME = "processAot";

@Override
public void apply(Project project) {
PluginContainer plugins = project.getPlugins();
plugins.withType(JavaPlugin.class).all((javaPlugin) -> {
plugins.withType(SpringBootPlugin.class).all((bootPlugin) -> {
SourceSet aotSourceSet = configureAotSourceSet(project);
registerGenerateAotSourcesTask(project, aotSourceSet);
registerProcessAotTask(project, aotSourceSet);
});
});
}
Expand Down Expand Up @@ -97,11 +97,11 @@ private void configureJavaRuntimeUsageAttribute(Project project, AttributeContai
attributes.attribute(Usage.USAGE_ATTRIBUTE, javaRuntime);
}

private void registerGenerateAotSourcesTask(Project project, SourceSet aotSourceSet) {
private void registerProcessAotTask(Project project, SourceSet aotSourceSet) {
TaskProvider<ResolveMainClassName> resolveMainClassName = project.getTasks()
.named(SpringBootPlugin.RESOLVE_MAIN_CLASS_NAME_TASK_NAME, ResolveMainClassName.class);
TaskProvider<GenerateAotSources> generateAotSources = project.getTasks()
.register(GENERATE_AOT_SOURCES_TASK_NAME, GenerateAotSources.class, (task) -> {
TaskProvider<ProcessAot> processAot = project.getTasks().register(PROCESS_AOT_TASK_NAME, ProcessAot.class,
(task) -> {
Provider<Directory> generatedClasses = project.getLayout().getBuildDirectory()
.dir("generated/aotClasses");
aotSourceSet.getOutput().dir(generatedClasses);
Expand All @@ -114,9 +114,9 @@ private void registerGenerateAotSourcesTask(Project project, SourceSet aotSource
task.getArtifactId().set(project.provider(() -> project.getName()));
});
project.getTasks().named(aotSourceSet.getCompileJavaTaskName())
.configure((compileJava) -> compileJava.dependsOn(generateAotSources));
.configure((compileJava) -> compileJava.dependsOn(processAot));
project.getTasks().named(aotSourceSet.getProcessResourcesTaskName())
.configure((processResources) -> processResources.dependsOn(generateAotSources));
.configure((processResources) -> processResources.dependsOn(processAot));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@
import org.gradle.api.tasks.TaskAction;

/**
* Custom {@link JavaExec} task for generating sources ahead of time.
* Custom {@link JavaExec} task for processing code ahead-of-time.
*
* @author Andy Wilkinson
* @since 3.0.0
*/
@CacheableTask
public class GenerateAotSources extends JavaExec {
public class ProcessAot extends JavaExec {

private final Property<String> applicationClass;

Expand All @@ -48,7 +48,7 @@ public class GenerateAotSources extends JavaExec {

private final Property<String> artifactId;

public GenerateAotSources() {
public ProcessAot() {
this.applicationClass = getProject().getObjects().property(String.class);
this.sourcesDir = getProject().getObjects().directoryProperty();
this.resourcesDir = getProject().getObjects().directoryProperty();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,30 +39,30 @@ class SpringBootAotPluginIntegrationTests {
GradleBuild gradleBuild;

@TestTemplate
void noGenerateAotSourcesTaskWithoutAotPluginApplied() {
assertThat(this.gradleBuild.build("taskExists", "-PtaskName=generateAotSources").getOutput())
.contains("generateAotSources exists = false");
void noProcessAotTaskWithoutAotPluginApplied() {
assertThat(this.gradleBuild.build("taskExists", "-PtaskName=processAot").getOutput())
.contains("processAot exists = false");
}

@TestTemplate
void applyingAotPluginCreatesGenerateAotSourcesTask() {
assertThat(this.gradleBuild.build("taskExists", "-PtaskName=generateAotSources").getOutput())
.contains("generateAotSources exists = true");
void applyingAotPluginCreatesProcessAotTask() {
assertThat(this.gradleBuild.build("taskExists", "-PtaskName=processAot").getOutput())
.contains("processAot exists = true");
}

@TestTemplate
void generateAotSourcesHasLibraryResourcesOnItsClasspath() throws IOException {
void processAotHasLibraryResourcesOnItsClasspath() throws IOException {
File settings = new File(this.gradleBuild.getProjectDir(), "settings.gradle");
Files.write(settings.toPath(), List.of("include 'library'"));
File library = new File(this.gradleBuild.getProjectDir(), "library");
library.mkdirs();
Files.write(library.toPath().resolve("build.gradle"), List.of("plugins {", " id 'java-library'", "}"));
assertThat(this.gradleBuild.build("generateAotSourcesClasspath").getOutput()).contains("library.jar");
assertThat(this.gradleBuild.build("processAotClasspath").getOutput()).contains("library.jar");
}

@TestTemplate
void generateAotSourcesHasTransitiveRuntimeDependenciesOnItsClasspath() {
String output = this.gradleBuild.build("generateAotSourcesClasspath").getOutput();
void processAotHasTransitiveRuntimeDependenciesOnItsClasspath() {
String output = this.gradleBuild.build("processAotClasspath").getOutput();
assertThat(output).contains("org.jboss.logging" + File.separatorChar + "jboss-logging");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ dependencies {
implementation project(":library")
}

task('generateAotSourcesClasspath') {
task('processAotClasspath') {
doFirst {
tasks.findByName('generateAotSources').classpath.files.each { println it }
tasks.findByName('processAot').classpath.files.each { println it }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ dependencies {
implementation "org.hibernate.orm:hibernate-core:6.1.1.Final"
}

task('generateAotSourcesClasspath') {
task('processAotClasspath') {
doFirst {
tasks.findByName('generateAotSources').classpath.files.each { println it }
tasks.findByName('processAot').classpath.files.each { println it }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Based on your `@SpringBootApplication`-annotated main class, the AOT engine gene
Additional post-processing of the factory is possible using callbacks.
For instance, these are used to generate the necessary reflection configuration that GraalVM needs to initialize the context in a native image.

To configure your application to use this feature, add an execution for the `aot-generate` goal, as shown in the following example:
To configure your application to use this feature, add an execution for the `process-aot` goal, as shown in the following example:

[source,xml,indent=0,subs="verbatim,attributes",tabsize=4]
----
Expand All @@ -16,7 +16,7 @@ include::../maven/aot/pom.xml[tags=aot]
As the `BeanFactory` is fully prepared at build-time, conditions are also evaluated.
This has an important difference compared to what a regular Spring Boot application does at runtime.
For instance, if you want to opt-in or opt-out for certain features, you need to configure the environment used at build time to do so.
The `aot-generate` goal shares a number of properties with the <<run,run goal>> for that reason.
The `process-aot` goal shares a number of properties with the <<run,run goal>> for that reason.


include::goals/aot-generate.adoc[leveloffset=+1]
include::goals/process-aot.adoc[leveloffset=+1]
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<id>aot-generate</id>
<id>process-aot</id>
<goals>
<goal>aot-generate</goal>
<goal>process-aot</goal>
</goals>
</execution>
</executions>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<executions>
<execution>
<goals>
<goal>aot-generate</goal>
<goal>process-aot</goal>
</goals>
</execution>
</executions>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<executions>
<execution>
<goals>
<goal>aot-generate</goal>
<goal>process-aot</goal>
</goals>
</execution>
</executions>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<executions>
<execution>
<goals>
<goal>aot-generate</goal>
<goal>process-aot</goal>
</goals>
</execution>
</executions>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,10 @@
* @author Andy Wilkinson
* @since 3.0.0
*/
@Mojo(name = "aot-generate", defaultPhase = LifecyclePhase.PREPARE_PACKAGE, threadSafe = true,
@Mojo(name = "process-aot", defaultPhase = LifecyclePhase.PREPARE_PACKAGE, threadSafe = true,
requiresDependencyResolution = ResolutionScope.COMPILE_PLUS_RUNTIME,
requiresDependencyCollection = ResolutionScope.COMPILE_PLUS_RUNTIME)
public class AotGenerateMojo extends AbstractDependencyFilterMojo {
public class ProcessAotMojo extends AbstractDependencyFilterMojo {

private static final String AOT_PROCESSOR_CLASS_NAME = "org.springframework.boot.AotProcessor";

Expand Down

0 comments on commit ed42823

Please sign in to comment.