openrewrite / rewrite

Automated mass refactoring of source code.

Home Page:https://docs.openrewrite.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Gradle wrapper upgrade recipe to 7.x+ is not updating "compile" dependencies to "implementation" in build.gradle files

aakash-pinc opened this issue · comments

How are you running OpenRewrite?

moderne.io

Problem statement

Gradle wrapper upgrade recipe to 7.x is not updating the "compile" to "implementation" string in build.gradle files.

What is the smallest, simplest way to reproduce the problem?

Create a Gradle (4.x) project with dependencies and then run the "Gradle wrapper upgrade" recipe to 7.x. You will notice the "compile" in build.gradle is not getting replaced with "implementation"

Are you interested in [contributing a fix to OpenRewrite]

No

Thanks for logging the issue @aakash-pinc ; I'll link this doc page here for some more context:
https://docs.gradle.org/8.7/userguide/java_library_plugin.html#sec:java_library_separation

The compile and runtime configurations have been removed with Gradle 7.0. Please refer to the upgrade guide how to migrate to implementation and api configurations`.

So the base recipe for this is available in the ChangeDependency recipe. Unfortunately, it's not as easy as to migrate from compile to implementation. This works only for Gradle projects that fit the category of applications and falls apart for libraries. For libraries, it's more nuanced in that it needs to migrate to either api or implementation.

While migrating from compile to implementation would result in a successful build for the library code, it's dependency descriptor would state that all of these dependencies should be in the runtime scope for projects that then consume them, thus often resulting in compilation errors in those external projects.

Note: There are also other configurations that would need to be migrated as part of this migration as well.