rewrite-migrate-java icon indicating copy to clipboard operation
rewrite-migrate-java copied to clipboard

Include adding javafx dependencies with JDK17 upgrade recipe

Open Kushank24 opened this issue 1 year ago • 5 comments

What problem are you trying to solve?

I am running the JDK17 update recipe. But once the recipe is run and I am trying to test it out I am getting the following error:

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.7.0:compile (default-compile) on project topology: Compilation failure: Compilation failure:
[ERROR] package javafx.util does not exist
[ERROR] package javafx.util does not exist
[ERROR] cannot find symbol
[ERROR] symbol: class Pair
[ERROR] location: class 

Describe the solution you'd like

The solution should be incorporated in the JDK17 upgrade recipe only so that the solution automatically gets remdified.

Have you considered any alternatives or workarounds?

Tried using java.util.Map.Entry but also some in that sense i needed to change the user code

Kushank24 avatar May 03 '24 10:05 Kushank24

Thanks for logging an issue! As discussed on Slack there's likely a couple changes we'd need to make for JavaFX projects adopting Java 17; would you mind breaking down those changes a bit in this issue? Things like adding a dependency, changing packages or classes, or switching to a different runtime. That way we're better able to start codifying such changes as recipes.

timtebeek avatar May 03 '24 10:05 timtebeek

Thanks for your prompt reply Tim. These are the following changes which I observed which needs to be incorporated to used javafx with Java 17:

  1. The platform no longer contains as part of the specification, and most JDK builds have removed it, thus an alternate way of using it is to add the dependencies to the project.
  2. Another workaround is to use java.util.Map.Entry or org.apache.commons.lang3.tuple but in that case also complete functionality is not available
  3. Liberica Full with LibericaFX, an open-source implementation of JavaFX can also be used for solving this. But all these requires specifc changes that needs to be done based on the scenario being decided.

Kushank24 avatar May 03 '24 15:05 Kushank24

I think adding the required dependencies is the most straightforward way we can keep supporting JavaFX if that's used.

If folks only use one or two classes (such as Pair here), then it might make sense to use ChangeType instead to an alternative.

timtebeek avatar May 03 '24 16:05 timtebeek

Yeah correct Tim. I resolved the issue by adding the following dependencies in the parent pom:

<dependency>
 <groupId>org.openjfx</groupId>
 <artifactId>javafx-base</artifactId>
 <version>17.0.7</version>
</dependency>
<dependency>
 <groupId>org.openjfx</groupId>
 <artifactId>javafx-controls</artifactId>
 <version>17.0.7</version>
</dependency>
<dependency>
 <groupId>org.openjfx</groupId>
 <artifactId>javafx-fxml</artifactId>
 <version>17.0.7</version>
</dependency>

And it worked.

Kushank24 avatar May 06 '24 18:05 Kushank24

Looks like those could be added with a declarative recipe if needed. That would then close out this issue for folks similarly migrating. Is that something you'd want to contribute?

timtebeek avatar Aug 12 '24 16:08 timtebeek