Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to derive a gradle based version of the public-static-main native-image maven sample #276

Open
lestephane opened this issue Mar 18, 2022 · 3 comments
Labels
question Further information is requested

Comments

@lestephane
Copy link

I started from the public-static-main sample, removed the maven project file, and used instead:

build.gradle.kts

plugins {
    `java-library`
}

tasks.jar {
    manifest {
        attributes["Main-Class"] = "io.paketo.App"
    }
}

gradle-wrapper.properties

distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4.1-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists

Pack command + Output

$ pack build --builder paketobuildpacks/builder:tiny --env BP_NATIVE_IMAGE=true public-static-main:gradle
...
Downloading from https://download.bell-sw.com/vm/22.0.0.2/bellsoft-liberica-vm-core-openjdk11-22.0.0.2-linux-amd64.tar.gz
...
Downloading https://services.gradle.org/distributions/gradle-7.4.1-bin.zip
...
Daemon will be stopped at the end of the build 
      > Task :compileJava
      > Task :processResources NO-SOURCE
      > Task :classes
      > Task :jar
      > Task :assemble
      
      BUILD SUCCESSFUL in 36s
      2 actionable tasks: 2 executed
...
Paketo Native Image Buildpack 5.2.0
  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
    GraalVM 22.0.0.2 Java 11 CE (Java Version 11.0.14.1+1-LTS)
    Executing native-image -H:+StaticExecutableWithDynamicLibC -jar /workspace
Error: /workspace is a directory. (-jar requires a valid jarfile)
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

There's too much magic going on, and I have absolutely no idea whether I'm doing something wrong, or whether what I'm trying to do is unsupported.

Can you provide a working example for native-image + gradle?

@lestephane lestephane changed the title Unable to derive a java-native-image gradle project from the maven sample Unable to derive a java-native-image gradle project from the public-static-main maven sample Mar 18, 2022
@lestephane lestephane changed the title Unable to derive a java-native-image gradle project from the public-static-main maven sample Unable to derive a gradle based version of the public-static-main native-image maven sample Mar 18, 2022
@fg-j
Copy link

fg-j commented Mar 21, 2022

@paketo-buildpacks/java-buildpacks can you perhaps offer an example to help this user?

@dmikusa
Copy link
Contributor

dmikusa commented Mar 21, 2022

@lestephane - Can you include the full output of your build? The error is because something is missing from the output (it seems like it can't find a JAR file) of running the Gradle build. I can't see that output though, so I'm not totally sure what's happened.

Also, you may want to try with this setting and see if that helps: https://github.com/paketo-buildpacks/samples/blob/main/java/gradle/build.gradle#L11-L13 We use that with the Boot demos because they produce two JAR files, the Boot executable JAR and a regular JAR. This suppresses the regular JAR. Not sure if your app is a Boot app or not, but maybe worth a try.

@dmikusa dmikusa added the question Further information is requested label Mar 21, 2022
@dmikusa
Copy link
Contributor

dmikusa commented Mar 21, 2022

Maybe also helpful for us to understand. What do you get when you gradle assemble locally? With the Maven version, when you mvn package you get an output executable JAR. The example works because there is an executable JAR produced.

Buildpacks are just a pipeline of actions which get performed, so the output of Gradle running gets fed into the input of the next step which is native image running. The native image command is expecting a JAR, but not finding one which is why it fails. Verifying that gradle assemble produces an executable JAR would help to verify the input to native image. Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants