Include library resources on classpath of AOT source generation

Closes gh-31803
pull/31828/head
Andy Wilkinson 2 years ago
parent c31ad5f175
commit 6da8c88b2b

@ -22,6 +22,7 @@ import org.gradle.api.Plugin;
import org.gradle.api.Project;
import org.gradle.api.artifacts.Configuration;
import org.gradle.api.artifacts.ConfigurationContainer;
import org.gradle.api.attributes.LibraryElements;
import org.gradle.api.file.Directory;
import org.gradle.api.plugins.JavaPlugin;
import org.gradle.api.plugins.JavaPluginExtension;
@ -75,6 +76,9 @@ 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) -> attributes.attribute(LibraryElements.LIBRARY_ELEMENTS_ATTRIBUTE,
project.getObjects().named(LibraryElements.class, LibraryElements.CLASSES_AND_RESOURCES)));
});
return aotSourceSet;
}

@ -16,6 +16,11 @@
package org.springframework.boot.gradle.plugin;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.util.List;
import org.junit.jupiter.api.TestTemplate;
import org.springframework.boot.gradle.junit.GradleCompatibility;
@ -45,4 +50,14 @@ class SpringBootAotPluginIntegrationTests {
.contains("generateAotSources exists = true");
}
@TestTemplate
void generateAotSourcesHasLibraryResourcesOnItsClasspath() 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");
}
}

@ -0,0 +1,15 @@
plugins {
id 'org.springframework.boot'
id 'org.springframework.boot.aot'
id 'java'
}
dependencies {
implementation project(":library")
}
task('generateAotSourcesClasspath') {
doFirst {
tasks.findByName('generateAotSources').classpath.files.each { println it }
}
}
Loading…
Cancel
Save