littlerobots/version-catalog-update-plugin

version-catalog-update-plugin should also inspect dependencies in buildSrc

Opened this issue · 7 comments

Please describe your feature request, and some context why this would be useful to you and others using the plugin.
Hi,

I have added library capability to my project buildSrc by adding this block to buildSrc/settings.gradle.kts

dependencyResolutionManagement {
    versionCatalogs {
        create("libs")  {
            from(files("../gradle/libs.versions.toml"))
        }
    }
}

The project compiles well. But when I use the versionCatalogUpdate task, the records in libs/versions.toml are stripped away causing of course buildSrc to be no longer compilable.

Either the task needs to analyse/update the buildSrc dependencies, or we need to tell it to not delete unused rows.

There's not much I can do here as the actual version resolving is done by the versions-plugin. There are some issues on that to report buildSrc dependencies, like ben-manes/gradle-versions-plugin#283 and ben-manes/gradle-versions-plugin#478. It looks like Gradle isn't making those dependencies visible to the versions plugin.

As a workaround you can set the keep option to true, so that missing dependencies are not removed from the toml file.

What if an option is added to this plugin to declare extra versions plugin files? Something like this:

versionCatalogUpdate {
   readVersionsReport("../buildSrc/build/dependencyUpdates/versions.json")
}

Then, we could manually run dependency updates on the buildSrc + version catalog update like this:

./gradlew :buildSrc:dependencyUpdates versionCatalogUpdate

I think that would probably complicate things alot. Buildsrc is now implemented as an included build which means it can declare its own dependencies. This is (probably) also why the dependency versions plugin doesn't pick up the dependencies, it's a separate project. Different versions means potential conflicts that would need to be resolved.

I haven't tested if you can also apply the dependency versions plugin to the buildsrc Gradle file. For normal modules the dependency versions plugin will create an aggregated report, if it does the same for buildsrc then everything should just work. But it's probably not that simple :)

Yes, you can apply dependency versions plugin to buildsrc. That's why I recommended this above, problem is only that this plugin will not collect dependency versions plugin's report from build src. My workaround would solve this.

I know you can do that since it's the same as any other project. I just haven't tested if running the plugin from the root project will create a report.json for all dependencies. If you are able to try, that would be great.

Like I said.I don't think merging two separate report files is practically possible as there are many edge cases, so it's not some I'm considering for that reason.

If I remember correctly, it only creates report json for dependencies in buildSrc.

Yup, just checked, versions.json inside buildSrc only contains dependencies from buildSrc. So they would have to be merged with the main project.