Make transitive runtime dependencies available to AOT processing
Closes gh-31970
This commit is contained in:
@@ -24,6 +24,7 @@ import org.gradle.api.artifacts.Configuration;
|
||||
import org.gradle.api.artifacts.ConfigurationContainer;
|
||||
import org.gradle.api.attributes.AttributeContainer;
|
||||
import org.gradle.api.attributes.LibraryElements;
|
||||
import org.gradle.api.attributes.Usage;
|
||||
import org.gradle.api.file.Directory;
|
||||
import org.gradle.api.plugins.JavaPlugin;
|
||||
import org.gradle.api.plugins.JavaPluginExtension;
|
||||
@@ -77,16 +78,23 @@ public class SpringBootAotPlugin implements Plugin<Project> {
|
||||
Configuration aotImplementation = configurations.getByName(aot.getImplementationConfigurationName());
|
||||
aotImplementation.extendsFrom(configurations.getByName(main.getImplementationConfigurationName()));
|
||||
aotImplementation.extendsFrom(configurations.getByName(main.getRuntimeOnlyConfigurationName()));
|
||||
configurations.getByName(aot.getCompileClasspathConfigurationName())
|
||||
.attributes((attributes) -> addLibraryElementsAttribute(project, attributes));
|
||||
configurations.getByName(aot.getCompileClasspathConfigurationName()).attributes((attributes) -> {
|
||||
configureClassesAndResourcesLibraryElementsAttribute(project, attributes);
|
||||
configureJavaRuntimeUsageAttribute(project, attributes);
|
||||
});
|
||||
});
|
||||
return aotSourceSet;
|
||||
}
|
||||
|
||||
private AttributeContainer addLibraryElementsAttribute(Project project, AttributeContainer attributes) {
|
||||
LibraryElements libraryElements = project.getObjects().named(LibraryElements.class,
|
||||
private void configureClassesAndResourcesLibraryElementsAttribute(Project project, AttributeContainer attributes) {
|
||||
LibraryElements classesAndResources = project.getObjects().named(LibraryElements.class,
|
||||
LibraryElements.CLASSES_AND_RESOURCES);
|
||||
return attributes.attribute(LibraryElements.LIBRARY_ELEMENTS_ATTRIBUTE, libraryElements);
|
||||
attributes.attribute(LibraryElements.LIBRARY_ELEMENTS_ATTRIBUTE, classesAndResources);
|
||||
}
|
||||
|
||||
private void configureJavaRuntimeUsageAttribute(Project project, AttributeContainer attributes) {
|
||||
Usage javaRuntime = project.getObjects().named(Usage.class, Usage.JAVA_RUNTIME);
|
||||
attributes.attribute(Usage.USAGE_ATTRIBUTE, javaRuntime);
|
||||
}
|
||||
|
||||
private void registerGenerateAotSourcesTask(Project project, SourceSet aotSourceSet) {
|
||||
|
||||
@@ -60,4 +60,10 @@ class SpringBootAotPluginIntegrationTests {
|
||||
assertThat(this.gradleBuild.build("generateAotSourcesClasspath").getOutput()).contains("library.jar");
|
||||
}
|
||||
|
||||
@TestTemplate
|
||||
void generateAotSourcesHasTransitiveRuntimeDependenciesOnItsClasspath() {
|
||||
String output = this.gradleBuild.build("generateAotSourcesClasspath").getOutput();
|
||||
assertThat(output).contains("org.jboss.logging/jboss-logging");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
plugins {
|
||||
id 'org.springframework.boot'
|
||||
id 'org.springframework.boot.aot'
|
||||
id 'java'
|
||||
}
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation "org.hibernate.orm:hibernate-core:6.1.1.Final"
|
||||
}
|
||||
|
||||
task('generateAotSourcesClasspath') {
|
||||
doFirst {
|
||||
tasks.findByName('generateAotSources').classpath.files.each { println it }
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user