openrewrite / rewrite

Automated mass refactoring of source code.
https://docs.openrewrite.org
Apache License 2.0
2.19k stars 329 forks source link

Quickstarts fails (straight out the gate) with JDK 11 #2342

Closed ge0ffrey closed 1 year ago

ge0ffrey commented 1 year ago

When I follow the quickstart https://docs.openrewrite.org/getting-started/getting-started and git clone https://github.com/openrewrite/spring-petclinic-migration.git

I run into two problems:

./mvnw clean install
...
[ERROR] Failed to execute goal org.codehaus.mojo:cobertura-maven-plugin:2.7:clean (default) on project spring-petclinic: Execution default of goal org.codehaus.mojo:cobertura-maven-plugin:2.7:clean failed: Plugin org.codehaus.mojo:cobertura-maven-plugin:2.7 or one of its dependencies could not be resolved: Could not find artifact com.sun:tools:jar:0 at specified path /home/.../.sdkman/candidates/java/11.0.14-tem/../lib/tools.jar -> [Help 1]
./mvnw rewrite:run -Drewrite.activeRecipes=org.openrewrite.java.format.AutoFormat
...
[ERROR] Failed to execute goal ro.isdc.wro4j:wro4j-maven-plugin:1.8.0:run (default) on project spring-petclinic: Execution default of goal ro.isdc.wro4j:wro4j-maven-plugin:1.8.0:run failed: An API incompatibility was encountered while executing ro.isdc.wro4j:wro4j-maven-plugin:1.8.0:run: java.lang.ExceptionInInitializerError: null
tkvangorder commented 1 year ago

@ge0ffrey

Thanks for reporting.

See the first warning in step 1:

You must run maven with a java 8 SDK.

jkschneider commented 1 year ago

We should consider moving away from Spring Petclinic as the example, since it requires the extra step of using JDK 8 which is becoming increasingly unlikely to be installed on a dev machine.

timtebeek commented 1 year ago

I'm also updating my write up here for Foojay, but keeping the Java 8 in there; with SDKMan instructions to make it easy to run multiple versions. That version also does not use the openrewrite/spring-petclinic, so might be more familiar to users.

Missed you at Devoxx @ge0ffrey ; were you looking to continue the demo you saw there perhaps? That one's here.

ge0ffrey commented 1 year ago

@timtebeek I heard good things about the devoxx talk, but missed it myself. I saw a good talk mention it on Thursday - this project looks wonderful! Happy to meet up sometime. I am based out of Gent.

I tried JDK 17 too, which runs into the same issue. As for requiring JDK 8 for the quickstart... that's... unsettling. Having sdkman already installed, it somehow feels very dirty to type "sdk install java 8.0.322-tem". No, I can't. It's almost Halloween. I got two rules around Halloween: Don't stay boogieman 3 times. And don't install a Java version older than Java 11. Too dangerous. Who knows what happens if we start writing such incantations?

ge0ffrey commented 1 year ago

This works like a charm on a newly generated quarkus project (and probably for new spring boot project too), with JDK 17:

./mvnw org.openrewrite.maven:rewrite-maven-plugin:4.36.0:run -Drewrite.activeRecipes=org.openrewrite.java.format.AutoFormat
timtebeek commented 1 year ago

@timtebeek I heard good things about the devoxx talk, but missed it myself. I saw a good talk mention it on Thursday - this project looks wonderful! Happy to meet up sometime. I am based out of Gent.

Cool yes Marit and I did some cross-promotion; good to hear you enjoyed hers as well. Would be fun to meet up again; it's been a while since our dinner at Devoxx Poland. Are you presenting at JavaLand early next year?

I tried JDK 17 too, which runs into the same issue. As for requiring JDK 8 for the quickstart... that's... unsettling. Having sdkman already installed, it somehow feels very dirty to type "sdk install java 8.0.322-tem". No, I can't. It's almost Halloween. I got two rules around Halloween: Don't stay boogieman 3 times. And don't install a Java version older than Java 11. Too dangerous. Who knows what happens if we start writing such incantations?

Understandable that you'd prefer 11+, but you can't run this 1.5.x branch of spring-projects/spring-petclinic without Java 8 at least temporarily. :) Luckily it's just two quick commands to switch to Spring Boot 2.7 & Java 17:

./mvnw org.openrewrite.maven:rewrite-maven-plugin:4.36.0:run \
  -Drewrite.recipeArtifactCoordinates=org.openrewrite.recipe:rewrite-spring:4.29.0 \
  -DactiveRecipes=org.openrewrite.java.spring.boot2.SpringBoot1To2Migration

./mvnw org.openrewrite.maven:rewrite-maven-plugin:4.36.0:run \
  -Drewrite.recipeArtifactCoordinates=org.openrewrite.recipe:rewrite-migrate-java:1.13.0 \
  -DactiveRecipes=org.openrewrite.java.migrate.UpgradeJava17

That's the extremely short version of the quickstart & blogpost. And you can explore & run other recipes in the same way as well. We even have a few on Quarkus that I think you'll enjoy.

ge0ffrey commented 1 year ago

Thank you Tim :)

traceyyoshima commented 1 year ago

Quick update: The 1.5x branch has been updated to Java 11 with SpringBoot 2.1.x.

traceyyoshima commented 1 year ago

Hi @ge0ffrey, thank you for reporting the issue -- we've updated the getting started example of pet clinic to Java 11 using SpringBoot 2.1.x.

Does the change resolve your issue?

traceyyoshima commented 1 year ago

Closing the issue due to inactivity - pet clinic has been upgraded to SpringBoot 2.1.x with Java 11.