Add native image manifest entry
A manifest entry `Spring-Boot-Native-Processed: true` is added to the jar manifest by the Maven or Gradle plugin when the jar has been built for use in a native image. With the Gradle plugin, this is done in reaction to the GraalVM Native Image Plugin being applied to the project. With the Maven plugin, this is done when the `native` profile is applied to the build.
This commit is contained in:
@@ -25,6 +25,7 @@ import java.util.Enumeration;
|
||||
import java.util.List;
|
||||
import java.util.jar.JarEntry;
|
||||
import java.util.jar.JarFile;
|
||||
import java.util.jar.Manifest;
|
||||
|
||||
import org.gradle.testkit.runner.BuildResult;
|
||||
import org.gradle.testkit.runner.TaskOutcome;
|
||||
@@ -115,6 +116,17 @@ class NativeImagePluginActionIntegrationTests {
|
||||
projectPath("build/resources/aotTest"), projectPath("build/generated/aotTestClasses"));
|
||||
}
|
||||
|
||||
@TestTemplate
|
||||
void nativeEntryIsAddedToManifest() throws IOException {
|
||||
writeDummySpringApplicationAotProcessorMainClass();
|
||||
BuildResult result = this.gradleBuild.build("bootJar");
|
||||
assertThat(result.task(":bootJar").getOutcome()).isEqualTo(TaskOutcome.SUCCESS);
|
||||
File buildLibs = new File(this.gradleBuild.getProjectDir(), "build/libs");
|
||||
JarFile jarFile = new JarFile(new File(buildLibs, this.gradleBuild.getProjectDir().getName() + ".jar"));
|
||||
Manifest manifest = jarFile.getManifest();
|
||||
assertThat(manifest.getMainAttributes().getValue("Spring-Boot-Native-Processed")).isEqualTo("true");
|
||||
}
|
||||
|
||||
private String projectPath(String path) {
|
||||
try {
|
||||
return new File(this.gradleBuild.getProjectDir(), path).getCanonicalPath();
|
||||
|
||||
Reference in New Issue
Block a user