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

Change javac executable used by quarkus-maven-plugin #39129

Open
w0pp opened this issue Mar 2, 2024 · 3 comments
Open

Change javac executable used by quarkus-maven-plugin #39129

w0pp opened this issue Mar 2, 2024 · 3 comments
Labels
area/maven good first issue Good for newcomers kind/enhancement New feature or request

Comments

@w0pp
Copy link
Contributor

w0pp commented Mar 2, 2024

Description

There is currently no way to change the JDK used by quarkus-maven-plugin, which is an annoyance for developers that have to switch between projects using different JDK versions.
Usually we would do one of these two things to specify the path to the JDK the project should use:

  • change the <executable> in maven-compiler-plugin's <configuration> to point to something like ${JAVA_17_HOME}/bin/javac
  • use a Maven toolchain

However, none of these approaches work for Quarkus projects, since they don't have any effect on quarkus-maven-plugin. We now have to resort to manually changing the JAVA_HOME environment variable before executing with Maven, or to automatically changing it inside the Maven wrapper script. The latter approach is not ideal because JAVA_HOME stays changed even after the Maven command has finished, and it doesn't work if the developer uses mvn instead of mvnw.

It would be great if we could set a custom path to the javac executable used by quarkus-maven-plugin. Support for toolchains would also be awesome, but I think that's already tracked in this issue: #12943

Implementation ideas

Add an <executable> property to quarkus-maven-plugin's <configuration> section

@w0pp w0pp added the kind/enhancement New feature or request label Mar 2, 2024
@quarkus-bot
Copy link

quarkus-bot bot commented Mar 2, 2024

/cc @quarkusio/devtools (maven)

@gastaldi gastaldi added the good first issue Good for newcomers label Mar 2, 2024
@gastaldi
Copy link
Contributor

gastaldi commented Mar 2, 2024

Sounds like a good first issue, want to submit a PR?

@w0pp
Copy link
Contributor Author

w0pp commented Mar 2, 2024

I gave it a shot, assuming that it would be as easy as adding a new property for the executable path and passing it to the MavenDevModeLauncher.Builder, just like compilerArgs. But it seems like the problem actually lies in GenerateCodeMojo, and I have no idea how to go about making it use a different Java path. It would probably require some major changes.
There's also this line that scared me:
<!-- Not sure exactly why but the Maven plugins need to be compiled with Java 11 -->

I don't think this is a good first issue but would instead require someone quite familiar with developing Maven plugins and Quarkus code generation, which I am definitely not.

For anyone deciding to look into this, here's the stack trace I get when running mvnw clean package with JAVA_HOME set to jdk11 and the project requiring jdk17, with maven-compiler-plugin's <executable> property set to jdk17 javac:

[INFO] Scanning for projects...
[WARNING] ClassRealm[extension>io.quarkus.platform:quarkus-maven-plugin:3.8.1, parent: java.net.URLClassLoader@2c9f9fb0]
com.google.inject.CreationException: Unable to create injector, see the following errors:

1) [Guice/MissingImplementation]: No implementation for QuarkusBootstrapProvider annotated with interface TypeArguments$Implicit was bound.

Did you mean?
    QuarkusBootstrapProvider bound at LocatorWiring

Requested by:
1  : LocatorWiring

Learn more:
  https://github.com/google/guice/wiki/MISSING_IMPLEMENTATION

1 error

======================
Full classname legend:
======================
LocatorWiring:            "org.eclipse.sisu.wire.LocatorWiring"
QuarkusBootstrapProvider: "io.quarkus.maven.QuarkusBootstrapProvider"
TypeArguments$Implicit:   "org.eclipse.sisu.inject.TypeArguments$Implicit"
========================
End of classname legend:
========================

    at com.google.inject.internal.Errors.throwCreationExceptionIfErrorsExist (Errors.java:576)
    at com.google.inject.internal.InternalInjectorCreator.initializeStatically (InternalInjectorCreator.java:163)
    at com.google.inject.internal.InternalInjectorCreator.build (InternalInjectorCreator.java:110)
    at com.google.inject.Guice.createInjector (Guice.java:87)
    at com.google.inject.Guice.createInjector (Guice.java:69)
    at com.google.inject.Guice.createInjector (Guice.java:59)
    at org.codehaus.plexus.DefaultPlexusContainer.addPlexusInjector (DefaultPlexusContainer.java:482)
    at org.codehaus.plexus.DefaultPlexusContainer.discoverComponents (DefaultPlexusContainer.java:461)
    at org.apache.maven.plugin.internal.DefaultMavenPluginManager.discoverPluginComponents (DefaultMavenPluginManager.java:410)
    at org.apache.maven.plugin.internal.DefaultMavenPluginManager.setupExtensionsRealm (DefaultMavenPluginManager.java:804)
    at org.apache.maven.project.DefaultProjectBuildingHelper.createProjectRealm (DefaultProjectBuildingHelper.java:177)
    at org.apache.maven.project.DefaultModelBuildingListener.buildExtensionsAssembled (DefaultModelBuildingListener.java:92)
    at org.apache.maven.model.building.ModelBuildingEventCatapult$1.fire (ModelBuildingEventCatapult.java:40)
    at org.apache.maven.model.building.DefaultModelBuilder.fireEvent (DefaultModelBuilder.java:1269)
    at org.apache.maven.model.building.DefaultModelBuilder.build (DefaultModelBuilder.java:474)
    at org.apache.maven.model.building.DefaultModelBuilder.build (DefaultModelBuilder.java:455)
    at org.apache.maven.project.DefaultProjectBuilder.build (DefaultProjectBuilder.java:612)
    at org.apache.maven.project.DefaultProjectBuilder.build (DefaultProjectBuilder.java:375)
    at org.apache.maven.graph.DefaultGraphBuilder.collectProjects (DefaultGraphBuilder.java:349)
    at org.apache.maven.graph.DefaultGraphBuilder.getProjectsForMavenReactor (DefaultGraphBuilder.java:340)
    at org.apache.maven.graph.DefaultGraphBuilder.build (DefaultGraphBuilder.java:76)
    at org.apache.maven.DefaultMaven.buildGraph (DefaultMaven.java:448)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:197)
    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.NativeMethodAccessorImpl.invoke0 (Native Method)
    at jdk.internal.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62)
    at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke (Method.java:566)
    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)
    at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
    at jdk.internal.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62)
    at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke (Method.java:566)
    at org.apache.maven.wrapper.BootstrapMainStarter.start (BootstrapMainStarter.java:52)
    at org.apache.maven.wrapper.WrapperExecutor.execute (WrapperExecutor.java:161)
    at org.apache.maven.wrapper.MavenWrapperMain.main (MavenWrapperMain.java:73)


[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  3.879 s
[INFO] Finished at: 2024-03-02T20:39:51+01:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal io.quarkus.platform:quarkus-maven-plugin:3.8.1:generate-code (default) on project backend: Execution default of goal io.quarkus.platform:quarkus-maven-plugin:3.8.1:generate-code failed: Unable to load the mojo 'generate-code' (or one of its required components) from the plugin 'io.quarkus.platform:quarkus-maven-plugin:3.8.1': java.util.NoSuchElementException
[ERROR]       role: org.apache.maven.plugin.Mojo
[ERROR]   roleHint: io.quarkus.platform:quarkus-maven-plugin:3.8.1:generate-code
[ERROR] -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/PluginContainerException

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/maven good first issue Good for newcomers kind/enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants