findepi / graalvm-docker

Apache License 2.0
28 stars 9 forks source link

Add export of JAVA_HOME #13

Closed mihael97 closed 1 year ago

mihael97 commented 1 year ago

Hello!

During native build compilation inside CI/CD, I need to manually add the JAVA_HOME export.

It would be helpful if the variable is exported by default. I am open to contributing to the implementation.

findepi commented 1 year ago

@mihael97 thanks for the feedback!

on the CI the native image is getting exercised with https://github.com/findepi/graalvm-docker/blob/master/bin/test-native.sh. Of course, this simplistic test doesn't need this env variable. Would you like to help me understand when it's needed? Would be good to have validation that things indeed work as expected.

mihael97 commented 1 year ago

Hi @findepi , below is a working example.

Without exported JAVA_HOME - failing:

Failed attempt ```bash ❯ docker run --rm --name example -it -v ${PWD}:/app -w /app findepi/graalvm:java17-all ./gradlew nativeCompile Downloading https://services.gradle.org/distributions/gradle-7.6-bin.zip ...........10%............20%...........30%............40%............50%...........60%............70%............80%...........90%............100% Welcome to Gradle 7.6! Here are the highlights of this release: - Added support for Java 19. - Introduced `--rerun` flag for individual task rerun. - Improved dependency block for test suites to be strongly typed. - Added a pluggable system for Java toolchains provisioning. For more details see https://docs.gradle.org/7.6/release-notes.html Starting a Gradle Daemon (subsequent builds will be faster) > Task :compileJava > Task :processResources > Task :classes > Task :resolveMainClassName > Task :processAot . ____ _ __ _ _ /\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \ ( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \ \\/ ___)| |_)| | | | | || (_| | ) ) ) ) ' |____| .__|_| |_|_| |_\__, | / / / / =========|_|==============|___/=/_/_/_/ :: Spring Boot :: (v3.0.2) 2023-02-16T18:35:56.568Z INFO 226 --- [ main] mihael.macuka.mail.server.Application : Starting Application using Java 17.0.6 with PID 226 (/app/build/classes/java/main started by root in /app) 2023-02-16T18:35:56.573Z INFO 226 --- [ main] mihael.macuka.mail.server.Application : No active profile set, falling back to 1 default profile: "default" > Task :compileAotJava Note: /app/build/generated/aotSources/org/springframework/boot/autoconfigure/web/servlet/WebMvcAutoConfiguration__BeanDefinitions.java uses or overrides a deprecated API. Note: Recompile with -Xlint:deprecation for details. > Task :processAotResources > Task :aotClasses > Task :jar > Task :generateResourcesConfigFile [native-image-plugin] Resources configuration written into /app/build/native/generated/generateResourcesConfigFile/resource-config.json > Task :nativeCompile FAILED FAILURE: Build failed with an exception. * What went wrong: Execution failed for task ':nativeCompile'. > Cannot query the value of property 'javaLauncher' because it has no value available. * Try: > Run with --stacktrace option to get the stack trace. > Run with --info or --debug option to get more log output. > Run with --scan to get full insights. * Get more help at https://help.gradle.org BUILD FAILED in 1m 2s 9 actionable tasks: 9 executed ```

But, with exported JAVA_HOME, everything works and the application is compiled successfully.

Successfull attempt ```bash ❯ docker run --rm --name example -it -v ${PWD}:/app -e JAVA_HOME=/graalvm -w /app findepi/graalvm:java17-all ./gradlew nativeCompile Downloading https://services.gradle.org/distributions/gradle-7.6-bin.zip ...........10%............20%...........30%............40%............50%...........60%............70%............80%...........90%............100% Welcome to Gradle 7.6! Here are the highlights of this release: - Added support for Java 19. - Introduced `--rerun` flag for individual task rerun. - Improved dependency block for test suites to be strongly typed. - Added a pluggable system for Java toolchains provisioning. For more details see https://docs.gradle.org/7.6/release-notes.html Starting a Gradle Daemon (subsequent builds will be faster) > Task :compileJava UP-TO-DATE > Task :processResources UP-TO-DATE > Task :classes UP-TO-DATE > Task :resolveMainClassName UP-TO-DATE > Task :processAot UP-TO-DATE > Task :compileAotJava UP-TO-DATE > Task :processAotResources UP-TO-DATE > Task :aotClasses UP-TO-DATE > Task :jar UP-TO-DATE > Task :generateResourcesConfigFile UP-TO-DATE > Task :nativeCompile [native-image-plugin] GraalVM Toolchain detection is disabled [native-image-plugin] GraalVM location read from environment variable: JAVA_HOME [native-image-plugin] Native Image executable path: /graalvm/lib/svm/bin/native-image ======================================================================================================================== GraalVM Native Image: Generating 'mail.server' (executable)... ...more not important logs ```

I am trying to compile native image of Spring Boot(version 3.0.2) application

findepi commented 1 year ago

@mihael97 sorry for the delay here. Can you please confirm https://github.com/findepi/graalvm-docker/pull/14 is exactly what you need?

mihael97 commented 1 year ago

Hi @findepi , this looks OK and I think it will fix the issue. Thanks!

findepi commented 1 year ago

Thanks @mihael97 for confirming & once again thank you for reporting the issue!