mike-neck / graalvm-native-image-plugin

A Gradle plugin which creates a native executable via GraalVM's native-image. This is a thin wrapper of the native-image command.
Apache License 2.0
89 stars 14 forks source link

Spring Boot layout support #142

Closed sergey-morenets closed 3 years ago

sergey-morenets commented 3 years ago

Hi

Does your plugin support Spring Boot jar layout ? In this layout there're special folder for classes: /BOOT-INF/classes and libraries: /BOOT-INF/lib inside jar file.

If I try to configure your plugin:

plugins {
     id 'org.springframework.boot' version '2.4.4' apply true
     id 'org.springframework.experimental.aot' version '0.9.1'
     id "org.mikeneck.graalvm-native-image" version "1.3.0"     
}

nativeImage {
  graalVmHome = System.getProperty('java.home')
  mainClass = 'demo.MyApplication'
  executableName = 'demo'
  outputDirectory = file("$buildDir")
  arguments {
    add '--no-fallback'
    add '--verbose'
   }
}

and run AOT compilation: gradle assemble nativeImage I always get an error:

Error: Main entry point class 'demo.MyApplication' not found.
Error: Image build request failed with exit status 1
com.oracle.svm.driver.NativeImage$NativeImageError: Image build request failed with exit status 1
        at com.oracle.svm.driver.NativeImage.showError(NativeImage.java:1676)
        at com.oracle.svm.driver.NativeImage.build(NativeImage.java:1426)
        at com.oracle.svm.driver.NativeImage.performBuild(NativeImage.java:1387)
        at com.oracle.svm.driver.NativeImage.main(NativeImage.java:1374)
        at com.oracle.svm.driver.NativeImage$JDK9Plus.main(NativeImage.java:1858)
mike-neck commented 3 years ago

This plugin does not support spring-boot.

I'll recommend you to use spring-native experimental project.(Please note that the library is still in beta phase.)

sergey-morenets commented 3 years ago

Thank you, @mike-neck spring-native project (together with Spring AOT plugin) generates configuration files required for AOT. However Spring Boot Maven plugin doesn't support creating native image (only Docker Native image).

mike-neck commented 3 years ago

You may be able to generate native image of spring-boot application, by creating another new jar task (As you may know that the default jar task is disabled by spring boot plugin), and using the product of the new jar task as an input of nativeImage task(I'm sorry I have not tried this workaround yet).

task anotherJar(type: Jar) {
  from sourceSets.main.output
}

nativeImage {
  classpath = anotherJar
  withConfigFiles {
    // add configuration files here
  }
  // other configurations
}
sergey-morenets commented 3 years ago

@mike-neck

Thank you for suggestion. Creating native image is rather common task so I would wait for support in new versions of the official Spring Boot plugin.

mike-neck commented 3 years ago

There is an issue(#128) for supporting spring-boot feature.