gluonhq / gluonfx-maven-plugin

Plugin that simplifies creating native images for Java/JavaFX maven projects
BSD 3-Clause "New" or "Revised" License
186 stars 38 forks source link

compile step fails if JAVA_TOOL_OPTIONS is set #471

Open i-thiemann opened 1 year ago

i-thiemann commented 1 year ago

During compile step an exception is thrown if the JAVA_TOOL_OPTIONS environment variable is set. On my local system the workaround is to not set the environment variable, but I am also trying to automate my build with Jenkins where the agent injects JAVA_TOOL_OPTIONS for the workspace.

Log Output Excerpt with Exception:

> 16:35:12  [INFO] --- gluonfx-maven-plugin:1.0.18:compile (default-cli) @ project ---
> 16:35:13  java.io.IOException: Couldn't determine GraalVM's Java version for Picked up JAVA_TOOL_OPTIONS: -Dmaven.ext.class.path="/work/workspace/project/master@tmp/withMavena620dbb9/pipeline-maven-spy.jar" -Dorg.jenkinsci.plugins.pipeline.maven.reportsFolder="/work/workspace/project/master@tmp/withMavena620dbb9" 
> 16:35:13      at com.gluonhq.substrate.model.InternalProjectConfiguration.getGraalVMJavaVersion(InternalProjectConfiguration.java:674)
> 16:35:13      at com.gluonhq.substrate.model.InternalProjectConfiguration.checkGraalVMJavaVersion(InternalProjectConfiguration.java:490)
> 16:35:13      at com.gluonhq.substrate.SubstrateDispatcher.<init>(SubstrateDispatcher.java:382)
> 16:35:13      at com.gluonhq.NativeBaseMojo.createSubstrateDispatcher(NativeBaseMojo.java:173)
> 16:35:13      at com.gluonhq.NativeCompileMojo.execute(NativeCompileMojo.java:53)
> 16:35:13      at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:137)
> 16:35:13      at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:210)
> 16:35:13      at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:156)
> 16:35:13      at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:148)
> 16:35:13      at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:117)
> 16:35:13      at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:81)
> 16:35:13      at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:56)
> 16:35:13      at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:128)
> 16:35:13      at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:305)
> 16:35:13      at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:192)
> 16:35:13      at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:105)
> 16:35:13      at org.apache.maven.cli.MavenCli.execute(MavenCli.java:972)
> 16:35:13      at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:293)
> 16:35:13      at org.apache.maven.cli.MavenCli.main(MavenCli.java:196)
> 16:35:13      at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> 16:35:13      at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
> 16:35:13      at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
> 16:35:13      at java.base/java.lang.reflect.Method.invoke(Method.java:568)
> 16:35:13      at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:282)
> 16:35:13      at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:225)
> 16:35:13      at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:406)
> 16:35:13      at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:347)

The reason for this exception seems to be that the getGraalVMJavaVersion method always only evaluates the first line of the output of the java -version command, but if JAVA_TOOL_OPTIONS (this also applies to _JAVA_OPTIONS) environment variables are set, the "Picked up JAVA_TOOL_OPTIONS" message will be the first line of the reply.