GithubHelp home page GithubHelp logo

paketo-buildpacks / native-image Goto Github PK

View Code? Open in Web Editor NEW
47.0 8.0 9.0 491 KB

A Cloud Native Buildpack that creates native images from Java applications

License: Apache License 2.0

Go 99.21% Shell 0.79%
cnb spring-boot native-image jvm-applications java hacktoberfest

native-image's Introduction

gcr.io/paketo-buildpacks/native-image

The Paketo Buildpack for Native Image is a Cloud Native Buildpack that uses the GraalVM Native Image builder (native-image) to compile a standalone executable from an executable JAR.

Most users should not use this component buildpack directly and should instead use the Paketo Java Native Image, which provides the full set of buildpacks required to build a native image application.

Behavior

This buildpack will participate if one the following conditions are met:

  • $BP_NATIVE_IMAGE is set.
  • An upstream buildpack requests native-image-application in the build plan.
  • An upstream buildpack provides native-processed in the build plan.

The buildpack will do the following:

  • Requests that the Native Image builder be installed by requiring native-image-builder in the build plan.
  • If $BP_BINARY_COMPRESSION_METHOD is set to upx, requests that UPX be installed by requiring upx in the buildplan.
  • Uses native-image a to build a GraalVM native image and removes existing bytecode. Defaults to building the /workspace as an exploded JAR. If $BP_NATIVE_IMAGE_BUILT_ARTIFACT is set, it will build from the specified JAR file.
  • Uses $BP_BINARY_COMPRESSION_METHOD if set to upx or gzexe to compress the native image.

Configuration

Environment Variable Description
$BP_NATIVE_IMAGE Whether to build a native image from the application. Defaults to false.
$BP_NATIVE_IMAGE_BUILD_ARGUMENTS Arguments to pass to directly to the native-image command. These arguments must be valid and correctly formed or the native-image command will fail.
$BP_NATIVE_IMAGE_BUILD_ARGUMENTS_FILE A file containing arguments to pass to directly to the native-image command. The file must exist and the contents must be valid and correctly formed or the native-image command will fail. The file must follow the @argument file format as specified by Java. An argument file can be space-separated, EOL-separated, or a mix of both. We suggest sticking with one or the other, mixed separator support is best-effort only.
$BP_BINARY_COMPRESSION_METHOD Compression mechanism used to reduce binary size. Options: none (default), upx or gzexe
$BP_NATIVE_IMAGE_BUILT_ARTIFACT Configure the built application artifact explicitly. This is required if building a native image from a JAR file

Compression Caveats

  1. Using gzexe if you intend to run your application on a Paketo Tiny image is not currently supported. The gzexe utility will compress your executable into what is a shell script, which executes and extracts the actual binary to a temp location. This process requires /bin/sh and that is not in the Tiny images. If you try using gzexe with a Tiny stack, it'll build OK but fail to run saying a file is missing.

  2. Using upx will create a compressed executable that fails to run on M1 Macs. There is at the time of writing a bug in the emulation layer used by Docker on M1 Macs that is triggered when you try to run amd64 executable that has been compressed using upx. This is a known issue and will hopefully be patched in a future release.

License

This buildpack is released under version 2.0 of the Apache License.

native-image's People

Contributors

anthonydahanne avatar dependabot[bot] avatar dmikusa avatar ekcasey avatar nebhale avatar paketo-bot avatar pivotal-david-osullivan avatar twoseat avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

native-image's Issues

Spring Boot Native Image Build has been failed

Expected Behavior

Originally, bootBuildImage task should run normally.

Current Behavior

It still has been failed.

Test Environment:

  • macOS (Silicon)
  • Spring Boot 3.1.5

Logs are below:

> Running creator
    [creator]     ===> ANALYZING
    [creator]     Image with name "docker.io/library/demo:0.0.1-SNAPSHOT" not found
    [creator]     ===> DETECTING
    [creator]     6 of 15 buildpacks participating
    [creator]     paketo-buildpacks/ca-certificates   3.6.3
    [creator]     paketo-buildpacks/bellsoft-liberica 10.2.6
    [creator]     paketo-buildpacks/syft              1.32.1
    [creator]     paketo-buildpacks/executable-jar    6.7.4
    [creator]     paketo-buildpacks/spring-boot       5.26.1
    [creator]     paketo-buildpacks/native-image      5.12.1
    [creator]     ===> RESTORING
    [creator]     ===> BUILDING
    [creator]     
    [creator]     Paketo Buildpack for CA Certificates 3.6.3
    [creator]       https://github.com/paketo-buildpacks/ca-certificates
    [creator]       Launch Helper: Contributing to layer
    [creator]         Creating /layers/paketo-buildpacks_ca-certificates/helper/exec.d/ca-certificates-helper
    [creator]     
    [creator]     Paketo Buildpack for BellSoft Liberica 10.2.6
    [creator]       https://github.com/paketo-buildpacks/bellsoft-liberica
    [creator]       Build Configuration:
    [creator]         $BP_JVM_JLINK_ARGS           --no-man-pages --no-header-files --strip-debug --compress=1  configure custom link arguments (--output must be omitted)
    [creator]         $BP_JVM_JLINK_ENABLED        false                                                        enables running jlink tool to generate custom JRE
    [creator]         $BP_JVM_TYPE                 JRE                                                          the JVM type - JDK or JRE
    [creator]         $BP_JVM_VERSION              17                                                           the Java version
    [creator]       Launch Configuration:
    [creator]         $BPL_DEBUG_ENABLED           false                                                        enables Java remote debugging support
    [creator]         $BPL_DEBUG_PORT              8000                                                         configure the remote debugging port
    [creator]         $BPL_DEBUG_SUSPEND           false                                                        configure whether to suspend execution until a debugger has attached
    [creator]         $BPL_HEAP_DUMP_PATH                                                                       write heap dumps on error to this path
    [creator]         $BPL_JAVA_NMT_ENABLED        true                                                         enables Java Native Memory Tracking (NMT)
    [creator]         $BPL_JAVA_NMT_LEVEL          summary                                                      configure level of NMT, summary or detail
    [creator]         $BPL_JFR_ARGS                                                                             configure custom Java Flight Recording (JFR) arguments
    [creator]         $BPL_JFR_ENABLED             false                                                        enables Java Flight Recording (JFR)
    [creator]         $BPL_JMX_ENABLED             false                                                        enables Java Management Extensions (JMX)
    [creator]         $BPL_JMX_PORT                5000                                                         configure the JMX port
    [creator]         $BPL_JVM_HEAD_ROOM           0                                                            the headroom in memory calculation
    [creator]         $BPL_JVM_LOADED_CLASS_COUNT  35% of classes                                               the number of loaded classes in memory calculation
    [creator]         $BPL_JVM_THREAD_COUNT        250                                                          the number of threads in memory calculation
    [creator]         $JAVA_TOOL_OPTIONS                                                                        the JVM launch flags
    [creator]         Using Java version 17 extracted from MANIFEST.MF
    [creator]       BellSoft Liberica NIK 17.0.7: Contributing to layer
    [creator]         Downloading from https://download.bell-sw.com/vm/23.0.0/bellsoft-liberica-vm-core-openjdk17.0.7+7-23.0.0+1-linux-amd64.tar.gz
    [creator]         Verifying checksum
    [creator]         Expanding to /layers/paketo-buildpacks_bellsoft-liberica/native-image-svm
    [creator]         Adding 137 container CA certificates to JVM truststore
    [creator]         Writing env.build/JAVA_HOME.override
    [creator]         Writing env.build/JDK_HOME.override
    [creator]     
    [creator]     Paketo Buildpack for Syft 1.32.1
    [creator]       https://github.com/paketo-buildpacks/syft
    [creator]         Downloading from https://github.com/anchore/syft/releases/download/v0.84.0/syft_0.84.0_linux_amd64.tar.gz
    [creator]         Verifying checksum
    [creator]         Writing env.build/SYFT_CHECK_FOR_APP_UPDATE.default
    [creator]     
    [creator]     Paketo Buildpack for Executable JAR 6.7.4
    [creator]       https://github.com/paketo-buildpacks/executable-jar
    [creator]       Class Path: Contributing to layer
    [creator]         Writing env/CLASSPATH.delim
    [creator]         Writing env/CLASSPATH.prepend
    [creator]       Process types:
    [creator]         executable-jar: java org.springframework.boot.loader.JarLauncher (direct)
    [creator]         task:           java org.springframework.boot.loader.JarLauncher (direct)
    [creator]         web:            java org.springframework.boot.loader.JarLauncher (direct)
    [creator]     
    [creator]     Paketo Buildpack for Spring Boot 5.26.1
    [creator]       https://github.com/paketo-buildpacks/spring-boot
    [creator]       Build Configuration:
    [creator]         $BP_SPRING_CLOUD_BINDINGS_DISABLED   false  whether to contribute Spring Boot cloud bindings support
    [creator]       Launch Configuration:
    [creator]         $BPL_SPRING_CLOUD_BINDINGS_DISABLED  false  whether to auto-configure Spring Boot environment properties from bindings
    [creator]         $BPL_SPRING_CLOUD_BINDINGS_ENABLED   true   Deprecated - whether to auto-configure Spring Boot environment properties from bindings
    [creator]       Class Path: Contributing to layer
    [creator]         Writing env.build/CLASSPATH.append
    [creator]         Writing env.build/CLASSPATH.delim
    [creator]       Image labels:
    [creator]         org.opencontainers.image.title
    [creator]         org.opencontainers.image.version
    [creator]         org.springframework.boot.version
    [creator]     Warning: BOM table is deprecated in this buildpack api version, though it remains supported for backwards compatibility. Buildpack authors should write BOM information to <layer>.sbom.<ext>, launch.sbom.<ext>, or build.sbom.<ext>.
    [creator]     
    [creator]     Paketo Buildpack for Native Image 5.12.1
    [creator]       https://github.com/paketo-buildpacks/native-image
    [creator]       Build Configuration:
    [creator]         $BP_BINARY_COMPRESSION_METHOD                Compression mechanism used to reduce binary size. Options: `none` (default), `upx` or `gzexe`
    [creator]         $BP_NATIVE_IMAGE                       true  enable native image build
    [creator]         $BP_NATIVE_IMAGE_BUILD_ARGUMENTS             arguments to pass to the native-image command
    [creator]         $BP_NATIVE_IMAGE_BUILD_ARGUMENTS_FILE        a file with arguments to pass to the native-image command
    [creator]         $BP_NATIVE_IMAGE_BUILT_ARTIFACT              the built application artifact explicitly, required if building from a JAR
    [creator]       Native Image: Contributing to layer
    [creator]         Executing native-image --no-fallback -H:+StaticExecutableWithDynamicLibC -H:Name=/layers/paketo-buildpacks_native-image/native-image/com.example.demo.DemoApplication -cp /workspace:/workspace/BOOT-INF/classes:/workspace/BOOT-INF/lib/spring-cloud-starter-netflix-eureka-server-4.0.3.jar:/workspace/BOOT-INF/lib/spring-cloud-starter-loadbalancer-4.0.4.jar:/workspace/BOOT-INF/lib/spring-cloud-starter-4.0.4.jar:/workspace/BOOT-INF/lib/spring-cloud-netflix-eureka-server-4.0.3.jar:/workspace/BOOT-INF/lib/spring-boot-actuator-autoconfigure-3.1.5.jar:/workspace/BOOT-INF/lib/spring-boot-autoconfigure-3.1.5.jar:/workspace/BOOT-INF/lib/spring-boot-actuator-3.1.5.jar:/workspace/BOOT-INF/lib/spring-boot-3.1.5.jar:/workspace/BOOT-INF/lib/jaxb-runtime-4.0.3.jar:/workspace/BOOT-INF/lib/spring-bridge-3.0.3.jar:/workspace/BOOT-INF/lib/spring-webmvc-6.0.13.jar:/workspace/BOOT-INF/lib/spring-context-support-6.0.13.jar:/workspace/BOOT-INF/lib/spring-context-6.0.13.jar:/workspace/BOOT-INF/lib/spring-aop-6.0.13.jar:/workspace/BOOT-INF/lib/spring-web-6.0.13.jar:/workspace/BOOT-INF/lib/spring-beans-6.0.13.jar:/workspace/BOOT-INF/lib/spring-expression-6.0.13.jar:/workspace/BOOT-INF/lib/spring-core-6.0.13.jar:/workspace/BOOT-INF/lib/spring-cloud-loadbalancer-4.0.4.jar:/workspace/BOOT-INF/lib/spring-cloud-context-4.0.4.jar:/workspace/BOOT-INF/lib/spring-cloud-commons-4.0.4.jar:/workspace/BOOT-INF/lib/spring-security-rsa-1.0.12.RELEASE.jar:/workspace/BOOT-INF/lib/spring-cloud-netflix-eureka-client-4.0.3.jar:/workspace/BOOT-INF/lib/eureka-core-jersey3-2.0.1.jar:/workspace/BOOT-INF/lib/eureka-client-jersey3-2.0.1.jar:/workspace/BOOT-INF/lib/jersey-container-servlet-3.1.3.jar:/workspace/BOOT-INF/lib/jersey-container-servlet-core-3.1.3.jar:/workspace/BOOT-INF/lib/jersey-server-3.1.3.jar:/workspace/BOOT-INF/lib/jersey-apache-connector-3.1.3.jar:/workspace/BOOT-INF/lib/jersey-client-3.1.3.jar:/workspace/BOOT-INF/lib/jersey-hk2-3.1.3.jar:/workspace/BOOT-INF/lib/eureka-core-2.0.1.jar:/workspace/BOOT-INF/lib/eureka-client-2.0.1.jar:/workspace/BOOT-INF/lib/jersey-common-3.1.3.jar:/workspace/BOOT-INF/lib/hk2-locator-3.0.4.jar:/workspace/BOOT-INF/lib/hk2-api-3.0.4.jar:/workspace/BOOT-INF/lib/hk2-utils-3.0.4.jar:/workspace/BOOT-INF/lib/jakarta.inject-api-2.0.1.jar:/workspace/BOOT-INF/lib/jackson-datatype-jdk8-2.15.3.jar:/workspace/BOOT-INF/lib/jackson-datatype-jsr310-2.15.3.jar:/workspace/BOOT-INF/lib/jackson-module-parameter-names-2.15.3.jar:/workspace/BOOT-INF/lib/jackson-databind-2.15.3.jar:/workspace/BOOT-INF/lib/jackson-core-2.15.3.jar:/workspace/BOOT-INF/lib/jackson-annotations-2.15.3.jar:/workspace/BOOT-INF/lib/jackson-dataformat-xml-2.15.3.jar:/workspace/BOOT-INF/lib/evictor-1.0.0.jar:/workspace/BOOT-INF/lib/jaxb-core-4.0.3.jar:/workspace/BOOT-INF/lib/spring-jcl-6.0.13.jar:/workspace/BOOT-INF/lib/jakarta.annotation-api-2.1.1.jar:/workspace/BOOT-INF/lib/snakeyaml-1.33.jar:/workspace/BOOT-INF/lib/spring-security-crypto-6.1.5.jar:/workspace/BOOT-INF/lib/bcpkix-jdk18on-1.73.jar:/workspace/BOOT-INF/lib/micrometer-core-1.11.5.jar:/workspace/BOOT-INF/lib/micrometer-observation-1.11.5.jar:/workspace/BOOT-INF/lib/freemarker-2.3.32.jar:/workspace/BOOT-INF/lib/httpclient5-5.2.1.jar:/workspace/BOOT-INF/lib/jakarta.ws.rs-api-3.1.0.jar:/workspace/BOOT-INF/lib/jakarta.validation-api-3.0.2.jar:/workspace/BOOT-INF/lib/javassist-3.29.2-GA.jar:/workspace/BOOT-INF/lib/woodstox-core-6.5.1.jar:/workspace/BOOT-INF/lib/stax2-api-4.2.1.jar:/workspace/BOOT-INF/lib/reactor-extra-3.5.1.jar:/workspace/BOOT-INF/lib/reactor-core-3.5.11.jar:/workspace/BOOT-INF/lib/jakarta.xml.bind-api-4.0.1.jar:/workspace/BOOT-INF/lib/angus-activation-2.0.1.jar:/workspace/BOOT-INF/lib/jakarta.activation-api-2.1.2.jar:/workspace/BOOT-INF/lib/txw2-4.0.3.jar:/workspace/BOOT-INF/lib/istack-commons-runtime-4.1.2.jar:/workspace/BOOT-INF/lib/logback-classic-1.4.11.jar:/workspace/BOOT-INF/lib/log4j-to-slf4j-2.20.0.jar:/workspace/BOOT-INF/lib/jul-to-slf4j-2.0.9.jar:/workspace/BOOT-INF/lib/bcutil-jdk18on-1.73.jar:/workspace/BOOT-INF/lib/bcprov-jdk18on-1.73.jar:/workspace/BOOT-INF/lib/tomcat-embed-websocket-10.1.15.jar:/workspace/BOOT-INF/lib/tomcat-embed-core-10.1.15.jar:/workspace/BOOT-INF/lib/tomcat-embed-el-10.1.15.jar:/workspace/BOOT-INF/lib/micrometer-commons-1.11.5.jar:/workspace/BOOT-INF/lib/HdrHistogram-2.1.12.jar:/workspace/BOOT-INF/lib/LatencyUtils-2.0.3.jar:/workspace/BOOT-INF/lib/netflix-eventbus-0.3.0.jar:/workspace/BOOT-INF/lib/xstream-1.4.19.jar:/workspace/BOOT-INF/lib/servo-core-0.12.21.jar:/workspace/BOOT-INF/lib/httpclient-4.5.14.jar:/workspace/BOOT-INF/lib/commons-configuration-1.10.jar:/workspace/BOOT-INF/lib/jettison-1.4.0.jar:/workspace/BOOT-INF/lib/httpcore5-h2-5.2.3.jar:/workspace/BOOT-INF/lib/httpcore5-5.2.3.jar:/workspace/BOOT-INF/lib/netflix-infix-0.3.0.jar:/workspace/BOOT-INF/lib/slf4j-api-2.0.9.jar:/workspace/BOOT-INF/lib/jakarta.servlet-api-6.0.0.jar:/workspace/BOOT-INF/lib/osgi-resource-locator-1.0.3.jar:/workspace/BOOT-INF/lib/aopalliance-repackaged-3.0.4.jar:/workspace/BOOT-INF/lib/reactive-streams-1.0.4.jar:/workspace/BOOT-INF/lib/logback-core-1.4.11.jar:/workspace/BOOT-INF/lib/log4j-api-2.20.0.jar:/workspace/BOOT-INF/lib/commons-math-2.2.jar:/workspace/BOOT-INF/lib/mxparser-1.2.2.jar:/workspace/BOOT-INF/lib/guava-19.0.jar:/workspace/BOOT-INF/lib/commons-lang-2.6.jar:/workspace/BOOT-INF/lib/httpcore-4.4.16.jar:/workspace/BOOT-INF/lib/commons-codec-1.15.jar:/workspace/BOOT-INF/lib/commons-jxpath-1.3.jar:/workspace/BOOT-INF/lib/joda-time-2.3.jar:/workspace/BOOT-INF/lib/antlr-runtime-3.4.jar:/workspace/BOOT-INF/lib/gson-2.10.1.jar:/workspace/BOOT-INF/lib/xmlpull-1.1.3.1.jar:/workspace/BOOT-INF/lib/stringtemplate-3.2.1.jar:/workspace/BOOT-INF/lib/antlr-2.7.7.jar com.example.demo.DemoApplication
    [creator]     Warning: The USE_NATIVE_IMAGE_JAVA_PLATFORM_MODULE_SYSTEM environment variable is deprecated and might be removed in a future release. Please refer to the GraalVM release notes.
    [creator]     #
    [creator]     # A fatal error has been detected by the Java Runtime Environment:
    [creator]     #
    [creator]     #  SIGSEGV (0xb) at pc=0x00007fffe6967571, pid=194, tid=220
    [creator]     #
    [creator]     # JRE version: OpenJDK Runtime Environment Liberica-NIK-23.0.0-1 (17.0.7+7) (build 17.0.7+7-LTS)
    [creator]     # Java VM: OpenJDK 64-Bit Server VM Liberica-NIK-23.0.0-1 (17.0.7+7-LTS, mixed mode, tiered, jvmci, compressed oops, compressed class ptrs, parallel gc, linux-amd64)
    [creator]     # Problematic frame:
    [creator]     # J 1993 c2 org.graalvm.collections.EconomicMapImpl.put(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; org.graalvm.sdk (192 bytes) @ 0x00007fffe6967571 [0x00007fffe6966ae0+0x0000000000000a91]
    [creator]     #
    [creator]     # No core dump will be written. Core dumps have been disabled. To enable core dumping, try "ulimit -c unlimited" before starting Java again
    [creator]     #
    [creator]     # An error report file with more information is saved as:
    [creator]     # /layers/paketo-buildpacks_native-image/native-image/hs_err_pid194.log
    [creator]     #
    [creator]     # If you would like to submit a bug report, please visit:
    [creator]     #   https://bell-sw.com/support
    [creator]     #
    [creator]     Error: Image build request for 'com.example.demo.DemoApplication' (pid: 194, path: /layers/paketo-buildpacks_native-image/native-image) failed with exit status 134
    [creator]     unable to invoke layer creator
    [creator]     unable to contribute native-image layer
    [creator]     error running build
    [creator]     exit status 134
    [creator]     ERROR: failed to build: exit status 1

