Skip to content
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

Update with "quarkus" fails with gradle configured subprojects #45238

Open
DaveO-Home opened this issue Dec 20, 2024 · 6 comments
Open

Update with "quarkus" fails with gradle configured subprojects #45238

DaveO-Home opened this issue Dec 20, 2024 · 6 comments
Labels

Comments

@DaveO-Home
Copy link

DaveO-Home commented Dec 20, 2024

Describe the bug

Execute: quarkus update

Using gradle configuration described here: https://docs.gradle.org/current/userguide/declaring_dependencies_between_subprojects.html

Fails with:

quarkusUpdate is experimental, its options and output might change in future versions
Detected project Java version: 21
Detected project Java version: 21
Instructions to update this project from '3.17.4' to '3.17.5':
Recommended Quarkus platform BOM updates:
Update: io.quarkus.platform:quarkus-bom:pom:3.17.4 -> 3.17.5

Extensions from io.quarkus.platform:quarkus-bom:

Resolved io.quarkus:quarkus-update-recipes:LATEST with 0 recipe(s) to update from 3.17.4 to 3.17.5 (initially made for OpenRewrite GRADLE plugin version: 6.18.0) 
OpenRewrite recipe generated: /tmp/quarkus-project-recipe-13898335995685777605.yaml



 ------------------------------------------------------------------------
Executing:
/home/daveo/.sdkman/candidates/gradle/current/bin/gradle --console plain --stacktrace --init-script /tmp/openrewrite-init17757224676489351441gradle rewriteDryRun


FAILURE: Build failed with an exception.

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

* What went wrong:
No signature of method: org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.rewrite() is applicable for argument types: (String) values: [org.openrewrite:rewrite-java]
Possible solutions: wait(), wait(long), create(java.lang.Object), with(groovy.lang.Closure), getAt(java.lang.String)
> 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.
> Get more help at https://help.gradle.org.

* Exception is:
org.codehaus.groovy.runtime.metaclass.MissingMethodExecutionFailed: No signature of method: org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.rewrite() is applicable for argument types: (String) values: [org.openrewrite:rewrite-java]
Possible solutions: wait(), wait(long), create(java.lang.Object), with(groovy.lang.Closure), getAt(java.lang.String)
Caused by: 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:84)
	at openrewrite_init17757224676489_10555thm7vf76a1ah66i939aw$_run_closure1$_closure3.doCall$original(/tmp/openrewrite-init17757224676489351441gradle:23)
	at openrewrite_init17757224676489_10555thm7vf76a1ah66i939aw$_run_closure1$_closure3.doCall(/tmp/openrewrite-init17757224676489351441gradle)
	at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103)
	at org.gradle.util.internal.ClosureBackedAction.execute(ClosureBackedAction.java:73)
	at org.gradle.util.internal.ConfigureUtil.configureTarget(ConfigureUtil.java:166)
	at org.gradle.util.internal.ConfigureUtil.configure(ConfigureUtil.java:107)
	at org.gradle.api.internal.project.DefaultProject.dependencies(DefaultProject.java:1300)
	at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103)
	at org.gradle.internal.metaobject.BeanDynamicObject$MetaClassAdapter.invokeMethod(BeanDynamicObject.java:541)
	at org.gradle.internal.metaobject.BeanDynamicObject.tryInvokeMethod(BeanDynamicObject.java:218)
	at org.gradle.internal.metaobject.CompositeDynamicObject.tryInvokeMethod(CompositeDynamicObject.java:99)
	at org.gradle.internal.extensibility.MixInClosurePropertiesAsMethodsDynamicObject.tryInvokeMethod(MixInClosurePropertiesAsMethodsDynamicObject.java:38)

Note: this also errors with previous versions.

Expected behavior

Update to new quarkus version

Actual behavior

See exception above.

How to Reproduce?

See: https://github.com/DaveO-Home/gradle-subprojects-quarkus

Create project like:

.
├── api
│ ├── src
│ │ └──...
│ └── build.gradle
├── services
│ └── person-service
│ ├── src
│ │ └──...
│ └── build.gradle
├── shared
│ ├── src
│ │ └──...
│ └── build.gradle
└── settings.gradle

execute quarkus update at top level

Note: When executing quarkus in a subproject it attempts to run correctly but fails during compile because it can't find the other subprojects.

Output of uname -a or ver

Linux mini-pc 6.12.5-200.fc41.x86_64 #1 SMP PREEMPT_DYNAMIC Sun Dec 15 16:48:23 UTC 2024 x86_64 GNU/Linux

Output of java -version

java 21.0.2 2024-01-16 LTS Java(TM) SE Runtime Environment Oracle GraalVM 21.0.2+13.1 (build 21.0.2+13-LTS-jvmci-23.1-b30) Java HotSpot(TM) 64-Bit Server VM Oracle GraalVM 21.0.2+13.1 (build 21.0.2+13-LTS-jvmci-23.1-b30, mixed mode, sharing)

