graalvm / native-build-tools

Native-image plugins for various build tools
https://graalvm.github.io/native-build-tools/
Other
366 stars 57 forks source link

Add a parameter to be able to skip build native for pom type modules, leave it as false per default for backward compat #593

Closed olamy closed 4 months ago

olamy commented 5 months ago

When using in a multi module Apache Maven build, the plugin can cause some issues for pom type project. Such

[ERROR] Failed to execute goal org.graalvm.buildtools:native-maven-plugin:0.10.1:compile-no-fork (build-native) on project jetty-project: Image classpath is empty. Check if your classpath configuration is correct. -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.graalvm.buildtools:native-maven-plugin:0.10.1:compile-no-fork (build-native) on project jetty-project: Image classpath is empty. Check if your classpath configuration is correct.
    at org.apache.maven.lifecycle.internal.MojoExecutor.doExecute2 (MojoExecutor.java:333)
    at org.apache.maven.lifecycle.internal.MojoExecutor.doExecute (MojoExecutor.java:316)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:212)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:174)
    at org.apache.maven.lifecycle.internal.MojoExecutor.access$000 (MojoExecutor.java:75)
    at org.apache.maven.lifecycle.internal.MojoExecutor$1.run (MojoExecutor.java:162)
    at org.apache.maven.buildcache.BuildCacheMojosExecutionStrategy.execute (BuildCacheMojosExecutionStrategy.java:145)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:159)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:105)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:73)
    at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:53)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:118)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:261)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:173)
    at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:101)
    at org.apache.maven.cli.MavenCli.execute (MavenCli.java:906)
    at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:283)
    at org.apache.maven.cli.MavenCli.main (MavenCli.java:206)
    at jdk.internal.reflect.DirectMethodHandleAccessor.invoke (DirectMethodHandleAccessor.java:103)
    at java.lang.reflect.Method.invoke (Method.java:580)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:283)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:226)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:407)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:348)
Caused by: org.apache.maven.plugin.MojoExecutionException: Image classpath is empty. Check if your classpath configuration is correct.
    at org.graalvm.buildtools.maven.AbstractNativeImageMojo.getClasspath (AbstractNativeImageMojo.java:394)
    at org.graalvm.buildtools.maven.AbstractNativeImageMojo.getBuildArgs (AbstractNativeImageMojo.java:192)
    at org.graalvm.buildtools.maven.AbstractNativeImageMojo.buildImage (AbstractNativeImageMojo.java:408)
    at org.graalvm.buildtools.maven.NativeCompileNoForkMojo.execute (NativeCompileNoForkMojo.java:96)

See some details here https://github.com/jetty/jetty.project/issues/11683

oracle-contributor-agreement[bot] commented 5 months ago

Thank you for your pull request and welcome to our community! To contribute, please sign the Oracle Contributor Agreement (OCA). The following contributors of this PR have not signed the OCA:

To sign the OCA, please create an Oracle account and sign the OCA in Oracle's Contributor Agreement Application.

When signing the OCA, please provide your GitHub username. After signing the OCA and getting an OCA approval from Oracle, this PR will be automatically updated.

If you are an Oracle employee, please make sure that you are a member of the main Oracle GitHub organization, and your membership in this organization is public.

olamy commented 5 months ago

no idea what to do to sign the OCA.... I have an account with the email used to sign this commit. I can connect to my oracle but now when I want to sign the OCA, I get this

Screenshot from 2024-04-28 16-26-43

Please contact but there is no link provided.

fniephaus commented 5 months ago

Hi @olamy, thanks for the PR. Maybe @alina-yur can help us find out what's going on with the OCA portal. In the meantime, could you maybe extend the description of the PR a bit and make it clear why this is needed and what problem this solves? Thank you! :)

alina-yur commented 5 months ago

hi @olamy! Thank you for reporting, I passed your message to the OCA team. In the meantime, can you please try again (and ideally from a different browser), maybe it was a one-time glitch?

olamy commented 5 months ago

@alina-yur @fniephaus all good. I tried again and it works. Thanks

oracle-contributor-agreement[bot] commented 5 months ago

Thank you for signing the OCA.

alina-yur commented 5 months ago

@olamy your OCA is now approved. happy contributing :)

joakime commented 4 months ago

Why do you need yet another skip parameter? Is skipNativeBuild not enough?

Using that in a sub-module would also make the sub-sub-modules skip native, which is not what we want. Skipping by packaging type is more appropriate with maven than a global skip option like skipNativeBuild.

Btw, just so you know, @olamy is a committer on the Apache Maven project itself, and is involved in countless maven plugin projects around the maven ecosystem. I trust his experience when it comes to proper maven plugin behavior and maintainability of both the maven plugin and the projects that use the maven plugin.

alvarosanchez commented 4 months ago

Using that in a sub-module would also make the sub-sub-modules skip native, which is not what we want. Skipping by packaging type is more appropriate with maven than a global skip option like skipNativeBuild.

Right, in that case I think the mojo should just simply skip execution for pom projects, without needing an extra parameter.

@olamy I understand your intention was to not introduce breaking changes, which I appreciate, but we can probably regard this issue as a bug, in which case it's fine to do the change I proposed.

Btw, just so you know, @olamy is a committer on the Apache Maven project itself, and is involved in countless maven plugin projects around the maven ecosystem. I trust his experience when it comes to proper maven plugin behavior and maintainability of both the maven plugin and the projects that use the maven plugin.

Thanks for the heads-up. I didn't mean to question his skills at all. Mine was a pure question that, in retrospect, could have been written differently. Sorry if it sounded too harsh, not my intention.

joakime commented 4 months ago

Using that in a sub-module would also make the sub-sub-modules skip native, which is not what we want. Skipping by packaging type is more appropriate with maven than a global skip option like skipNativeBuild.

Right, in that case I think the mojo should just simply skip execution for pom projects, without needing an extra parameter.

There are many maven plugins that simply hardcode skipping of a project if it has no source, the easiest way is to skip pom packaging projects, others take a holistic approach and ask the Project if any sources have been attached (eg: extracted from another dependency via the maven-dependency-plugin and then attached as source for compilation into non-default artifacts,, even though the project is pom packaging).

This second approach also helps with nonstandard project packaging types (eg: bundle, resource, or any of a hundred other packaging types seen in the wild)

olamy commented 4 months ago

@alvarosanchez it looks @joakime explained perfectly why I choose this way of skipping :)

fniephaus commented 4 months ago

Thanks a lot for contributing and making clear why this is the right approach! :)