Cannot run in gradle multiproject: Could not find method rewrite() for arguments [org.openrewrite.recipe:rewrite-micronaut:1.3.0] on object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.

See original GitHub issue

Hi there. I try to use micronaut in gradle multiproject. But I get this error:

Build file '/home/fengyu/下载/demo/app/build.gradle' line: 30

* What went wrong:
A problem occurred evaluating project ':app'.
> Could not find method rewrite() for arguments [org.openrewrite.recipe:rewrite-micronaut:1.3.0] on object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.

* Try:
> Run with --stacktrace option to get the stack trace.
> 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

BUILD FAILED in 6s

Here is the reproduce steps:

curl --location --request GET 'https://launch.micronaut.io/create/default/com.example.app?lang=JAVA&build=GRADLE&test=SPOCK&javaVersion=JDK_11&features=openrewrite' --output app.zip
mkdir -p demo
unzip -d demo app.zip
echo "include 'app'" > demo/settings.gradle
rm -f demo/app/settings.gradle
cd demo/app
./gradlew rewriteDryRun

Will show error;

* Where:
Build file '/home/fengyu/下载/demo/app/build.gradle' line: 30

* What went wrong:
A problem occurred evaluating project ':app'.
> Could not find method rewrite() for arguments [org.openrewrite.recipe:rewrite-micronaut:1.3.0] on object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.

* Try:
Run with --stacktrace option to get the stack trace. 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

BUILD FAILED in 3s

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
abcfy2commented, Dec 7, 2021

Great. It’s working now. Thanks.

1reaction
lenaschimmelcommented, Dec 7, 2021

I experienced the same problem in my own project (coincidentially, also a micronaut project, though I think none of the problems is micronaut-specific), and could also reproduce it by following your steps. I will try to describe a solution.

Step 2 of the Quickstart guide states:

The Gradle plugin can only be applied to the root project. The tasks on the root project will orchestrate running recipes on all subprojects.

The OpenRewrite Guide does not explain how to do this, but some information can be found in the Gradle guide.

You need to have a build.gradle file in your root project (demo/build.gradle):

plugins {
    id("java")

    // apply only to the root project
    id("org.openrewrite.rewrite") version("5.14.0")
}

repositories {
    // The root project doesn't have to be a Java project, but this is necessary
    // to resolve recipe artifacts.
    mavenCentral()
}

dependencies {
    rewrite("org.openrewrite.recipe:rewrite-micronaut:1.3.0")
} 

rewrite {
    activeRecipe("org.openrewrite.java.micronaut.Micronaut2to3Migration")
}

Then you can remove everything rewrite-related from your subproject file demo/app/build.gradle. Theoretically, you can also keep those lines there, but you need to change id("org.openrewrite.rewrite") version("5.14.0") to just id("org.openrewrite.rewrite") then, or you will get the error:

Plugin request for plugin already on the classpath must not include a version

If you use JDK >= 16, you may now run into #909 which has a workaround.

Also, you need to run your task from the root directory demo, not from demo/app. In your case, gradle wrapper is only presend in the app directory, so instead of ./gradlew rewriteDryRun you must use gradle rewriteDryRun or initialize the wrapper in the root as well.


To get to this point, I made all the mistakes you made, and many more. I think the documentation should be improved, meaning both the OpenRewrite Quickstart guide and the Micronaut upgrade guide.

Read more comments on GitHub >

github_iconTop Results From Across the Web

core'] on object of type org.gradle.api.internal.artifacts.dsl ...
As the title says, it is erroring while i try to run the build.gradle file at line 7 dependencies { classpath ...
Read more >
Could not find method compile() for arguments Gradle
NOTE: I do have the java, maven, nexus, shadow, and rebel plugins applied. When I run my Gradle task, I encounter this error:...
Read more >
Gradle Plugin Configuration - OpenRewrite
With the plugin applied, the rewrite DSL is available for configuration. Multi-Module Gradle Projects.
Read more >
Gradle 5 - Grails 3 simple multi-project app/plugin won't compile
grails-plugin'] > Could not find method runtimeOnly() for arguments [io.methvin:directory-watcher] on object of type org.gradle.api.internal.
Read more >
Could not find method testCompile() for arguments [{group ...
I now ge the error: Could not find method testCompile() for arguments [{group=junit, name=junit, version=4.12}] on object of type org.gradle.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found