Quarkus version or git rev

3.17.4

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

------------------------------------------------------------ Gradle 8.8 ------------------------------------------------------------ Build time: 2024-05-31 21:46:56 UTC Revision: 4bd1b3d3fc3f31db5a26eecb416a165b8cc36082 Kotlin: 1.9.22 Groovy: 3.0.21 Ant: Apache Ant(TM) version 1.10.13 compiled on January 4 2023 JVM: 21.0.2 (Oracle Corporation 21.0.2+13-LTS-jvmci-23.1-b30) OS: Linux 6.12.5-200.fc41.x86_64 amd64

Additional information

No response

@DaveO-Home DaveO-Home added the kind/bug Something isn't working label Dec 20, 2024
Copy link

quarkus-bot bot commented Dec 20, 2024

/cc @geoand (kotlin), @glefloch, @quarkusio/devtools, @radcortez (config)

@gsmet gsmet added kind/enhancement New feature or request and removed kind/bug Something isn't working labels Dec 26, 2024
@gsmet
Copy link
Member

gsmet commented Dec 26, 2024

Yeah, unfortunately, supporting all combinations of Gradle config is hard and in this case, we are just using the recommendations from OpenRewrite as to how to apply updates to Gradle projects.

If you are familiar with Gradle and can think of a way to make it work we can certainly adjust the Gradle script we generate and the executed command.

@shanman190
Copy link

Hi, I'm an active member over in the OpenRewrite community where we had a ticket created over there as a link back to this one. I've also got a wealth of knowledge when it comes to Gradle itself.

I only have a superficial understanding of Quarkus, so I'm not quite sure where to look to see how/where the Gradle Groovy DSL initscript is defined within the project. But with the stacktrace alone, this kinda seems like the OpenRewrite plugin was missing when the dependency attempted to be added in the particular context since the rewrite configuration was missing (and internally to the OpenRewrite plugin this is always created when the plugin is applied; see https://github.com/openrewrite/rewrite-gradle-plugin/blob/main/plugin%2Fsrc%2Fmain%2Fjava%2Forg%2Fopenrewrite%2Fgradle%2FRewritePlugin.java#L61).

One possibility is that the OpenRewrite plugin wants to be applied to the Gradle root project. If the project isn't the root, then the plugin skips its apply phase.

@DaveO-Home
Copy link
Author

@shanman190 Quarkus removes the init script from /tmp, difficult to trap but was able to save this(not sure if this is the correct initscript)

// Script used to run Open Rewrite without having to modify the build.
// Based on https://docs.openrewrite.org/tutorials/running-rewrite-on-a-gradle-project-without-modifying-the-build

initscript {
    repositories {
        maven { url "https://plugins.gradle.org/m2" }
    }

    dependencies {
        classpath("org.openrewrite:plugin:6.18.0")
    }
}

addListener(new BuildInfoPluginListener())

allprojects {
    project.afterEvaluate {
        if (!project.plugins.hasPlugin(org.openrewrite.gradle.RewritePlugin)) {
            project.plugins.apply(org.openrewrite.gradle.RewritePlugin)
        }
    }
    dependencies {
      rewrite("org.openrewrite:rewrite-java")
      rewrite("io.quarkus:quarkus-update-recipes:1.0.22");
    }
    rewrite {
      configFile = project.getRootProject().file("/tmp/quarkus-project-recipe-5619128595086286605.yaml")
      activeRecipe("io.quarkus.openrewrite.Quarkus")
      plainTextMask("**/*.txt", "**/src/main/codestarts/**/*.java", "**/*.md", "**/*.kt", "**/src/test/resources/__snapshots__/**/*.java", "**/*.adoc", "**/META-INF/services/**")
    }
}

class BuildInfoPluginListener extends BuildAdapter {

    def void projectsLoaded(Gradle gradle) {
        Project root = gradle.getRootProject()
        if (!"buildSrc".equals(root.name)) {
            root.allprojects {
                apply {
                    apply plugin: org.openrewrite.gradle.RewritePlugin
                }
            }
        }
    }
}

@shanman190
Copy link

shanman190 commented Dec 26, 2024

Ok, so that's an older script. I made an update to the docs back in August 2023.

In the latest version of the initscript you'll find that the plugin is only applied to the rootProject and overall is a lot simpler than it used to be.

https://docs.openrewrite.org/running-recipes/running-rewrite-on-a-gradle-project-without-modifying-the-build

In this case, one of the subprojects would have had their Action run due to the allprojects block, but the plugin wouldn't have been applied, thus the rewrite configuration would have been absent.

@DaveO-Home
Copy link
Author

@gsmet @shanman190 Looks like an easy enough change? shanman thanks.

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

No branches or pull requests

4 participants