littlerobots / version-catalog-update-plugin

Gradle plugin for updating a project version catalog
Apache License 2.0
565 stars 23 forks source link

Resolve without the versions plugin #125

Closed hvisser closed 11 months ago

hvisser commented 11 months ago

Initial version of resolving dependencies without the versions plugin.

Behavioural changes

In this PR these changes are behind a flag for testing, set the nl.littlerobots.vcu.resolver property to true (in gradle.properties or by passing -Pnl.littlerobots.vcu.resolver=true to switch to the new update task.

For resolving the TOML file is used as the source of the dependencies to check for updates. Therefore:

Changes not directly related to not using the versions plugin:

For selecting components use the versionSelector method on the extension. This function should return true to select a version, false otherwise.

versionCatalogUpdate {
    versionSelector {
        // function from the version plugin docs
        !isNonStable(it.candidate.version)
    }
}

If omitted, a default will now be set: non-stable versions are allowed if the current version is non-stable, otherwise only a stable version is allowed. Implementation for this is basically the same as in the versions plugin README. This means less configuration too.

ref #123 #111 #122

TWiStErRob commented 11 months ago

The option to create a TOML file is no longer available

:( that was one of the main reasons I used this plugin, there's nothing else that can do it. I use Renovate to update version catalogs, because I want CI to be executed on every bump.

hvisser commented 11 months ago

@TWiStErRob that's good to know, thanks for that feedback. If there are more folks find that functionality useful then an option would be to keep depending on the versions plugin for that functionality in some shape or form, but it would definitely complicate things a bit.

TWiStErRob commented 11 months ago

It's tricky to get this feedback, because this means that I only used it once per project and I only use it once every few months. There are a lot more legacy projects to migrate at work. It's unclear though if it's worth it for you to support this. It's definitely a good tech challenge. :) If I were you I would consider creating a separate plugin for the new behaviour rather than flagging, although that might double the maintenance.

extmkv commented 10 months ago

In our project setup, we've multiple TOML files, and this is the setup we had:

versionCatalogUpdate {
    sortByKey = false

    versionCatalogs {
        getTOMLFiles().forEach {
            create("${it.nameWithoutExtension}Lib") {
                catalogFile = file("configs/libs/${it.name}")
                sortByKey = false

                keep {
                    keepUnusedPlugins = true
                }
            }
        }
    }
}

tasks.register("versionCatalogUpdateAll") {
    dependsOn(tasks.withType(VersionCatalogUpdateTask::class.java).filterNot { it.name == "versionCatalogUpdate" })
}

Command run to update all catalogs: ./gradlew versionCatalogUpdateAll

Running with the new flag and nothing happens at all. Do you have any clue what's wrong @hvisser ?

hvisser commented 10 months ago

@extmkv You are depending on the task class, which is basically an implementation detail at this point. The new task class is ExperimentalVersionCatalogUpdateTask, but that is just temporary. So I'd advice to depend on the task name only.

extmkv commented 10 months ago

That makes sense @hvisser and now it calls all the tasks correctly. However, the output for all the tasks is the same:

Gradle: 8.5 AGP: 8.2.1

> Task :versionCatalogUpdateAndroidLib
There are libraries that could not be resolved:
 - com.google.android.material:material (material ref:material)
 - com.google.android.play:core (playCore ref:playCore)
 - com.google.android.play:core-ktx (playCoreKtx ref:playCoreKtx)
There are plugins that could not be resolved:
 - com.android.application (application ref:androidGradle)
 - com.android.library (library ref:androidGradle)

> Task :versionCatalogUpdateAndroidxLib
There are libraries that could not be resolved:
 - androidx.activity:activity-ktx (activityKtx ref:activity)
 - androidx.activity:activity-compose (activityCompose ref:activity)
 - androidx.appcompat:appcompat (appcompat ref:appCompat)
 - androidx.constraintlayout:constraintlayout (constraintlayout ref:constraintLayout)
 - androidx.constraintlayout:constraintlayout-compose (constraintlayoutCompose ref:constraintLayoutCompose)
 - androidx.coordinatorlayout:coordinatorlayout (coordinatorlayout ref:coordinatorlayout)
 - androidx.test:core (core ref:test)
 - androidx.core:core-ktx (coreKtx ref:core_ktx)
 - androidx.arch.core:core-testing (coreTesting ref:arch)
 - androidx.test.espresso:espresso-core (espressoCore ref:espresso)
 - androidx.fragment:fragment-ktx (fragmentKtx ref:fragment)
 - androidx.fragment:fragment (fragment ref:fragment)
 - androidx.test.ext:junit (junit ref:test_ext)
 - androidx.test:rules (testRules ref:test_ext_rules)
 - androidx.lifecycle:lifecycle-extensions (lifecycleExtensions ref:lifecycleExtensions)
 - androidx.lifecycle:lifecycle-livedata-ktx (lifecycleLivedataKtx ref:lifecycle)
 - androidx.lifecycle:lifecycle-runtime-ktx (lifecycleRuntimeKtx ref:lifecycle)
 - androidx.lifecycle:lifecycle-runtime (lifecycleRuntime ref:lifecycle)
 - androidx.lifecycle:lifecycle-viewmodel-ktx (lifecycleViewmodelKtx ref:lifecycle)
 - androidx.lifecycle:lifecycle-viewmodel (lifecycleViewmodel ref:lifecycle)
 - androidx.lifecycle:lifecycle-viewmodel-compose (lifecycleViewmodelCompose ref:lifecycleComposeExtension)
 - androidx.lifecycle:lifecycle-common-java8 (lifecycleCommonJava8 ref:lifecycle)
 - androidx.lifecycle:lifecycle-common (lifecycleCommon ref:lifecycle)
 - androidx.lifecycle:lifecycle-livedata-core (lifecycleLivedataCore ref:lifecycle)
 - androidx.lifecycle:lifecycle-runtime-compose (lifecycleRuntimeCompose ref:lifecycle)
 - androidx.navigation:navigation-fragment-ktx (navigationFragmentKtx ref:navigation)
 - androidx.navigation:navigation-common (navigationCommon ref:navigation)
 - androidx.navigation:navigation-runtime-ktx (navigationRuntimeKtx ref:navigation)
 - androidx.navigation:navigation-runtime (navigationRuntime ref:navigationRuntime)
 - androidx.navigation:navigation-ui-ktx (navigationUiKtx ref:navigation)
 - androidx.recyclerview:recyclerview (recyclerview ref:recyclerview)
 - androidx.room:room-compiler (roomCompiler ref:room)
 - androidx.room:room-ktx (roomKtx ref:room)
 - androidx.room:room-runtime (roomRuntime ref:room)
 - androidx.room:room-testing (roomTesting ref:room)

Example of one of the catalogs:

[versions]
androidGradle = "8.2.1"
material = "1.9.0"
playCore = "1.8.0"
playCoreKtx = "1.8.1"

[libraries]
material = { module = "com.google.android.material:material", version.ref = "material" }
playCore = { module = "com.google.android.play:core", version.ref = "playCore" }
playCoreKtx = { module = "com.google.android.play:core-ktx", version.ref = "playCoreKtx" }

[plugins]
application = { id = "com.android.application", version.ref = "androidGradle" }
library = { id = "com.android.library", version.ref = "androidGradle" }
hvisser commented 10 months ago

Can you please move this to an issue and provide a small repro project so that I can take a look?

extmkv commented 10 months ago

@hvisser here is a repository with the issue: https://github.com/extmkv/versions-bump

I notice that works if I've the libs.versions.toml on the gradle folder + with the other toml's on the config/libs folder. When I also moved the libs.versions.toml to config/libs/libs.toml it started to happen

extmkv commented 10 months ago

@hvisser the plugin will check if there is an update in all the maven repositories? It seem isn't checking google() and specific private mavens we have configured