Possible Solution

Steps to Reproduce

  1. Create Project via start.spring.io with latest versions and GraalVM Plugin
  2. Just Run bootBuildImage task

Motivations

It affects everyone who uses the latest Spring Boot project.

Remove requirement to set `start-class` which is Spring Boot related

What happened?

  • What were you attempting to do?

If you try to build a non-Spring Boot app with native-image, it still expects start-class to be set, which is a Spring Boot convention.

[INFO] Downloading from central: https://repo.maven.apache.org/maven2/io/quarkus/quarkus-bom-quarkus-platform-properties/2.1.2.Final/quarkus-bom-quarkus-platform-properties-2.1.2.Final.properties
[INFO] Downloaded from central: https://repo.maven.apache.org/maven2/io/quarkus/quarkus-bom-quarkus-platform-properties/2.1.2.Final/quarkus-bom-quarkus-platform-properties-2.1.2.Final.properties (90 B at 3.1 kB/s)
[INFO] [org.jboss.threads] JBoss Threads version 3.4.2.Final
[INFO] [io.quarkus.deployment.QuarkusAugmentor] Quarkus augmentation completed in 2978ms
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  28.923 s
[INFO] Finished at: 2021-08-16T15:08:57Z
[INFO] ------------------------------------------------------------------------
  Removing source code

Paketo Native Image Buildpack 4.2.0
  https://github.com/paketo-buildpacks/native-image
  Build Configuration:
    $BP_NATIVE_IMAGE                  true  enable native image build
    $BP_NATIVE_IMAGE_BUILD_ARGUMENTS        arguments to pass to the native-image command

Paketo Native Image Buildpack 4.2.0
  manifest does not contain Start-Class
ERROR: failed to build: exit status 1
Error: build failed

https://github.com/paketo-buildpacks/native-image/blob/main/native/build.go#L89-L94

  • What did you expect to happen?

It should source this information from elsewhere if the app is not Spring Boot. Probably falling back to main-class (for runnable jars) or if that's not set either an env variable or default of "app-binary" or we could go old school and use "a.out". Lol.

  • What was the actual behavior? Please provide log output, if possible.

Build Configuration

  • What platform (pack, kpack, tekton buildpacks plugin, etc.) are you
    using? Please include a version.

TBS

  • What buildpacks are you using? Please include versions.

native-image

Checklist

  • I have included log output.
  • The log output includes an error message.
  • I have included steps for reproduction.

Configure `--no-fallback` flag by default

Current default behavior for native-image is to switch to requiring a JVM when a native build fails. This can be super confusing for users, like in this use case.

If a Spring Boot 3 developer configures:

bootBuildImage {
    builder = "paketobuildpacks/builder:tiny"
    environment = [
            "BP_NATIVE_IMAGE" : "true"
    ]
}

But forget to enable Spring AOT/native support when building the app (currently triggered by adding the Native Build Tools plugin with Spring Boot 3), he gets a pretty weird behavior with those messages during the build:

    [creator]     Warning: Serialization method java.io.ObjectOutputStream.writeObject invoked at ch.qos.logback.core.net.AutoFlushingObjectWriter.write(AutoFlushingObjectWriter.java:46)
...
    [creator]     Warning: Image '/layers/paketo-buildpacks_native-image/native-image/com.example.springboot.Application' is a fallback image that requires a JDK for execution (use --no-fallback to suppress fallback image generation and to print more detailed information why a fallback image was necessary).

And then running the app fails with:

docker run docker.io/library/spring-boot:0.0.1-SNAPSHOT
Error: No bin/java and no environment variable JAVA_HOME

There are discussion to make --no-fallback the default behavior of GraalVM native-image but that won't happen until native passes the TCK. In the meantime, Spring Boot 3 set --no-fallback by default when AOT/native support is enabled. But here this support is not enabled.

So my proposal is to set --no-fallback by default, maybe by defining BP_NATIVE_IMAGE_BUILD_ARGUMENTS = --no-fallback by default to allow to disable it in case of, and document that in https://github.com/paketo-buildpacks/native-image#configuration. This buildpack is designed to build a native image to this default configuration would make sense to me.

ERROR: Please rebuild the executable with an appropriate setting of the -march option.

my project config:

springboot 3.1.1
jdk17

I made the image mvn spring-boot:build-image -pnative with the following command, and then it ran fine locally and failed to boot on a machine in a corporate environment and threw the following exception:

The current machine does not support all of the following CPU features that are required by the image: [CX8, CMOV, FXSR, MMX, SSE, SSE2, SSE3, SSSE3, SSE4_1, SSE4_2, POPCNT, LZCNT, AVX, AVX2, BMI1, BMI2, FMA].
Please rebuild the executable with an appropriate setting of the -march option.

native-image --version

Could it be possible to add native-image --version before starting the build in order to have more information about the GraalVM version used?

debug symbols are dropped if user specify `-g` flag for native-image

Expected Behaviour

