rewrite-docs icon indicating copy to clipboard operation
rewrite-docs copied to clipboard

Running Rewrite on a Gradle Kotlin project without modifying the build

Open ia3andy opened this issue 2 years ago • 2 comments

The current doc only shows the groovy option, it would be nice to also provide the Kotlin one.

ia3andy avatar Sep 28 '23 15:09 ia3andy

I took a look at this, but I'm not that familiar with Gradle or Kotlin 😅 . I was able to resolve some of the issues converting it to Kotlin -- but I'm struggling to figure out the syntax for how to apply the rewrite plugin.

I keep getting an Unresolved reference: rewrite error when I try and run gradle --init-script init.gradle.kts.

Things I've tried include:

rootProject {
    apply<org.openrewrite.gradle.RewritePlugin>()
    
    dependencies {
        rewrite("org.openrewrite:rewrite-java")
    }

    rewrite {
        activeRecipe("org.openrewrite.FindSpringUses")
    }
}
rootProject {
    apply {
        plugin("org.openrewrite.gradle.RewritePlugin")
    }
    
    dependencies {
        rewrite("org.openrewrite:rewrite-java")
    }

    rewrite {
        activeRecipe("org.openrewrite.FindSpringUses")
    }
}
rootProject {
    plugins.apply("org.openrewrite.gradle.RewritePlugin")

    dependencies {
        rewrite("org.openrewrite:rewrite-java")
    }

    rewrite {
        activeRecipe("org.openrewrite.FindSpringUses")
    }
}

If anyone has figured this out please let me know :D

mike-solomon avatar Oct 04 '23 17:10 mike-solomon

Also - for anyone looking at this in the future, Kotlin expects a url like this for the first part of the initscript as far as I can tell:

initscript {
    repositories {
        maven {
            url = uri("https://plugins.gradle.org/m2")
        }
    }

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

mike-solomon avatar Oct 04 '23 17:10 mike-solomon