quarkusio / quarkus

Quarkus: Supersonic Subatomic Java.
https://quarkus.io
Apache License 2.0
13.64k stars 2.64k forks source link

Quarkus update tool not working in gradle multimodule project #33014

Closed kyngs closed 1 month ago

kyngs commented 1 year ago

Describe the bug

When attempting to to run the update script via quarkus update --stream=3.0 the script fails with the following error:

kyngs@dada ~/D/C/G/P/Web-Backend (master)> quarkus update --stream=3.0
Starting a Gradle Daemon (subsequent builds will be faster)

> Task :Web-Backend:quarkusUpdate
quarkusUpdate is experimental, its options and output might change in future versions
Instructions to update this project from '2.11.1.Final' to '3.0.1.Final':

Recommended Quarkus platform BOM updates:
Update: io.quarkus.platform:quarkus-bom:pom:2.11.1.Final -> 3.0.1.Final

Resolved io.quarkus:quarkus-updates-recipes:1.0.1 with 1 recipe(s) to update from 2.11.1.Final to 3.0.1.Final (initially made for OpenRewrite GRADLE plugin version: 5.39.3) 
The update feature does not yet handle updates of the extension versions. If needed, update your extensions manually.

 ------------------------------------------------------------------------
Executing:
/home/kyngs/Documents/Code/GitHub/<redacted>/Web-Backend/gradlew --console plain --stacktrace --init-script /tmp/openrewrite-init8788081860581362177gradle rewriteRun

Starting a Gradle Daemon, 1 busy Daemon could not be reused, use --status for details

FAILURE: Build failed with an exception.

* Where:
Initialization script '/tmp/openrewrite-init8788081860581362177gradle' line: 23

* What went wrong:
Could not find method rewrite() for arguments [org.openrewrite:rewrite-java] on object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.

* Try:
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.

* Exception is:
org.gradle.internal.metaobject.AbstractDynamicObject$CustomMessageMissingMethodException: Could not find method rewrite() for arguments [org.openrewrite:rewrite-java] on object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.
        at org.gradle.internal.metaobject.AbstractDynamicObject$CustomMissingMethodExecutionFailed.<init>(AbstractDynamicObject.java:190)
        at org.gradle.internal.metaobject.AbstractDynamicObject.methodMissingException(AbstractDynamicObject.java:184)
        at org.gradle.internal.metaobject.ConfigureDelegate.invokeMethod(ConfigureDelegate.java:86)
        at openrewrite_init87880818605813_f34l0tq4eedrpzis5wgri4lpi$_run_closure1$_closure3.doCall(/tmp/openrewrite-init8788081860581362177gradle:23)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at org.gradle.util.internal.ClosureBackedAction.execute(ClosureBackedAction.java:72)
... hundreds of lines of stacktrace 

The Gradle plugin way also does not work (./gradlew -PquarkusPluginVersion=3.0.1.Final quarkusUpdate --stream=3.0)

Expected behavior

The script should update Quarkus to 3.0

Actual behavior

The script errors out with the exception above

How to Reproduce?

  1. Create a Gradle project
  2. Add a quarkus (2.x) module to it
  3. Attempt to update

Output of uname -a or ver

Linux dada 6.2.13-zen-1-zen #1 ZEN SMP PREEMPT_DYNAMIC Wed, 26 Apr 2023 20:49:44 +0000 x86_64 GNU/Linux

Output of java -version

openjdk version "17.0.7" 2023-04-18 OpenJDK Runtime Environment (build 17.0.7+7) OpenJDK 64-Bit Server VM (build 17.0.7+7, mixed mode)

GraalVM version (if different from Java)

Not applicable

Quarkus version or git rev

2.11.Final

Build tool (ie. output of mvnw --version or gradlew --version)

------------------------------------------------------------ Gradle 7.4.2 ------------------------------------------------------------ Build time: 2022-03-31 15:25:29 UTC Revision: 540473b8118064efcc264694cbcaa4b677f61041 Kotlin: 1.5.31 Groovy: 3.0.9 Ant: Apache Ant(TM) version 1.10.11 compiled on July 10 2021 JVM: 17.0.7 (Oracle Corporation 17.0.7+7) OS: Linux 6.2.13-zen-1-zen amd64

Additional information

No response

quarkus-bot[bot] commented 1 year ago

/cc @evanchooly (kotlin), @geoand (kotlin), @glefloch, @quarkusio/devtools

jesantana commented 1 year ago

This is also happening to me +1

kyngs commented 1 year ago

This is also happening to me +1

Yeah, I'm starting to worry that I'll need to do the migration manually

ia3andy commented 1 year ago

I am not sure if OpenRewrite support Gradle multi-module project. If that's the case, feel free to have a look and see what's wrong in the current implementation..

quotidian-ennui commented 4 months ago

I have been playing around with the init-gradle script and haven't been able to get it to work; however, you can workaround the problem by doing something like this (so I hope this helps someone).

top-level build.gradle extract

plugins{
  id 'org.openrewrite.rewrite' version '6.12.0' apply false
}
ext {
  quarkusUpdateConfig = project.findProperty('quarkusUpdateConfig') ?: ''
}

if (quarkusUpdateConfig != "") {
  apply plugin: "org.openrewrite.rewrite"
  repositories {
    mavenCentral()
  }
  dependencies {
    rewrite("org.openrewrite:rewrite-java")
    rewrite("io.quarkus:quarkus-update-recipes:1.0.17")
  }
  rewrite {
    configFile = quarkusUpdateConfig
    activeRecipe("io.quarkus.openrewrite.Quarkus")
    plainTextMask("**/*.adoc", "**/src/test/resources/__snapshots__/**/*.java", "**/*.kt", "**/*.md", "**/src/main/codestarts/**/*.java", "**/*.txt", "**/META-INF/services/**")
  }
}

And then you can have a script

if ! builtin type -f quarkus >/dev/null 2>&1; then
  echo "No Quarkus; nothing to do"
  exit 2
fi
# This will fail with a exitcode=1, but we capture the recipe.
recipe=$(quarkus update --dry-run 2>/dev/null | grep "OpenRewrite recipe generated" | cut -f 2 -d':' | sed -e "s/^[[:blank:]]*//" -e "s/[[:blank:]]*$//") || true
if [[ -n "$recipe" ]]; then
  ./gradlew -PquarkusUpdateConfig="$(realpath "$recipe")" rewriteRun
else
  echo "No quarkus update recipe generated; no updates?"
fi

What would actually be useful would be for a custom quarkus flag that generates the yml recipe file and does nothing else...

gsmet commented 1 month ago

I will close this one as I don't see a way to handle all the possibilities of the Gradle builds out there.

However @quotidian-ennui had a great idea about having a way to save the recipes so that you can apply them yourself. I created https://github.com/quarkusio/quarkus/issues/42743 and will have a look soon.