I'm trying out OpenRewrite and I wanted to test it out with the "Remove unused imports" recipe against our a large multi-module Gradle project.
I'm opting for the init-script approach so I don't have to edit our build.gradle
. I copied the script from the website and named it unused-imports.gradle
.
I added an exclusion
section for excluding our generated files:
initscript {
repositories {
maven { url "https://plugins.gradle.org/m2" }
}
dependencies { classpath("org.openrewrite:plugin:latest.release") }
}
rootProject {
plugins.apply(org.openrewrite.gradle.RewritePlugin)
dependencies {
rewrite("org.openrewrite:rewrite-java")
}
rewrite {
activeRecipe("org.openrewrite.java.RemoveUnusedImports")
exportDatatables = true
exclusion(
"**/generated/**"
)
}
afterEvaluate {
if (repositories.isEmpty()) {
repositories {
mavenCentral()
}
}
}
}
When I run it with the command wsl ./gradlew --init-script unused-imports.gradle rewriteDryRun
it seems to be going alright. I see all our modules en sub-modules being parsed until, after about half an hour I'm seeing this:
Scanning sources in project :
Using active styles [org.openrewrite.java.Checkstyle]
<============-> 99% EXECUTING [58m 45s]
> IDLE
> IDLE
> :rewriteDryRun
> IDLE
After an hour I terminated the command because there seemed to be no progress.
What might be wrong?
Additional info:
org.gradle.jvmargs=-Xmx25G -XX:+UnlockDiagnosticVMOptions -XX:GCLockerRetryAllocationCount=100
. (taken from another StackOverflow thread)Cause 80: org.gradle.internal.resolve.ModuleVersionNotFoundException: Could not find some:dependency:.
Required by:
project :our:module > project :another:module
I tried modifying the repositories
section so it mirrors our build.gradle
one but it didn't make a difference:
afterEvaluate {
if (repositories.isEmpty()) {
repositories {
maven {
url = uri('https://our/artifactory/repo')
}
mavenCentral()
}
}
}
Ok, at the end of my work day I let it run and eventually it actually completed!
BUILD SUCCESSFUL in 6h 7m 51s
It seems I just had to be very patient.