in case of -g native-image (since 22.3) produces two images: binary and binary.debug, containing debug info. some debug tools expects lack one to resolve symbols.

Current Behaviour

Only one binary copied to layer

Possible Solution

publish all binaries produced by native-image

Steps to Reproduce

  1. generate simple Spring boot application in IDEA (maven)
  2. add configuration to spring-boot-maven-plugin plugin:
<configuration>
                    <image>
                        <env>
                            <BP_NATIVE_IMAGE_BUILD_ARGUMENTS>
                                --no-fallback
                                --verbose
                                -g
                                -O0
                                -H:-Inline
                            </BP_NATIVE_IMAGE_BUILD_ARGUMENTS>
                        </env>
                    </image>
                </configuration>

In result image contains only one binary com.example.demo.DemoApplication

Motivations

We're developing plugin for GraalVM to let users debug their binary applications, and lack of debug info break opportunity for Spring users to debug theirs applications.

Always builds a native-image event when explicitly disabled

I have a Spring Boot App with Gradle and Kotlin including id("org.graalvm.buildtools.native") version "0.9.26" and a META-INF/native-image folder in Resources. When running bootBuildImage with paketo base builder, it builds a native image. This is fine for prod uses. For some debugging I want to build a java based image, not a native image. When I now set BP_NATIVE_IMAGE=false, still a native image is build. I did try to exclude the plugin and also to exclude the META-INF folder, but regardless of what I try, the builder always builds a native image with liberica nik.

Expected Behavior

When setting BP_NATIVE_IMAGE=false I would expect to not build a native-image but rather a normal jvm based image.

Current Behavior

The builder builds a native image, regardless of which variables I set.

Possible Solution

Steps to Reproduce

import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

plugins {
    val kotlinVersion = "1.9.10"
    kotlin("jvm") version kotlinVersion
    kotlin("plugin.spring") version kotlinVersion
    id("org.springframework.boot") version "3.1.3"
    id("io.spring.dependency-management") version "1.1.3"
    id("org.graalvm.buildtools.native") version "0.9.26"

    application
    id("org.flywaydb.flyway") version "9.22.0"
}

group = "com.example"

kotlin {
    jvmToolchain {
        languageVersion.set(JavaLanguageVersion.of(17))
    }
}

repositories {
    mavenCentral()
}

dependencies {
    implementation(platform("org.springframework.cloud:spring-cloud-dependencies:2022.0.4"))
    implementation("org.springframework.boot:spring-boot-starter-actuator")
    implementation("org.springframework.boot:spring-boot-starter-data-r2dbc")
    implementation("org.springframework.boot:spring-boot-starter-security")
    implementation("org.springframework.boot:spring-boot-starter-thymeleaf")
    implementation("org.springframework.boot:spring-boot-starter-validation")
    implementation("org.springframework.boot:spring-boot-starter-webflux")
    implementation("org.springframework.cloud:spring-cloud-starter-gateway")
    implementation("org.thymeleaf.extras:thymeleaf-extras-springsecurity6")
    runtimeOnly("io.r2dbc:r2dbc-h2")
    runtimeOnly("com.h2database:h2")
    runtimeOnly(kotlin("reflect"))

    // Kotlin
    implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core")
    implementation("org.jetbrains.kotlinx:kotlinx-coroutines-reactive")
    implementation("org.jetbrains.kotlinx:kotlinx-coroutines-reactor")
    implementation("com.fasterxml.jackson.module:jackson-module-kotlin")

    // Flyway
    implementation("org.flywaydb:flyway-core")
}

tasks {
    bootBuildImage {
        builder.set("paketobuildpacks/builder:base")
        environment.set(
            mapOf(
                "BP_JVM_VERSION" to "17",
                "BP_NATIVE_IMAGE" to "false",
                "BPE_SPRING_PROFILES_ACTIVE" to "prod",
                "BP_SPRING_CLOUD_BINDINGS_DISABLED" to "true",
                "BPE_APPEND_JAVA_TOOL_OPTIONS" to "-XX:+ExtensiveErrorReports",
                "BPE_DELIM_JAVA_TOOL_OPTIONS" to " ",
            ),
        )
        imageName.set("registry.gitlab.com/etalytics/infrastructure/eta-central")
        tags.set(listOf("${project.version}"))
    }
}

tasks.withType<KotlinCompile>().configureEach {
    kotlinOptions {
        javaParameters = true
        freeCompilerArgs = listOf("-Xjsr305=strict", "-Xemit-jvm-type-annotations", "-Xjvm-default=all", "-Xcontext-receivers")
    }
}

tasks.test {
    useJUnitPlatform()
}

graalvmNative {
    agent {
        defaultMode.set("standard")
    }
    toolchainDetection.set(false)
    binaries {
        all {
            resources.autodetect()
            buildArgs("--enable-monitoring=heapdump", "-march=native", "--initialize-at-build-time=org.slf4j.LoggerFactory,ch.qos.logback,org.apache.logging")
        }
        named("main") {
            when {
                project.hasProperty("static") -> buildArgs("--static", "--libc=musl")
                else -> buildArgs("-H:+StaticExecutableWithDynamicLibC")
            }
        }
    }
    metadataRepository {
        enabled.set(true)
    }
}

Motivations

Support native executables as input

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.

Doesn't Work With Non-Spring Apps

I'm trying to get a native image working with a non-spring app and can't get it working. Here is the app:
https://github.com/jamesward/samples/tree/main/java/native-image/java-plain-native-image-sample

Running:

pack build applications/plain-native-image   --builder paketobuildpacks/builder:tiny   --env BP_NATIVE_IMAGE=true

Output:

tiny: Pulling from paketobuildpacks/builder
Digest: sha256:957b1e3c60c175e9b30585d70a89fdd9c3813456d30907745a7b7a3643a1ac31
Status: Image is up to date for paketobuildpacks/builder:tiny
tiny-cnb: Pulling from paketobuildpacks/run
Digest: sha256:57768a9ede0bed24b6c176a673e2cc825c65ac319be0baa32661eb4db722dba3
Status: Image is up to date for paketobuildpacks/run:tiny-cnb
===> DETECTING
5 of 11 buildpacks participating
paketo-buildpacks/graalvm        6.0.0
paketo-buildpacks/maven          5.0.0
paketo-buildpacks/executable-jar 5.0.0
paketo-buildpacks/spring-boot    4.2.0
paketo-buildpacks/native-image   4.0.0
===> ANALYZING
Restoring metadata for "paketo-buildpacks/graalvm:jdk" from cache
Restoring metadata for "paketo-buildpacks/maven:application" from cache
Restoring metadata for "paketo-buildpacks/maven:cache" from cache
===> RESTORING
Restoring data for "paketo-buildpacks/graalvm:jdk" from cache
Restoring data for "paketo-buildpacks/maven:application" from cache
Restoring data for "paketo-buildpacks/maven:cache" from cache
===> BUILDING

Paketo GraalVM Buildpack 6.0.0
  https://github.com/paketo-buildpacks/graalvm
  Build Configuration:
    $BP_JVM_VERSION              11              the Java version
  Launch Configuration:
    $BPL_JVM_HEAD_ROOM           0               the headroom in memory calculation
    $BPL_JVM_LOADED_CLASS_COUNT  35% of classes  the number of loaded classes in memory calculation
    $BPL_JVM_THREAD_COUNT        250             the number of threads in memory calculation
    $JAVA_TOOL_OPTIONS                           the JVM launch flags
  GraalVM JDK 11.0.10: Reusing cached layer

