Skip to content

proper toolchain support #118

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

Merged
merged 3 commits into from
Apr 9, 2021
Merged

proper toolchain support #118

merged 3 commits into from
Apr 9, 2021

Conversation

tbee
Copy link
Contributor

@tbee tbee commented Mar 27, 2021

Fix #124

@jperedadnr
Copy link
Collaborator

Please, can you create an issue that justifies this PR, describing what is failing and what this PR solves?

@tbee
Copy link
Contributor Author

tbee commented Apr 5, 2021

This is not as much a problem solving as it is an improvement; the plugin did not support toolchains (even though the source code suggested this: getLog().debug("Toolchains are ignored, 'executable' parameter is set to " + executable) ).

However, what can fail is that the compiler plugin can use a different JDK from the javafx:run. The compiler has a pretty complex determine-the-javac logic, while this plugin simply uses the java.exe on the system path. This manifested itself when I ran "clean javafx:run" from Eclipse; maven was ran with Java 15 (as configured in Eclipse), while javafx:run used Java 11 (which was used to start Eclipse). So I got a class version exception.

You can set the executable manually, but that would mean hardcoding or some variable. I solved this by making my pom toolschain aware.

@tbee
Copy link
Contributor Author

tbee commented Apr 9, 2021

Issue 124

@abhinayagarwal
Copy link
Collaborator

Hi @tbee ,

Thank you for this PR.

I applied this patch and build a new plugin version. However, it doesn't resolve the issue. Can you please guide me through the process?

Here are the steps I followed to test:

  1. Update the Maven project to use JDK 15 instead of the default JDK 11
  2. Maven uses JDK 15, however, the javafx-maven-plugin still seems to be using the default JDK 11 to run the project
  3. Plugin still reports Toolchain to be null: [INFO] Toolchain in javafx-maven-plugin null

Debug log (snipped):

Apache Maven 3.6.3 (cecedd343002696d0abb50b32b541b8a6ba2883f)
Maven home: /home/abhinay/Documents/git/samples/HelloFX/Maven/hellofx/EMBEDDED
Java version: 15, vendor: Oracle Corporation, runtime: /usr/lib/jvm/jdk-15
Default locale: en_GB, platform encoding: UTF-8
OS name: "linux", version: "5.4.0-70-generic", arch: "amd64", family: "unix"
....
[DEBUG] Configuring mojo 'org.openjfx:javafx-maven-plugin:0.0.6-SNAPSHOT:run' with basic configurator -->
...
[DEBUG] -- end configuration --
[INFO] Toolchain in javafx-maven-plugin null
...

@tbee
Copy link
Contributor Author

tbee commented Apr 9, 2021

You need to configure Maven toolchains.
https://maven.apache.org/guides/mini/guide-using-toolchains.html

  1. Create the toolchains.xml file
    The easiest way to do that, if you use sdkman and jbang, is to run my jbang script: jbang sdkman@tbee/mavenToolchains
    See https://github.com/tbee/mavenToolchains/blob/main/GenerateToolchainsFromSDKMAN.java
    It will generate the ~.m2/toolchains.xml from the installed JDK's.

  2. Define in your pom in the toolchains-plugin that JDK 15 is to be used

  <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-toolchains-plugin</artifactId>
    <version>3.0.0</version>
    <executions>
      <execution>
        <goals>
          <goal>toolchain</goal>
        </goals>
      </execution>
    </executions>
    <configuration>
      <toolchains>
        <jdk>
          <version>15</version>
        </jdk>
      </toolchains>
    </configuration>
  </plugin>

Now the compiler and javafx:run will use the same jdk.

@abhinayagarwal
Copy link
Collaborator

Hi @tbee,

Alright. This works!

However, there is still this manual configuration that the user has to do by setting the toolchain plugin. Is it possible for javafx-maven-plugin to directly use the JDK set by the user in the Eclipse project configuration, just like the maven-compiler-plugin does?

@tbee
Copy link
Contributor Author

tbee commented Apr 9, 2021

This PR is about adding toolchains support to the plugin.

I did take a look at copying the whole javac detection logic from the compiler plugin, but that is not quite trivial. In the end toolchains is the formal way to support these overarching tool concerns: The Maven Toolchains provide a way for plugins to discover what JDK (or other tools) are to be used during the build, without the need to configure them in each plugin nor in every pom.xml.
https://maven.apache.org/guides/mini/guide-using-toolchains.html

That said, I could take a peek if I can get the non-toolchain behavior closer to that of the compiler-plugin.

@abhinayagarwal
Copy link
Collaborator

abhinayagarwal commented Apr 9, 2021

Sounds great! This PR is good in its current state.

`I will file a new issue for the "non-toolchain behavior" so that it can be tracked. Filed #125

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

Successfully merging this pull request may close these issues.

javafx-maven-plugin does not really support toolchains
3 participants