openrewrite / rewrite-migrate-java

OpenRewrite recipes for migrating to newer versions of Java.
Apache License 2.0
92 stars 65 forks source link

Include adding javafx dependencies with JDK17 upgrade recipe #472

Open Kushank24 opened 2 months ago

Kushank24 commented 2 months ago

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

timtebeek commented 2 months ago

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.

Kushank24 commented 2 months ago

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.
timtebeek commented 2 months ago

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.

Kushank24 commented 2 months ago

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.