Paketo Maven Buildpack 5.0.0
  https://github.com/paketo-buildpacks/maven
  Build Configuration:
    $BP_MAVEN_BUILD_ARGUMENTS  -Dmaven.test.skip=true package  the arguments to pass to Maven
    $BP_MAVEN_BUILT_ARTIFACT   target/*.[jw]ar                 the built application artifact explicitly.  Supersedes $BP_MAVEN_BUILT_MODULE
    $BP_MAVEN_BUILT_MODULE                                     the module to find application artifact in
    Creating cache directory /home/cnb/.m2
  Compiled Application: Contributing to layer
    Executing mvnw --batch-mode -Dmaven.test.skip=true package
[INFO] Scanning for projects...
[INFO] 
[INFO] --------------------------< io.packeto:demo >---------------------------
[INFO] Building demo 0.1.0-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO] 
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ demo ---
[WARNING] Using platform encoding (ANSI_X3.4-1968 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory /workspace/src/main/resources
[INFO] 
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ demo ---
[INFO] Changes detected - recompiling the module!
[WARNING] File encoding has not been set, using platform encoding ANSI_X3.4-1968, i.e. build is platform dependent!
[INFO] Compiling 1 source file to /workspace/target/classes
[INFO] 
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ demo ---
[INFO] Not copying test resources
[INFO] 
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ demo ---
[INFO] Not compiling test sources
[INFO] 
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ demo ---
[INFO] Tests are skipped.
[INFO] 
[INFO] --- maven-jar-plugin:3.2.0:jar (default-jar) @ demo ---
[INFO] Building jar: /workspace/target/demo-0.1.0-SNAPSHOT.jar
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  1.280 s
[INFO] Finished at: 2021-05-07T04:44:36Z
[INFO] ------------------------------------------------------------------------
  Removing source code

Paketo Executable JAR Buildpack 5.0.0
  https://github.com/paketo-buildpacks/executable-jar
  Class Path: Contributing to layer
    Writing env.build/CLASSPATH.delim
    Writing env.build/CLASSPATH.prepend

Paketo Native Image Buildpack 4.0.0
  https://github.com/paketo-buildpacks/native-image
===> EXPORTING
Reusing 1/1 app layer(s)
Reusing layer 'launcher'
Reusing layer 'config'
Adding label 'io.buildpacks.lifecycle.metadata'
Adding label 'io.buildpacks.build.metadata'
Adding label 'io.buildpacks.project.metadata'
Warning: default process type 'web' not present in list []
Saving applications/plain-native-image...
*** Images (a1ff9de4f1a6):
      applications/plain-native-image
Reusing cache layer 'paketo-buildpacks/graalvm:jdk'
Adding cache layer 'paketo-buildpacks/maven:application'
Reusing cache layer 'paketo-buildpacks/maven:cache'
Successfully built image applications/plain-native-image

Maybe I'm doing something wrong?

investigate new Native Image Bundles (NIB)

Describe the Enhancement

GraalVM team recently announced a new release model, that will include Native Image Bundles (NIB) in the future GraalVM archives. https://medium.com/graalvm/a-new-graalvm-release-and-new-free-license-4aab483692f5

It would be nice to evaluate the impact it could have on the graalvm buildpack.

Possible Solution

The user could create a bundle from their jar:

native-image -jar MyApp.jar -bundle-create=…/path/to/<imagename>.nib

and later on create a native image with:

native-image -bundle-apply=…/path/to/<imagename>.nib

Motivation

we could decide to have the native-image buildpack support those uses cases

aws lambda runtime linking issue - /lib64/libc.so.6: version `GLIBC_2.3X' not found

Building a spring cloud function native executable using

  • OS: Linux
  • JDK: OpenJDK 17
  • Spring Boot: 3.0.0
  • Graal 22.3
  • native-image buildpack (standard spring boot v3 profile "native")
  • Spring Cloud Function: 4.0.0-SNAPSHOT
  • Using todays (SNAPSHOT) graalvm-reachability-metadata (profile "nativeRS")
  • packaging a lambda zip (profile "lambda" )

Step to reproduce:
"mvn -Pnative package" my spring cloud function app on my WSLES ubuntu 22.04 shell
or
"mvn -Pnative,nativeRS,lambda package spring-boot:build-image

deploy zip file to aws lamda
execute lambda function
cloud-function-dynamodb-lambda: /lib64/libc.so.6: version `GLIBC_2.32' not found (required by ./cloud-function-dynamodb-lambda)
./cloud-function-dynamodb-lambda: /lib64/libc.so.6: version `GLIBC_2.34' not found (required by ./cloud-function-dynamodb-lambda)
./cloud-function-dynamodb-lambda: /lib64/libc.so.6: version `GLIBC_2.32' not found (required by ./cloud-function-dynamodb-lambda)
./cloud-function-dynamodb-lambda: /lib64/libc.so.6: version `GLIBC_2.34' not found (required by ./cloud-function-dynamodb-lambda)
START RequestId: 054fd135-79e2-4ec7-b080-11820822a134 Version: $LATEST
RequestId: 054fd135-79e2-4ec7-b080-11820822a134 Error: Runtime exited with error: exit status 1
Runtime.ExitError
END RequestId: 054fd135-79e2-4ec7-b080-11820822a134
REPORT RequestId: 054fd135-79e2-4ec7-b080-11820822a134	Duration: 75.74 ms	Billed Duration: 76 ms	Memory Size: 128 MB	Max Memory Used: 4 MB	
XRAY TraceId: 1-639994f6-6fc8489d57c0cd106bdbaee8	SegmentId: 11040f061038b2f9	Sampled: true	

IT seems like the existing buildpack used is not providing the same? GLIBC version which is offered used by the aws lambda provided runtime.
Is there any buildback which provides a aws lambda compatible environment to build a graal native image which can be executed published as part of zipped package requesting for dynamic shared lib objects being available on aws provided runtime?

Some ideas i a, starting to investigate..

Assumption: The issue i have with GLIBC dynamic linking on aws lambda at runtime might only be there when i built with my local ubuntu 22.04 or the "tiny builder" cascade for above buidpacks?
I tried lambda runtime provided and provided.al2 (https://docs.aws.amazon.com/lambda/latest/dg/lambda-runtimes.html) which - as i thought has newer versions available - but still loading issue occurs.
I tried as well to use compiler switch on and off -H:+StaticExecutableWithDynamicLibC - same issue.
Todo:
Try to use the same image – amzn-ami-hvm-2018.03.0.20220802.0-x86_64-gp2 or similar (amazonlinux2) to build the native image on assuming it provides the same libc so linking which is needed on lambda works later
Another option is to package as container (instead of zip) where this container image (composed into a lambda layer?) brings its onw shared libs and the native executable on board - might not work together and might have start time latency downside.

Better support for Quarkus.

Relates and depends on paketo-buildpacks/maven#76

This buildpack is little bit spring specific.
It search only for Start-Class not Main-Class it think we should try both
(Start-Class should be first so backward compatibility is preserved).
Quarkus produces file containing native-image flags, this buildpack could check whether the file is present and use those flags.

Spring Boot Native image builds with 22.2.0 are failing

Expected Behavior

Build of a Spring Boot application with Liberica NIK 22.2.0 succeeds.

Current Behavior

Build of a Spring Boot application with Liberica NIK 22.2.0 fails with the following error:

Paketo Native Image Buildpack 5.2.5
  https://github.com/paketo-buildpacks/native-image
  Build Configuration:
    $BP_BINARY_COMPRESSION_METHOD                Compression mechanism used to reduce binary size. Options: `none` (default), `upx` or `gzexe`
    $BP_NATIVE_IMAGE                       true  enable native image build
    $BP_NATIVE_IMAGE_BUILD_ARGUMENTS             arguments to pass to the native-image command
    $BP_NATIVE_IMAGE_BUILD_ARGUMENTS_FILE        a file with arguments to pass to the native-image command
    $BP_NATIVE_IMAGE_BUILT_ARTIFACT              the built application artifact explicitly, required if building from a JAR
  Native Image: Contributing to layer
    Executing native-image -H:Name=/layers/paketo-buildpacks_native-image/native-image/io.paketo.demo.DemoApplication -cp /workspace:/workspace/BOOT-INF/classes:/workspace/BOOT-INF/lib/spring-boot-2.7.2.jar:/workspace/BOOT-INF/lib/spring-context-5.3.22.jar:/workspace/BOOT-INF/lib/spring-aop-5.3.22.jar:/workspace/BOOT-INF/lib/spring-expression-5.3.22.jar:/workspace/BOOT-INF/lib/spring-boot-autoconfigure-2.7.2.jar:/workspace/BOOT-INF/lib/logback-classic-1.2.11.jar:/workspace/BOOT-INF/lib/logback-core-1.2.11.jar:/workspace/BOOT-INF/lib/log4j-to-slf4j-2.17.2.jar:/workspace/BOOT-INF/lib/log4j-api-2.17.2.jar:/workspace/BOOT-INF/lib/jul-to-slf4j-1.7.36.jar:/workspace/BOOT-INF/lib/jakarta.annotation-api-1.3.5.jar:/workspace/BOOT-INF/lib/snakeyaml-1.30.jar:/workspace/BOOT-INF/lib/jackson-databind-2.13.3.jar:/workspace/BOOT-INF/lib/jackson-annotations-2.13.3.jar:/workspace/BOOT-INF/lib/jackson-core-2.13.3.jar:/workspace/BOOT-INF/lib/jackson-datatype-jdk8-2.13.3.jar:/workspace/BOOT-INF/lib/jackson-datatype-jsr310-2.13.3.jar:/workspace/BOOT-INF/lib/jackson-module-parameter-names-2.13.3.jar:/workspace/BOOT-INF/lib/reactor-netty-http-1.0.21.jar:/workspace/BOOT-INF/lib/netty-codec-http-4.1.79.Final.jar:/workspace/BOOT-INF/lib/netty-common-4.1.79.Final.jar:/workspace/BOOT-INF/lib/netty-buffer-4.1.79.Final.jar:/workspace/BOOT-INF/lib/netty-transport-4.1.79.Final.jar:/workspace/BOOT-INF/lib/netty-codec-4.1.79.Final.jar:/workspace/BOOT-INF/lib/netty-handler-4.1.79.Final.jar:/workspace/BOOT-INF/lib/netty-codec-http2-4.1.79.Final.jar:/workspace/BOOT-INF/lib/netty-resolver-dns-4.1.79.Final.jar:/workspace/BOOT-INF/lib/netty-resolver-4.1.79.Final.jar:/workspace/BOOT-INF/lib/netty-codec-dns-4.1.79.Final.jar:/workspace/BOOT-INF/lib/netty-resolver-dns-native-macos-4.1.79.Final-osx-x86_64.jar:/workspace/BOOT-INF/lib/netty-resolver-dns-classes-macos-4.1.79.Final.jar:/workspace/BOOT-INF/lib/netty-transport-native-epoll-4.1.79.Final-linux-x86_64.jar:/workspace/BOOT-INF/lib/netty-transport-native-unix-common-4.1.79.Final.jar:/workspace/BOOT-INF/lib/netty-transport-classes-epoll-4.1.79.Final.jar:/workspace/BOOT-INF/lib/reactor-netty-core-1.0.21.jar:/workspace/BOOT-INF/lib/netty-handler-proxy-4.1.79.Final.jar:/workspace/BOOT-INF/lib/netty-codec-socks-4.1.79.Final.jar:/workspace/BOOT-INF/lib/spring-web-5.3.22.jar:/workspace/BOOT-INF/lib/spring-beans-5.3.22.jar:/workspace/BOOT-INF/lib/spring-webflux-5.3.22.jar:/workspace/BOOT-INF/lib/spring-native-0.12.1.jar:/workspace/BOOT-INF/lib/slf4j-api-1.7.36.jar:/workspace/BOOT-INF/lib/spring-core-5.3.22.jar:/workspace/BOOT-INF/lib/spring-jcl-5.3.22.jar:/workspace/BOOT-INF/lib/reactor-core-3.4.21.jar:/workspace/BOOT-INF/lib/reactive-streams-1.0.4.jar:/workspace/BOOT-INF/lib/spring-boot-jarmode-layertools-2.7.2.jar io.paketo.demo.DemoApplication
Warning: Using a deprecated option --allow-incomplete-classpath from 'META-INF/native-image/org.springframework.aot/spring-aot/native-image.properties' in 'file:///workspace/'. Allowing an incomplete classpath is now the default. Use --link-at-build-time to report linking errors at image build time for a class or package.
WARNING: Unknown module: org.graalvm.nativeimage.llvm specified to --add-exports
WARNING: Unknown module: org.graalvm.nativeimage.llvm specified to --add-exports
WARNING: Unknown module: org.graalvm.nativeimage.llvm specified to --add-exports
================================================================================
GraalVM Native Image: Generating '/layers/paketo-buildpacks_native-image/native-image/io.paketo.demo.DemoApplication' (executable)...
================================================================================
Warning: Could not register org.springframework.boot.autoconfigure.jdbc.HikariDriverConfigurationFailureAnalyzer: allDeclaredConstructors for reflection. Reason: java.lang.NoClassDefFoundError: org/springframework/jdbc/CannotGetJdbcConnectionException.
Warning: Could not register org.springframework.boot.autoconfigure.web.reactive.function.client.ClientHttpConnectorConfiguration$JettyClient: allDeclaredMethods for reflection. Reason: java.lang.NoClassDefFoundError: org/eclipse/jetty/util/ssl/SslContextFactory.
Warning: Could not register org.springframework.boot.diagnostics.analyzer.ValidationExceptionFailureAnalyzer: allDeclaredConstructors for reflection. Reason: java.lang.NoClassDefFoundError: javax/validation/ValidationException.
Warning: Could not register org.springframework.boot.liquibase.LiquibaseChangelogMissingFailureAnalyzer: allDeclaredConstructors for reflection. Reason: java.lang.NoClassDefFoundError: liquibase/exception/ChangeLogParseException.
Warning: Could not register org.springframework.boot.autoconfigure.jdbc.HikariDriverConfigurationFailureAnalyzer: allDeclaredConstructors for reflection. Reason: java.lang.NoClassDefFoundError: org/springframework/jdbc/CannotGetJdbcConnectionException.
Warning: Could not register org.springframework.boot.autoconfigure.web.reactive.function.client.ClientHttpConnectorConfiguration$JettyClient: allDeclaredMethods for reflection. Reason: java.lang.NoClassDefFoundError: org/eclipse/jetty/util/ssl/SslContextFactory.
Warning: Could not register org.springframework.boot.diagnostics.analyzer.ValidationExceptionFailureAnalyzer: allDeclaredConstructors for reflection. Reason: java.lang.NoClassDefFoundError: javax/validation/ValidationException.
Warning: Could not register org.springframework.boot.liquibase.LiquibaseChangelogMissingFailureAnalyzer: allDeclaredConstructors for reflection. Reason: java.lang.NoClassDefFoundError: liquibase/exception/ChangeLogParseException.
[1/7] Initializing...                                            (8.8s @ 0.38GB)
 Version info: 'GraalVM 22.2.0 Java 11 CE'
 Java version info: '11.0.16+8-LTS'
 C compiler: gcc (linux, x86_64, 7.5.0)
 Garbage collector: Serial GC
[2/7] Performing analysis...  []                                 (3.9s @ 0.74GB)
   1,385 (62.84%) of  2,204 classes reachable
     996 (38.00%) of  2,621 fields reachable
   4,240 (55.07%) of  7,699 methods reachable
     294 classes,     0 fields, and     0 methods registered for reflection
Fatal error: com.oracle.graal.pointsto.util.AnalysisError$ParsingError: Error encountered while parsing org.springframework.boot.SpringApplication.createSpringFactoriesInstances(java.lang.Class, java.lang.Class[], java.lang.ClassLoader, java.lang.Object[], java.util.Set)
Parsing context:
   at app//org.springframework.boot.SpringApplication.createSpringFactoriesInstances(SpringApplication.java:439)
   at app//org.springframework.nativex.substitutions.boot.Target_SpringApplication.getSpringFactoriesInstances(Target_SpringApplication.java:173)
   at app//org.springframework.boot.SpringApplication.getSpringFactoriesInstances(SpringApplication.java:424)
    at org.graalvm.nativeimage.pointsto/com.oracle.graal.pointsto.util.AnalysisError.parsingError(AnalysisError.java:152)
    at org.graalvm.nativeimage.pointsto/com.oracle.graal.pointsto.flow.MethodTypeFlow.createFlowsGraph(MethodTypeFlow.java:104)
    at org.graalvm.nativeimage.pointsto/com.oracle.graal.pointsto.flow.MethodTypeFlow.ensureFlowsGraphCreated(MethodTypeFlow.java:83)
    at org.graalvm.nativeimage.pointsto/com.oracle.graal.pointsto.flow.MethodTypeFlow.getOrCreateMethodFlowsGraph(MethodTypeFlow.java:65)
    at org.graalvm.nativeimage.pointsto/com.oracle.graal.pointsto.typestate.DefaultSpecialInvokeTypeFlow.onObservedUpdate(DefaultSpecialInvokeTypeFlow.java:61)
    at org.graalvm.nativeimage.pointsto/com.oracle.graal.pointsto.flow.TypeFlow.update(TypeFlow.java:558)
    at org.graalvm.nativeimage.pointsto/com.oracle.graal.pointsto.PointsToAnalysis$1.run(PointsToAnalysis.java:635)
    at org.graalvm.nativeimage.pointsto/com.oracle.graal.pointsto.util.CompletionExecutor.executeCommand(CompletionExecutor.java:193)
    at org.graalvm.nativeimage.pointsto/com.oracle.graal.pointsto.util.CompletionExecutor.lambda$executeService$0(CompletionExecutor.java:177)
    at java.base/java.util.concurrent.ForkJoinTask$RunnableExecuteAction.exec(ForkJoinTask.java:1426)
    at java.base/java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:290)
    at java.base/java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(ForkJoinPool.java:1020)
    at java.base/java.util.concurrent.ForkJoinPool.scan(ForkJoinPool.java:1656)
    at java.base/java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1594)
    at java.base/java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:183)
Caused by: org.graalvm.compiler.java.BytecodeParser$BytecodeParserError: com.oracle.graal.pointsto.constraints.UnresolvedElementException: Discovered unresolved method during parsing: org.springframework.beans.BeanUtils$KotlinDelegate.instantiateClass(java.lang.reflect.Constructor, java.lang.Object[]). This error is reported at image build time because class org.springframework.beans.BeanUtils is registered for linking at image build time by system default
    at parsing app//org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:196)
    at jdk.internal.vm.compiler/org.graalvm.compiler.java.BytecodeParser.throwParserError(BytecodeParser.java:2506)
    at org.graalvm.nativeimage.builder/com.oracle.svm.hosted.phases.SharedGraphBuilderPhase$SharedBytecodeParser.throwParserError(SharedGraphBuilderPhase.java:105)
    at jdk.internal.vm.compiler/org.graalvm.compiler.java.BytecodeParser.iterateBytecodesForBlock(BytecodeParser.java:3367)
    at jdk.internal.vm.compiler/org.graalvm.compiler.java.BytecodeParser.handleBytecodeBlock(BytecodeParser.java:3319)
    at jdk.internal.vm.compiler/org.graalvm.compiler.java.BytecodeParser.processBlock(BytecodeParser.java:3164)
    at jdk.internal.vm.compiler/org.graalvm.compiler.java.BytecodeParser.build(BytecodeParser.java:1138)
    at jdk.internal.vm.compiler/org.graalvm.compiler.java.BytecodeParser.buildRootMethod(BytecodeParser.java:1030)
    at jdk.internal.vm.compiler/org.graalvm.compiler.java.GraphBuilderPhase$Instance.run(GraphBuilderPhase.java:84)
    at org.graalvm.nativeimage.builder/com.oracle.svm.hosted.phases.SharedGraphBuilderPhase.run(SharedGraphBuilderPhase.java:79)
    at jdk.internal.vm.compiler/org.graalvm.compiler.phases.Phase.run(Phase.java:49)
    at jdk.internal.vm.compiler/org.graalvm.compiler.phases.BasePhase.apply(BasePhase.java:261)
    at jdk.internal.vm.compiler/org.graalvm.compiler.phases.Phase.apply(Phase.java:42)
    at jdk.internal.vm.compiler/org.graalvm.compiler.phases.Phase.apply(Phase.java:38)
    at org.graalvm.nativeimage.pointsto/com.oracle.graal.pointsto.flow.AnalysisParsedGraph.parseBytecode(AnalysisParsedGraph.java:135)
    at org.graalvm.nativeimage.pointsto/com.oracle.graal.pointsto.meta.AnalysisMethod.ensureGraphParsed(AnalysisMethod.java:685)
    at org.graalvm.nativeimage.pointsto/com.oracle.graal.pointsto.phases.InlineBeforeAnalysisGraphDecoder.lookupEncodedGraph(InlineBeforeAnalysis.java:180)
    at jdk.internal.vm.compiler/org.graalvm.compiler.replacements.PEGraphDecoder.doInline(PEGraphDecoder.java:1162)
    at jdk.internal.vm.compiler/org.graalvm.compiler.replacements.PEGraphDecoder.tryInline(PEGraphDecoder.java:1145)
    at jdk.internal.vm.compiler/org.graalvm.compiler.replacements.PEGraphDecoder.trySimplifyInvoke(PEGraphDecoder.java:1003)
    at jdk.internal.vm.compiler/org.graalvm.compiler.replacements.PEGraphDecoder.handleInvoke(PEGraphDecoder.java:957)
    at jdk.internal.vm.compiler/org.graalvm.compiler.nodes.GraphDecoder.processNextNode(GraphDecoder.java:817)
    at org.graalvm.nativeimage.pointsto/com.oracle.graal.pointsto.phases.InlineBeforeAnalysisGraphDecoder.processNextNode(InlineBeforeAnalysis.java:240)
    at jdk.internal.vm.compiler/org.graalvm.compiler.nodes.GraphDecoder.decode(GraphDecoder.java:548)
    at jdk.internal.vm.compiler/org.graalvm.compiler.replacements.PEGraphDecoder.decode(PEGraphDecoder.java:833)
    at org.graalvm.nativeimage.pointsto/com.oracle.graal.pointsto.phases.InlineBeforeAnalysis.decodeGraph(InlineBeforeAnalysis.java:98)
    at org.graalvm.nativeimage.pointsto/com.oracle.graal.pointsto.flow.MethodTypeFlowBuilder.parse(MethodTypeFlowBuilder.java:176)
    at org.graalvm.nativeimage.pointsto/com.oracle.graal.pointsto.flow.MethodTypeFlowBuilder.apply(MethodTypeFlowBuilder.java:343)
    at org.graalvm.nativeimage.pointsto/com.oracle.graal.pointsto.flow.MethodTypeFlow.createFlowsGraph(MethodTypeFlow.java:93)
    ... 13 more
Caused by: com.oracle.graal.pointsto.constraints.UnresolvedElementException: Discovered unresolved method during parsing: org.springframework.beans.BeanUtils$KotlinDelegate.instantiateClass(java.lang.reflect.Constructor, java.lang.Object[]). This error is reported at image build time because class org.springframework.beans.BeanUtils is registered for linking at image build time by system default
    at org.graalvm.nativeimage.builder/com.oracle.svm.hosted.phases.SharedGraphBuilderPhase$SharedBytecodeParser.reportUnresolvedElement(SharedGraphBuilderPhase.java:298)
    at org.graalvm.nativeimage.builder/com.oracle.svm.hosted.phases.SharedGraphBuilderPhase$SharedBytecodeParser.handleUnresolvedMethod(SharedGraphBuilderPhase.java:288)
    at org.graalvm.nativeimage.builder/com.oracle.svm.hosted.phases.SharedGraphBuilderPhase$SharedBytecodeParser.handleUnresolvedInvoke(SharedGraphBuilderPhase.java:244)
    at jdk.internal.vm.compiler/org.graalvm.compiler.java.BytecodeParser.genInvokeStatic(BytecodeParser.java:1664)
    at jdk.internal.vm.compiler/org.graalvm.compiler.java.BytecodeParser.genInvokeStatic(BytecodeParser.java:1639)
    at jdk.internal.vm.compiler/org.graalvm.compiler.java.BytecodeParser.processBytecode(BytecodeParser.java:5224)
    at jdk.internal.vm.compiler/org.graalvm.compiler.java.BytecodeParser.iterateBytecodesForBlock(BytecodeParser.java:3359)
    ... 38 more
--------------------------------------------------------------------------------
    1.0s (7.1% of total time) in 13 GCs | Peak RSS: 1.17GB | CPU load: 4.10
================================================================================
Failed generating '/layers/paketo-buildpacks_native-image/native-image/io.paketo.demo.DemoApplication' after 13.0s.
Error: Image build request failed with exit status 1
unable to invoke layer creator
unable to contribute native-image layer
error running build
exit status 1
ERROR: failed to build: exit status 1
ERROR: failed to build: executing lifecycle: failed with status code: 51

Possible Solution

There are presently two workarounds. The first workaround is recommended, unless you cannot use it for some reason.

  1. Set USE_NATIVE_IMAGE_JAVA_PLATFORM_MODULE_SYSTEM=false. You can do that with pack build demo -e USE_NATIVE_IMAGE_JAVA_PLATFORM_MODULE_SYSTEM=false or with the following change in pom.xml.
      <plugin>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-maven-plugin</artifactId>
        <configuration>
          <classifier>${repackage.classifier}</classifier>
          <image>
            <builder>paketobuildpacks/builder:tiny</builder>
            <env>
              <BP_NATIVE_IMAGE>true</BP_NATIVE_IMAGE>
              <USE_NATIVE_IMAGE_JAVA_PLATFORM_MODULE_SYSTEM>false</USE_NATIVE_IMAGE_JAVA_PLATFORM_MODULE_SYSTEM>
            </env>
          </image>
        </configuration>
      </plugin>
  1. Downgrade your buildpack. You can downgrade the buildpack by setting pack build demo -b gcr.io/paketo-buildpacks/java:6.34.0, or make this change in your pom.xml:
      <plugin>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-maven-plugin</artifactId>
        <configuration>
          <classifier>${repackage.classifier}</classifier>
          <image>
            <builder>paketobuildpacks/builder:tiny</builder>
            <env>
              <BP_NATIVE_IMAGE>true</BP_NATIVE_IMAGE>
            </env>
            <buildpacks>
               <buildpack>gcr.io/paketo-buildpacks/java:6.34.0</buildpack>
            </buildpacks>
          </image>
        </configuration>
      </plugin>

Steps to Reproduce

  1. Download app from https://start.spring.io with WebFlux, Spring Native + Actuators.
  2. ./mvnw spring-boot:build-image or pack build demo -e BP_NATIVE_IMAGE=true.

Motivations

Impact: this is breaking builds for anyone using the latest builders or buildpack.

Remove 'org.springframework.boot.loader.nio.file.NestedFileSystemProvider' for Spring Boot 3.2+ Applications

Hello team,

I just downloaded the latest 3.3.0-RC1, and wanted to build a native image out of it, with GraalVM 22.

With the simple maven command mvn -Pnative spring-boot:build-image with this pom

<plugin>
				<groupId>org.springframework.boot</groupId>
				<artifactId>spring-boot-maven-plugin</artifactId>
				<configuration>
					<image>
						<env>
							<BP_JVM_VERSION>22</BP_JVM_VERSION>
						</env>
					</image>
				</configuration>
			</plugin>

I am able to reproduce this 100%:

[INFO]     [creator]     [2/8] Performing analysis...  []                                (30.6s @ 0.82GB)
[INFO]     [creator]        10,667 reachable types   (74.8% of   14,256 total)
[INFO]     [creator]        14,669 reachable fields  (50.2% of   29,204 total)
[INFO]     [creator]        43,373 reachable methods (46.3% of   93,752 total)
[INFO]     [creator]         4,399 types,   848 fields, and 6,558 methods registered for reflection
[INFO]     [creator]     
[INFO]     [creator]     Error: com.oracle.graal.pointsto.constraints.UnsupportedFeatureException: An object of type 'org.springframework.boot.loader.nio.file.NestedFileSystemProvider' was found in the image heap. This type, however, is marked for initialization at image run time for the following reason: classes are initialized at run time by default.
[INFO]     [creator]     This is not allowed for correctness reasons: All objects that are stored in the image heap must be initialized at build time.
[INFO]     [creator]     
[INFO]     [creator]     You now have two options to resolve this:
[INFO]     [creator]     
[INFO]     [creator]     1) If it is intended that objects of type 'org.springframework.boot.loader.nio.file.NestedFileSystemProvider' are persisted in the image heap, add 
[INFO]     [creator]     
[INFO]     [creator]         '--initialize-at-build-time=org.springframework.boot.loader.nio.file.NestedFileSystemProvider'
[INFO]     [creator]     
[INFO]     [creator]     to the native-image arguments. Note that initializing new types can store additional objects to the heap. It is advised to check the static fields of 'org.springframework.boot.loader.nio.file.NestedFileSystemProvider' to see if they are safe for build-time initialization,  and that they do not contain any sensitive data that should not become part of the image.
[INFO]     [creator]     
[INFO]     [creator]     2) If these objects should not be stored in the image heap, you can use 
[INFO]     [creator]     
[INFO]     [creator]         '--trace-object-instantiation=org.springframework.boot.loader.nio.file.NestedFileSystemProvider'
[INFO]     [creator]     
[INFO]     [creator]     to find classes that instantiate these objects. Once you found such a class, you can mark it explicitly for run time initialization with 
[INFO]     [creator]     
[INFO]     [creator]         '--initialize-at-run-time=<culprit>'
[INFO]     [creator]     
[INFO]     [creator]     to prevent the instantiation of the object.
[INFO]     [creator]     
[INFO]     [creator]     If you are seeing this message after upgrading to a new GraalVM release, this means that some objects ended up in the image heap without their type being marked with --initialize-at-build-time.
[INFO]     [creator]     To fix this, include '--initialize-at-build-time=org.springframework.boot.loader.nio.file.NestedFileSystemProvider' in your configuration. If the classes do not originate from your code, it is advised to update all library or framework dependencies to the latest version before addressing this error.
[INFO]     [creator]     
[INFO]     [creator]     The following detailed trace displays from which field in the code the object was reached.
[INFO]     [creator]     Object was reached by
[INFO]     [creator]       manually created constant
[INFO]     [creator]     Error: java.util.concurrent.ExecutionException: com.oracle.graal.pointsto.util.AnalysisError: com.oracle.graal.pointsto.constraints.UnsupportedFeatureException: An object of type 'org.springframework.boot.loader.nio.file.NestedFileSystemProvider' was found in the image heap. This type, however, is marked for initialization at image run time for the following reason: classes are initialized at run time by default.
[INFO]     [creator]     This is not allowed for correctness reasons: All objects that are stored in the image heap must be initialized at build time.
[INFO]     [creator]     
[INFO]     [creator]     You now have two options to resolve this:
[INFO]     [creator]     
[INFO]     [creator]     1) If it is intended that objects of type 'org.springframework.boot.loader.nio.file.NestedFileSystemProvider' are persisted in the image heap, add 
[INFO]     [creator]     
[INFO]     [creator]         '--initialize-at-build-time=org.springframework.boot.loader.nio.file.NestedFileSystemProvider'
[INFO]     [creator]     
[INFO]     [creator]     to the native-image arguments. Note that initializing new types can store additional objects to the heap. It is advised to check the static fields of 'org.springframework.boot.loader.nio.file.NestedFileSystemProvider' to see if they are safe for build-time initialization,  and that they do not contain any sensitive data that should not become part of the image.
[INFO]     [creator]     
[INFO]     [creator]     2) If these objects should not be stored in the image heap, you can use 
[INFO]     [creator]     
[INFO]     [creator]         '--trace-object-instantiation=org.springframework.boot.loader.nio.file.NestedFileSystemProvider'
[INFO]     [creator]     
[INFO]     [creator]     to find classes that instantiate these objects. Once you found such a class, you can mark it explicitly for run time initialization with 
[INFO]     [creator]     
[INFO]     [creator]         '--initialize-at-run-time=<culprit>'
[INFO]     [creator]     
[INFO]     [creator]     to prevent the instantiation of the object.
[INFO]     [creator]     
[INFO]     [creator]     If you are seeing this message after upgrading to a new GraalVM release, this means that some objects ended up in the image heap without their type being marked with --initialize-at-build-time.
[INFO]     [creator]     To fix this, include '--initialize-at-build-time=org.springframework.boot.loader.nio.file.NestedFileSystemProvider' in your configuration. If the classes do not originate from your code, it is advised to update all library or framework dependencies to the latest version before addressing this error.
[INFO]     [creator]     
[INFO]     [creator]     The following detailed trace displays from which field in the code the object was reached.
[INFO]     [creator]     Object was reached by
[INFO]     [creator]       manually created constant
[INFO]     [creator]     --------------------------------------------------------------------------------
[INFO]     [creator]         3.6s (9.4% of total time) in 73 GCs | Peak RSS: 1.99GB | CPU load: 6.20
[INFO]     [creator]     ================================================================================
[INFO]     [creator]     Failed generating 'com.Application' after 37.7s.
[INFO]     [creator]     unable to invoke layer creator
[INFO]     [creator]     unable to contribute native-image layer
[INFO]     [creator]     error running build
[INFO]     [creator]     exit status 1
[INFO]     [creator]     ERROR: failed to build: exit status 1
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------


Could you please help on this UnsupportedFeatureException issue?

Do not use the full path in generated process types

Describe the Enhancement

When the buildpack runs, it generates process types to run the native-image executables. It generates a full path like /workspace/my-super-cool-app. Instead, we should use ./my-super-cool-app. The app will be executed from the application workspace so it's not necessary to prefix the path.

Possible Solution

Modify build.go to generate different commands.

Motivation

This is not presently a problem, but theoretically, the /workspace or application directory can change between the build and export phase. So the platform could provide /workspace at build time and /app during export, so the image is generated with /app. That would obviously break the commands generated because they hardcode in the full path.

We're not seeing any platforms that do this presently, but this would be a minor change to make the buildpacks more flexible.

Configure runtime augument for java native image

I use kpack 0.9.2 and java-native-image.

From GraalVM Debugging and Diagnostics doc, I want to configure heapdump, see the doc: https://www.graalvm.org/22.3/reference-manual/native-image/guides/create-heap-dump/

In build phase, add BP_NATIVE_IMAGE_BUILD_ARGUMENTS="--enable-monitoring=heapdump"
In runtime phase, I hope to run {command} -XX:+DumpHeapAndExit, but there is no place to pass -XX:+DumpHeapAndExit. I directly run the command in a container, the error shows:

image

Expected Behavior

Current Behavior

should pass some argument to runtime phase

Possible Solution

Steps to Reproduce

Motivations

runtime certificates loading for truststore

From @neoludo via spring-attic/spring-native#1434

HI there,

I've followed instructions at https://paketo.io/docs/howto/configuration/#ca-certificates to add certificates at runtime.
I can see that log at startup :
Added 3 additional CA certificate(s) to system truststore

But when I'm listing certificates from inside my app, I dont see the 3 added certificates...
It seems that build-time truststore is used....
I should have missed a step.

Can anyone help me, plz ?

Thanks
Ludo

Spring Boot cannot build a Java 17 native Docker image because native-image is failing to unresolved method

What happened?

I have a simple Spring Boot application using Java 17 and Maven with the following dependencies I would like to build using spring-boot-maven-plugin as a native Docker image. The parent version is 2.6.0:

  • org.springframework.boot:spring-boot-starter-data-r2dbc
  • org.springframework.boot:spring-boot-starter-webflux
  • org.springframework.boot:spring-boot-starter-actuator
  • org.springframework.experimental:spring-native (from org.springframework.experimental)
  • io.r2dbc:r2dbc-postgresql

What were you attempting to do?

I attempt to build a native Docker image using Packeto (that uses GraalVM) using the following command:

./mvnw.cmd spring-boot:build-image -DskipTests

What did you expect to happen?

I expect the image is built with no error.

What was the actual behavior? Please provide log output, if possible.

Here is a full log output: log.txt

The image cannot be built and the following error is displayed:

[INFO]     [creator]     [/layers/paketo-buildpacks_native-image/native-image/sandbox.Application:174]    classlist:   6,368.93 ms,  0.96 GB
[INFO]     [creator]     [/layers/paketo-buildpacks_native-image/native-image/sandbox.Application:174]        (cap):   2,071.22 ms,  0.96 GB
[INFO]     [creator]     [/layers/paketo-buildpacks_native-image/native-image/sandbox.Application:174]        setup:   6,094.75 ms,  0.96 GB
[INFO]     [creator]     [/layers/paketo-buildpacks_native-image/native-image/sandbox.Application:174]     analysis:  10,400.77 ms,  1.68 GB
[INFO]     [creator]     Fatal error:com.oracle.graal.pointsto.util.AnalysisError$ParsingError: Error encountered while parsing org.springframework.beans.BeanUtils.instantiateClass(java.lang.Class)
[INFO]     [creator]     Parsing context:
[INFO]     [creator]        at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:141)
[INFO]     [creator]        at org.springframework.boot.context.properties.bind.JavaBeanBinder.create(JavaBeanBinder.java:67)
[INFO]     [creator]        at org.springframework.boot.context.properties.bind.Binder.create(Binder.java:366)

...

[INFO]     [creator]     Caused by: com.oracle.graal.pointsto.util.AnalysisError: parsing had failed in another thread
[INFO]     [creator]            at com.oracle.graal.pointsto.util.AnalysisError.shouldNotReachHere(AnalysisError.java:153)
[INFO]     [creator]            at com.oracle.graal.pointsto.meta.AnalysisMethod.ensureGraphParsed(AnalysisMethod.java:656)
[INFO]     [creator]            at com.oracle.graal.pointsto.phases.InlineBeforeAnalysisGraphDecoder.lookupEncodedGraph(InlineBeforeAnalysis.java:182)
[INFO]     [creator]            at jdk.internal.vm.compiler/org.graalvm.compiler.replacements.PEGraphDecoder.doInline(PEGraphDecoder.java:1120)
[INFO]     [creator]            at jdk.internal.vm.compiler/org.graalvm.compiler.replacements.PEGraphDecoder.tryInline(PEGraphDecoder.java:1103)
[INFO]     [creator]            at jdk.internal.vm.compiler/org.graalvm.compiler.replacements.PEGraphDecoder.trySimplifyInvoke(PEGraphDecoder.java:961)
[INFO]     [creator]            at jdk.internal.vm.compiler/org.graalvm.compiler.replacements.PEGraphDecoder.handleInvoke(PEGraphDecoder.java:915)
[INFO]     [creator]            at jdk.internal.vm.compiler/org.graalvm.compiler.nodes.GraphDecoder.processNextNode(GraphDecoder.java:791)
[INFO]     [creator]            at com.oracle.graal.pointsto.phases.InlineBeforeAnalysisGraphDecoder.processNextNode(InlineBeforeAnalysis.java:242)
[INFO]     [creator]            at jdk.internal.vm.compiler/org.graalvm.compiler.nodes.GraphDecoder.decode(GraphDecoder.java:532)
[INFO]     [creator]            at jdk.internal.vm.compiler/org.graalvm.compiler.replacements.PEGraphDecoder.decode(PEGraphDecoder.java:787)
[INFO]     [creator]            at com.oracle.graal.pointsto.phases.InlineBeforeAnalysis.decodeGraph(InlineBeforeAnalysis.java:99)
[INFO]     [creator]            at com.oracle.graal.pointsto.flow.MethodTypeFlowBuilder.parse(MethodTypeFlowBuilder.java:171)
[INFO]     [creator]            at com.oracle.graal.pointsto.flow.MethodTypeFlowBuilder.apply(MethodTypeFlowBuilder.java:321)
[INFO]     [creator]            at com.oracle.graal.pointsto.flow.MethodTypeFlow.createTypeFlow(MethodTypeFlow.java:293)
[INFO]     [creator]            ... 12 more
[INFO]     [creator]     Caused by: org.graalvm.compiler.java.BytecodeParser$BytecodeParserError: com.oracle.graal.pointsto.constraints.UnresolvedElementException: Discovered unresolved method during parsing: org.springframework.beans.BeanUtils$Kot
linDelegate.instantiateClass(java.lang.reflect.Constructor, java.lang.Object[]). To diagnose the issue you can use the --allow-incomplete-classpath option. The missing method is then reported at run time when it is accessed the first time.
[INFO]     [creator]            at parsing org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:196)
[INFO]     [creator]            at jdk.internal.vm.compiler/org.graalvm.compiler.java.BytecodeParser.throwParserError(BytecodeParser.java:2624)
[INFO]     [creator]            at com.oracle.svm.hosted.phases.SharedGraphBuilderPhase$SharedBytecodeParser.throwParserError(SharedGraphBuilderPhase.java:107)

...

[INFO]     [creator]     Caused by: com.oracle.graal.pointsto.constraints.UnresolvedElementException: Discovered unresolved method during parsing: org.springframework.beans.BeanUtils$KotlinDelegate.instantiateClass(java.lang.reflect.Constructor, ja
va.lang.Object[]). To diagnose the issue you can use the --allow-incomplete-classpath option. The missing method is then reported at run time when it is accessed the first time.
[INFO]     [creator]            at com.oracle.svm.hosted.phases.SharedGraphBuilderPhase$SharedBytecodeParser.reportUnresolvedElement(SharedGraphBuilderPhase.java:307)
[INFO]     [creator]            at com.oracle.svm.hosted.phases.SharedGraphBuilderPhase$SharedBytecodeParser.handleUnresolvedMethod(SharedGraphBuilderPhase.java:298)
[INFO]     [creator]            at com.oracle.svm.hosted.phases.SharedGraphBuilderPhase$SharedBytecodeParser.handleUnresolvedInvoke(SharedGraphBuilderPhase.java:252)
[INFO]     [creator]            at jdk.internal.vm.compiler/org.graalvm.compiler.java.BytecodeParser.genInvokeStatic(BytecodeParser.java:1677)
[INFO]     [creator]            at jdk.internal.vm.compiler/org.graalvm.compiler.java.BytecodeParser.genInvokeStatic(BytecodeParser.java:1652)
[INFO]     [creator]            at jdk.internal.vm.compiler/org.graalvm.compiler.java.BytecodeParser.processBytecode(BytecodeParser.java:5419)
[INFO]     [creator]            at jdk.internal.vm.compiler/org.graalvm.compiler.java.BytecodeParser.iterateBytecodesForBlock(BytecodeParser.java:3477)
[INFO]     [creator]            ... 39 more

I assume there is something wrong with native-image buildpack since the following lines can be found in the log:

[INFO]     [creator]     # Printing build artifacts to: /layers/paketo-buildpacks_native-image/native-image/sandbox.Application.build_artifacts.txt
[INFO]     [creator]     Error: Image build request failed with exit status 1
[INFO]     [creator]     unable to invoke layer creator
[INFO]     [creator]     unable to contribute native-image layer
[INFO]     [creator]     error running build
[INFO]     [creator]     exit status 1
[INFO]     [creator]     ERROR: failed to build: exit status 1

Build Configuration

I use paketobuildpacks (I have no idea what should be specified as a "platform") and here is the full build configuration:

<build>
	<finalName>spring-boot-reactive</finalName>
	<plugins>
		<plugin>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-maven-plugin</artifactId>
			<configuration>
				<image>
					<builder>paketobuildpacks/builder:tiny</builder>
					<env>
						<BP_BOOT_NATIVE_IMAGE>1</BP_BOOT_NATIVE_IMAGE>
						<BP_BOOT_NATIVE_IMAGE_BUILD_ARGUMENTS>-Dspring.spel.ignore=true</BP_BOOT_NATIVE_IMAGE_BUILD_ARGUMENTS>
					</env>
					<buildpacks>
						<buildpack>gcr.io/paketo-buildpacks/java-native-image:5.12.0</buildpack>
					</buildpacks>
				</image>
			</configuration>
		</plugin>

	</plugins>
</build>

What buildpacks are you using? Please include versions.

I use java-native-image of version 5.12.0 as long as it is compatible with GraalVM supporting Java 17.

What builder are you using? If custom, can you provide the output from `pack

inspect-builder `?

I use paketobuildpacks/builder:tiny as shown in the configuration above.

Can you provide a sample app or relevant configuration (buildpack.yml,

nginx.conf, etc.)?

I have no other configuration.


A side question: Does exist a compatibility matrix between Java version, GraalVM version, individual paketo-buildpacks? How is bellsoft-liberica relevant to them?

Support append BP_NATIVE_IMAGE_BUILD_ARGUMENTS to the end of command

Describe the Enhancement

After using BP_NATIVE_IMAGE_BUILD_ARGUMENTS, these arguments are always added to the very beginning of the command(before -cp), example:

[creator]         Executing native-image --no-fallback -H:+StaticExecutableWithDynamicLibC @/workspace/META-INF/native-image/argfile $BP_NATIVE_IMAGE_BUILD_ARGUMENTS -H:Name=/layers/paketo-buildpacks_native-image/native-image/xxxx -cp xxxx

Is it possible to append BP_NATIVE_IMAGE_BUILD_ARGUMENTS to the end of the command instead of the beginning? example:

native-image --no-fallback -H:+StaticExecutableWithDynamicLibC @/workspace/META-INF/native-image/argfile -H:Name=/layers/paketo-buildpacks_native-image/native-image/xxxx -cp xxxx $BP_NATIVE_IMAGE_BUILD_ARGUMENTS

Possible Solution

Add another environment variable to switch this feature on and off

Motivation

In some cases, it is necessary to override graalvm native image arguments that are included in some of the dependency jars. additional command line arguments must be placed at the end of the line for this to work (actually, after -cp)

example: apache/camel-quarkus#5006 (comment)

In order to override RunReachabilityHandlersConcurrently in google-gax, this parameter must be placed last

Update for spring-native and disable automatic dependency

As discussed in spring-attic/spring-native#399, please remove automatic provisioning of spring-graalvm-native dependency. Notice the artifact name has been renamed from spring-graalvm-native to spring-native (same groupId).

Given this new behavior, my proposal would be to enable this buildpack when spring-native dependency is detected, and allow to disable it by setting $BP_BOOT_NATIVE_IMAGE to false.

For reasonable backward compatibility, please continue to detect spring-graalvm-native in addition to spring-native for now in order to not break 0.8.x users.

Question : How to attach a debugger during image building

Hi there,

This is more a question than an issue, but it might result as an enhancement.

I am working on a Spring Boot POC application that I build in native using Spring Boot buildpack. During the native image build process, there is a NullPointerException in a GraalVM class I would like to investigate.

The native-image argument --debug-attach allows me to attach a debugger during the image building but I am unable to connect, I presume, because the port number is not exposed. I may be underestimating the difficulty, but would it be possible to expose the port mentioned in the aforementioned argument ?

Thank you in advance of your advice

detect.go does not parse values for .platform/env/BP_NATIVE_IMAGE correctly

I do not use pack but rely instead on paketobuildpacks/builder:tiny directly on my .gitlab-ci.yml.
As a consequence, I write the variable like BP_NATIVE_IMAGE to .platform/env/BP_NATIVE_IMAGE and invoke cnb/lifecycle/creator -app=. -platform=$HOME/.platform in the container itself.

The native buildpack throws an error:

Paketo Buildpack for Native Image 5.8.0
  invalid value '1
  ' for key 'BP_NATIVE_IMAGE': expected one of [1, t, T, TRUE, true, True, 0, f, F, FALSE, false, False]

Searching for the string leads me to this buildpack. For the java-buildpack (where I set the BP_JVM_VERSION the same way), it works fine.

Expected Behavior

Setting the BP-*-variables should work for this build pack as denoted in https://github.com/buildpacks/spec/blob/main/platform.md#user-provided-variables

Executing the following commands in paketobuildpacks/builder:tiny should work and generate a native java application.

mkdir -p $HOME/.platform/env
echo "1" > $HOME/.platform/env/BP_NATIVE_IMAGE
echo "17" > $HOME/.platform/env/BP_JVM_VERSION
/cnb/lifecycle/creator -app=. -platform=$HOME/.platform image

Current Behavior

The commands above fail. I included some debug-code since the snippet is running in gitlab-ci to track the issue down:

$ cat $HOME/.platform/env/BP_NATIVE_IMAGE || true
cat: /home/cnb/.platform/env/BP_NATIVE_IMAGE: No such file or directory
$ rm $HOME/.platform/env/BP_NATIVE_IMAGE || true
$ echo "1" > $HOME/.platform/env/BP_NATIVE_IMAGE
rm: cannot remove '/home/cnb/.platform/env/BP_NATIVE_IMAGE': No such file or directory
$ cat $HOME/.platform/env/BP_NATIVE_IMAGE || true
1
$ echo "17" > $HOME/.platform/env/BP_JVM_VERSION
$ /cnb/lifecycle/creator -app=. -platform=$HOME/.platform $CI_REGISTRY_IMAGE:$CI_COMMIT_REF_SLUG-native
Warning: Not restoring or caching layer data, no cache flag specified.
===> DETECTING
======== Output: paketo-buildpacks/[email protected] ========
Paketo Buildpack for Native Image 5.8.0
  invalid value '1
  ' for key 'BP_NATIVE_IMAGE': expected one of [1, t, T, TRUE, true, True, 0, f, F, FALSE, false, False]

Afterwards a jar-application is build without nativeness.

I tried multiple variants: 1, true, etc.

Possible Solution

I guess it is a bug in the detect.go...in the last commits some test cases where removed...but this is a guess.

Steps to Reproduce

  1. Start paketobuildpacks/builder:tiny and enter the container: docker run --rm -it -v "$PWD":/usr/src/app -w /usr/src/app paketobuildpacks/builder:base bash
  2. Set the files for the platform:
mkdir -p $HOME/.platform/env
echo "1" > $HOME/.platform/env/BP_NATIVE_IMAGE
echo "17" > $HOME/.platform/env/BP_JVM_VERSION
  1. Execute the build process and see the error
cnb@bd1dc0691ed0:/usr/src/app$ /cnb/lifecycle/creator -app=. -platform=$HOME/.platform image
Warning: Not restoring or caching layer data, no cache flag specified.
===> DETECTING
======== Output: paketo-buildpacks/[email protected] ========

Paketo Buildpack for Native Image 5.8.0
  invalid value '1
  ' for key 'BP_NATIVE_IMAGE': expected one of [1, t, T, TRUE, true, True, 0, f, F, FALSE, false, False]

Motivations

Letting buildpacks generate native java-image and run in gitlab-ci without autodevops-magic via the builder-image directly.

Consider using upx to compress native executables

While discussing with GraalVM team, they brought to my attention UPX, also mentioned in this blog post. It allows to compress very significantly executables, with fast decompression and faster startup than the uncompressed version at least on my personal computer.

I tried it on the typical webmvc-tomcat sample of Spring Native, the result are kind of mind blowing, since it allows to turn a 50M Spring Boot + Spring MVC + Tomcat + Jackson native executable into a 14M one!

15:36 $ upx -7 -k target/webmvc-tomcat
                       Ultimate Packer for eXecutables
                          Copyright (C) 1996 - 2020
UPX git-d7ba31+ Markus Oberhumer, Laszlo Molnar & John Reiser   Jan 23rd 2020

        File size         Ratio      Format      Name
   --------------------   ------   -----------   -----------
  50265544 ->  14983784   29.81%   linux/amd64   webmvc-tomcat                 

Packed 1 file.
✔ ~/workspace/spring-native/samples/webmvc-tomcat
15:36 $ exa -l target/webmvc-tomcat*
.rwxr-xr-x 14M seb 17 Mar 15:28 target/webmvc-tomcat
.rw-r--r-- 15M seb 17 Mar 15:28 target/webmvc-tomcat-0.0.1-SNAPSHOT-exec.jar
.rw-r--r-- 30k seb 17 Mar 15:28 target/webmvc-tomcat-0.0.1-SNAPSHOT.jar
.rwxr-xr-x 50M seb 17 Mar 15:28 target/webmvc-tomcat.~
✔ ~/workspace/spring-native/samples/webmvc-tomcat
15:36 $ target/webmvc-tomcat.~ 
2021-03-17 15:37:16.605  INFO 75719 --- [           main] o.s.nativex.NativeListener               : This application is bootstrapped with code generated with Spring AOT

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::       (v2.4.4-SNAPSHOT)

2021-03-17 15:37:16.646  INFO 75719 --- [           main] com.example.webmvc.WebmvcApplication     : Started WebmvcApplication in 0.046 seconds (JVM running for 0.047)

✘-INT ~/workspace/spring-native/samples/webmvc-tomcat
15:37 $ target/webmvc-tomcat
2021-03-17 15:37:22.492  INFO 75777 --- [           main] o.s.nativex.NativeListener               : This application is bootstrapped with code generated with Spring AOT

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::       (v2.4.4-SNAPSHOT)

2021-03-17 15:37:22.513  INFO 75777 --- [           main] com.example.webmvc.WebmvcApplication     : Started WebmvcApplication in 0.023 seconds (JVM running for 0.024)

I guess less IO needed allows faster startup despite the decompression.

Remove `--no-sever` argument

What happened?

When run, native-image is complaining about the --no-server argument that the buildpack is setting.

Paketo Native Image Buildpack v4.2.0-11-gad050c8
  https://github.com/paketo-buildpacks/native-image
  Build Configuration:
    $BP_NATIVE_IMAGE                  true  enable native image build
    $BP_NATIVE_IMAGE_BUILD_ARGUMENTS        arguments to pass to the native-image command
  Native Image: Contributing to layer
    GraalVM 21.2.0 Java 11 CE (Java Version 11.0.12+6-jvmci-21.2-b08)
    Executing native-image -H:+StaticExecutableWithDynamicLibC -H:Name=/layers/paketo-buildpacks_native-image/native-image/io.paketo.demo.DemoApplication -cp /workspace:/workspace/BOOT-INF/classes:/workspace/BOOT-INF/lib/spring-boot-2.5.4.jar:/workspace/BOOT-INF/lib/spring-context-5.3.9.jar:/workspace/BOOT-INF/lib/spring-aop-5.3.9.jar:/workspace/BOOT-INF/lib/spring-expression-5.3.9.jar:/workspace/BOOT-INF/lib/spring-boot-autoconfigure-2.5.4.jar:/workspace/BOOT-INF/lib/logback-classic-1.2.5.jar:/workspace/BOOT-INF/lib/logback-core-1.2.5.jar:/workspace/BOOT-INF/lib/log4j-to-slf4j-2.14.1.jar:/workspace/BOOT-INF/lib/log4j-api-2.14.1.jar:/workspace/BOOT-INF/lib/jul-to-slf4j-1.7.32.jar:/workspace/BOOT-INF/lib/jakarta.annotation-api-1.3.5.jar:/workspace/BOOT-INF/lib/snakeyaml-1.28.jar:/workspace/BOOT-INF/lib/spring-boot-actuator-autoconfigure-2.5.4.jar:/workspace/BOOT-INF/lib/spring-boot-actuator-2.5.4.jar:/workspace/BOOT-INF/lib/jackson-databind-2.12.4.jar:/workspace/BOOT-INF/lib/jackson-annotations-2.12.4.jar:/workspace/BOOT-INF/lib/jackson-core-2.12.4.jar:/workspace/BOOT-INF/lib/jackson-datatype-jsr310-2.12.4.jar:/workspace/BOOT-INF/lib/micrometer-core-1.7.3.jar:/workspace/BOOT-INF/lib/HdrHistogram-2.1.12.jar:/workspace/BOOT-INF/lib/LatencyUtils-2.0.3.jar:/workspace/BOOT-INF/lib/jackson-datatype-jdk8-2.12.4.jar:/workspace/BOOT-INF/lib/jackson-module-parameter-names-2.12.4.jar:/workspace/BOOT-INF/lib/reactor-netty-http-1.0.10.jar:/workspace/BOOT-INF/lib/netty-codec-http-4.1.67.Final.jar:/workspace/BOOT-INF/lib/netty-common-4.1.67.Final.jar:/workspace/BOOT-INF/lib/netty-buffer-4.1.67.Final.jar:/workspace/BOOT-INF/lib/netty-transport-4.1.67.Final.jar:/workspace/BOOT-INF/lib/netty-codec-4.1.67.Final.jar:/workspace/BOOT-INF/lib/netty-handler-4.1.67.Final.jar:/workspace/BOOT-INF/lib/netty-codec-http2-4.1.67.Final.jar:/workspace/BOOT-INF/lib/netty-resolver-dns-4.1.67.Final.jar:/workspace/BOOT-INF/lib/netty-resolver-4.1.67.Final.jar:/workspace/BOOT-INF/lib/netty-codec-dns-4.1.67.Final.jar:/workspace/BOOT-INF/lib/netty-resolver-dns-native-macos-4.1.67.Final-osx-x86_64.jar:/workspace/BOOT-INF/lib/netty-transport-native-unix-common-4.1.67.Final.jar:/workspace/BOOT-INF/lib/netty-transport-native-epoll-4.1.67.Final-linux-x86_64.jar:/workspace/BOOT-INF/lib/reactor-netty-core-1.0.10.jar:/workspace/BOOT-INF/lib/netty-handler-proxy-4.1.67.Final.jar:/workspace/BOOT-INF/lib/netty-codec-socks-4.1.67.Final.jar:/workspace/BOOT-INF/lib/spring-web-5.3.9.jar:/workspace/BOOT-INF/lib/spring-beans-5.3.9.jar:/workspace/BOOT-INF/lib/spring-webflux-5.3.9.jar:/workspace/BOOT-INF/lib/spring-native-0.10.2.jar:/workspace/BOOT-INF/lib/slf4j-api-1.7.32.jar:/workspace/BOOT-INF/lib/spring-core-5.3.9.jar:/workspace/BOOT-INF/lib/spring-jcl-5.3.9.jar:/workspace/BOOT-INF/lib/reactor-core-3.4.9.jar:/workspace/BOOT-INF/lib/reactive-streams-1.0.3.jar:/workspace/BOOT-INF/lib/spring-boot-jarmode-layertools-2.5.4.jar io.paketo.demo.DemoApplication
Warning: Ignoring server-mode native-image argument --no-server.

Need to investigate and see if this option is still required, or if default behavior in native-image has changed and the buildpack needs to change to reflect that.

  • What did you expect to happen?

See no extraneous warnings.

Checklist

  • I have included log output.
  • The log output includes an error message.
  • I have included steps for reproduction.

Support Jammy Jellyfish

Describe the Enhancement

Currently, when I attempt to use this buildpack on top of the Paketo Jammy Tiny stack, my app fails to launch, complaining about a missing shared library:

 Timed out after 60.223s.
        Expected
                docker container id: 702371c0071915d7edc05acdb9ff0e43cf559814b4b85884d8e7d8488edbeab9
        to be available.

        Container logs:

        /workspace/io.paketo.demo.DemoApplication: error while loading shared libraries: libstdc++.so.6: cannot open shared object file: No such
 file or directory

You can see this failure in the context of smoke tests on this PR.

Possible Solution

It's not clear to me if the native-image dependency needs to be recompiled or differently configured. Perhaps somewhere in the implementation it checks the stack ID and sets up the launch environment accordingly? Any check like that will need to check for io.buildpacks.stacks.jammy.tiny.

Motivation

This buildpack works on the Paketo Bionic Tiny Builder. Ideally, we want to support the same buildpacks in the Jammy Tiny Builder.

Certain Native image artifacts are not copied to run image

I am using the builder-jammy-base buildpack with the spring-boot-maven-plugin to build a native image. After some troubleshooting with the Graal team (oracle/graal#8273) it seems that certain required artifacts (jdk_library and jdk_liberary_shim .so files) are not being included in the workspace/ directory of containers using the run image generated by this buildpack. We do see them listed as "produced artifacts" in the build log, however.

Expected Behavior

The following .so files (in bold) from the log snippet below should be included in the workspace/ directory alongside the native image executable (org.example.App):

INFO] [creator] Produced artifacts:
[INFO] [creator] /layers/paketo-buildpacks_native-image/native-image/libawt.so (jdk_library)
[INFO] [creator] /layers/paketo-buildpacks_native-image/native-image/libawt_headless.so (jdk_library)
[INFO] [creator] /layers/paketo-buildpacks_native-image/native-image/libawt_xawt.so (jdk_library)
[INFO] [creator] /layers/paketo-buildpacks_native-image/native-image/libfontmanager.so (jdk_library)
[INFO] [creator] /layers/paketo-buildpacks_native-image/native-image/libfreetype.so (jdk_library)
[INFO] [creator] /layers/paketo-buildpacks_native-image/native-image/libjava.so (jdk_library_shim)
[INFO] [creator] /layers/paketo-buildpacks_native-image/native-image/libjavajpeg.so (jdk_library)
[INFO] [creator] /layers/paketo-buildpacks_native-image/native-image/libjvm.so (jdk_library_shim)
[INFO] [creator] /layers/paketo-buildpacks_native-image/native-image/liblcms.so (jdk_library)
[INFO] [creator] /layers/paketo-buildpacks_native-image/native-image/org.example.App (executable)

Current Behavior

The files are not included, the directory in the run container only contains the native executable:
image

Steps to Reproduce

Repro:

  1. Please check out the following project for a small, single-class repro of this error: reproduce-awt-lib-error-graal
  2. Run mvn clean install in the root directory of the project to build the jar
  3. Run mvn -Pnative package to build the native image, called test/repro-awt-lib-error
  4. Read the log output and verify that the jdk library artifacts were produced. Attached is a copy of mine for your convenience:
    packageOutput.txt
  5. Run docker run test/repro-awt-lib-error
  6. The run fails because the libawt.so file is not in the same directory as the image executable (according to the Graal team: oracle/graal#8273 (comment))

Environment:
GraalVM version 23.0.2 (as determined by buildpack)
JDK major version: 17
OS: MacOS Sonoma 14.2.1
Architecture: 6-Core Intel Core i9
Maven version: 3.9.6
Docker version: 24.0.7

Motivations

My company is trying to convert one of our microservices to a native executable, using your buildpack. The service uses the Apache PDDocument class, which relies on the Java awt library. Since the library is not available to the native image at runtime, the executable crashes.

BP_NATIVE_IMAGE_BUILD_ARGUMENTS replaces arguments added by Datadog BP

We use BP_NATIVE_IMAGE=true and BP_DATADOG_ENABLED=true. Both add arguments to native-image. Unfortunately native-image BP removes argument added by Datadog BP.

Expected Behavior

native-image BP appends arguments

Current Behavior

native-image BP replaces arguments

Steps to Reproduce

  1. BP_NATIVE_IMAGE_BUILD_ARGUMENTS=-O0 -J-Xmx7g
Paketo Buildpack for Datadog 4.6.0
[INFO]     [creator]       https://github.com/paketo-buildpacks/datadog
[INFO]     [creator]       Build Configuration:
[INFO]     [creator]         $BP_DATADOG_ENABLED    true   whether to contribute the Datadog trace agent
[INFO]     [creator]       Launch Configuration:
[INFO]     [creator]         $BPL_DATADOG_DISABLED  false  whether to disable the Datadog trace agent (non native-image Java applications only!)
[INFO]     [creator]       Datadog Java Agent 1.25.1: Contributing to layer
[INFO]     [creator]         Downloading from https://repo1.maven.org/maven2/com/datadoghq/dd-java-agent/1.25.1/dd-java-agent-1.25.1.jar
[INFO]     [creator]         Verifying checksum
[INFO]     [creator]         Copying to /layers/paketo-buildpacks_datadog/datadog-agent-java
[INFO]     [creator]         Writing env.build/BP_NATIVE_IMAGE_BUILD_ARGUMENTS.append
[INFO]     [creator]         Writing env.build/BP_NATIVE_IMAGE_BUILD_ARGUMENTS.delim
[INFO]     [creator]         Writing env.launch/BPI_DATADOG_AGENT_PATH.default
[INFO]     [creator]     
[INFO]     [creator]     Paketo Buildpack for Native Image 5.12.7
[INFO]     [creator]       https://github.com/paketo-buildpacks/native-image
[INFO]     [creator]       Build Configuration:
[INFO]     [creator]         $BP_BINARY_COMPRESSION_METHOD                        Compression mechanism used to reduce binary size. Options: `none` (default), `upx` or `gzexe`
[INFO]     [creator]         $BP_NATIVE_IMAGE                       true          enable native image build
[INFO]     [creator]         $BP_NATIVE_IMAGE_BUILD_ARGUMENTS       -O0 -J-Xmx7g  arguments to pass to the native-image command
[INFO]     [creator]         $BP_NATIVE_IMAGE_BUILD_ARGUMENTS_FILE                a file with arguments to pass to the native-image command
[INFO]     [creator]         $BP_NATIVE_IMAGE_BUILT_ARTIFACT                      the built application artifact explicitly, required if building from a JAR
[INFO]     [creator]       Native Image: Contributing to layer
[INFO]     [creator]         Executing native-image --no-fallback -H:+StaticExecutableWithDynamicLibC -O0 -J-Xmx7g -H:Name=/layers/paketo-buildpacks_native-image/native-image/com.mercedesbenz.blueprint.Application -cp ...    

In last line Datadog agent configuration is missing.

  1. BP_NATIVE_IMAGE_BUILD_ARGUMENTS not set
Paketo Buildpack for Datadog 4.6.0
[INFO]     [creator]       https://github.com/paketo-buildpacks/datadog
[INFO]     [creator]       Build Configuration:
[INFO]     [creator]         $BP_DATADOG_ENABLED    true   whether to contribute the Datadog trace agent
[INFO]     [creator]       Launch Configuration:
[INFO]     [creator]         $BPL_DATADOG_DISABLED  false  whether to disable the Datadog trace agent (non native-image Java applications only!)
[INFO]     [creator]       Datadog Java Agent 1.25.1: Contributing to layer
[INFO]     [creator]         Downloading from https://repo1.maven.org/maven2/com/datadoghq/dd-java-agent/1.25.1/dd-java-agent-1.25.1.jar
[INFO]     [creator]         Verifying checksum
[INFO]     [creator]         Copying to /layers/paketo-buildpacks_datadog/datadog-agent-java
[INFO]     [creator]         Writing env.build/BP_NATIVE_IMAGE_BUILD_ARGUMENTS.append
[INFO]     [creator]         Writing env.build/BP_NATIVE_IMAGE_BUILD_ARGUMENTS.delim
[INFO]     [creator]         Writing env.launch/BPI_DATADOG_AGENT_PATH.default
[INFO]     [creator]     
[INFO]     [creator]     Paketo Buildpack for Native Image 5.12.7
[INFO]     [creator]       https://github.com/paketo-buildpacks/native-image
[INFO]     [creator]       Build Configuration:
[INFO]     [creator]         $BP_BINARY_COMPRESSION_METHOD                                                                                                      Compression mechanism used to reduce binary size. Options: `none` (default), `upx` or `gzexe`
[INFO]     [creator]         $BP_NATIVE_IMAGE                       true                                                                                        enable native image build
[INFO]     [creator]         $BP_NATIVE_IMAGE_BUILD_ARGUMENTS       -J-javaagent:/layers/paketo-buildpacks_datadog/datadog-agent-java/dd-java-agent-1.25.1.jar  arguments to pass to the native-image command
[INFO]     [creator]         $BP_NATIVE_IMAGE_BUILD_ARGUMENTS_FILE                                                                                              a file with arguments to pass to the native-image command
[INFO]     [creator]         $BP_NATIVE_IMAGE_BUILT_ARTIFACT                                                                                                    the built application artifact explicitly, required if building from a JAR
[INFO]     [creator]       Native Image: Contributing to layer
[INFO]     [creator]         Executing native-image --no-fallback -H:+StaticExecutableWithDynamicLibC -J-javaagent:/layers/paketo-buildpacks_datadog/datadog-agent-java/dd-java-agent-1.25.1.jar -H:Name=/layers/paketo-buildpacks_native-image/native-image/com.mercedesbenz.blueprint.Application -cp ...

In last line Datadog argument is included (-J-javaagent:/layers/paketo-buildpacks_datadog/datadog-agent-java/dd-java-agent-1.25.1.jar ).
Please see that native BP recognizes arguments added by Datadog:

[INFO]     [creator]     Paketo Buildpack for Native Image 5.12.7
...
[INFO]     [creator]         $BP_NATIVE_IMAGE_BUILD_ARGUMENTS       -J-javaagent:/layers/paketo-buildpacks_datadog/datadog-agent-java/dd-java-agent-1.25.1.jar  arguments to pass to the native-image command
...

Workaround

Configure Datadog argument manually:

 <BP_NATIVE_IMAGE_BUILD_ARGUMENTS>-O0 -J-Xmx7g -J-javaagent:/layers/paketo-buildpacks_datadog/datadog-agent-java/dd-java-agent-1.25.1.jar</BP_NATIVE_IMAGE_BUILD_ARGUMENTS>

unfortunately this workaround will fail after Datadog BP upgrades agent version

Motivations

We want to use Native, Datadog and custom arguments in the same time due to need to change default native-build memory settings, disable optimizations etc.

Allow --exclude-config arguments to be specified inside jar

Describe the Enhancement

Currently --exclude-config arguments can be specified in BP_NATIVE_IMAGE_BUILD_ARGUMENTS in order to pass a list of configurations that should be excluded during native image creation. Spring Boot is working on native image support and would like a way to define --exclude-config arguments inside the JAR file. This will allow a jar file to describe completely how it should be converted into a native image.

Possible Solution

During creation of the JAR file, Spring Boot can add a META-INF/native-image/exclude-config-args file containing the --exclude-config arguments that it would like added. For example:

\Qfirst-library.jar\E ^/META-INF/native-image/.*
\Qsecond-library.jar\E ^/META-INF/native-image/.*

The file would consist of one line per --exclude-config argument. The example above would result in the following being passed to the native-image command line:

--exclude-config \Qfirst-library.jar\E ^/META-INF/native-image/.* --exclude-config \Qsecond-library.jar\E ^/META-INF/native-image/.*

Motivation

Graal provides a reachability-metadata repository that contains JSON files that allow third-party libraries to work. Spring Boot is looking to use this repository to bundle appropriate JSON files from the repository into the fat jar that it creates. We hope to achieve this by configuring the native-build-tools plugin so that it directly packages the appropriate JSON files. An enhancement request for native-build-tools is currently under review.

For most libraries, adding the metadata will be enough to create a fully functioning native image, however, some need to use "overrides". The override flag allows the metadata repository to override hints that are packaged inside the library jar itself. It can be used when a library ships incorrect meta-data that later needs to be corrected.

When the native-build-tools plugin is being used directly to create the image it is able to construct appropriate --exclude-config arguments. For example, this is how the Maven plugin generates the arguments. We need an equivalent option for use with buildpacks and unfortunately we can use --exclude-config in the Args property under META-INF/native-image/native-image.properties.

For more background and discussion please see spring-projects/spring-boot#31782

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.