paketo-buildpacks / native-image

A Cloud Native Buildpack that creates native images from Java applications
Apache License 2.0
50 stars 9 forks source link

Support native executables as input #192

Open scottfrederick opened 1 year ago

scottfrederick commented 1 year ago

Describe the Enhancement

When buildpacks are building a project from source, it is possible for the project to include the Maven or Gradle Native Build Tools plugin and configure the command line for the Maven (mvn -Pnative package) or Gradle (gradle nativeCompile) build to generate a native executable instead of a jar or war archive. The native-image buildpack currently fails in this scenario, as it expects its input to be a jar or war archive. It would be nice if the native-image buildpack would detect this scenario and skip the invocation of the native-image tool.

Motivation

Building a native executable directly from the build system might not be as common as building an archive for input to buildpacks, but advances in the NBT build plugins as well as build plugins from frameworks like Spring Boot are making this easier to do. When customization of the native-image command is required, it might be easier for users to configure this customization in a Maven pom.xml or Gradle build.gradle file than by providing BP_NATIVE_IMAGE_BUILD_ARGUMENTS or BP_NATIVE_IMAGE_BUILD_ARGUMENTS_FILE environment variables to the buildpack platform.

dmikusa commented 1 year ago

Sounds totally reasonable. There might be some issues to work out around SBOM. The native-image buildpack generates the SBOM entry for the runtime image, so we'd have to figure out how to make that happen still. You'd also still need something to set process types.

I think the spring-boot buildpack might also need to adjust itself. It does have some logic specific to fetching the classpath for a Boot app that is compiled to native-image. That might break, depending on what changes.