littlerobots / version-catalog-update-plugin

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

Not updating to latest stable versions in some cases #110

Closed sandeepmassey closed 1 year ago

sandeepmassey commented 1 year ago

Hi,

The plugin is not reporting/updating the latest stable versions in some cases. For example io.realm.kotlin has latest stable as 1.8.0 but the plugin is keeping it as 1.7.1 Initially the plugin was working and formatting/updating the .toml file correctly, but not now.

Steps to reproduce My libs.versions.toml file is partially like this

[versions] gradle-versions = "0.46.0" realm-kotlin = "1.7.1" version-catalog-update = "0.8.0"

[plugins] gradle-versions = { id = "com.github.ben-manes.versions", version.ref = "gradle-versions" } realm-kotlin = { id = "io.realm.kotlin", version.ref = "realm-kotlin" } version-catalog-update = { id = "nl.littlerobots.version-catalog-update", version.ref = "version-catalog-update" }

The toml-updater-config.gradle file looks like this

versionCatalogUpdate {

// sort the catalog by key (default is true)
sortByKey = true

// Referenced that are pinned are not automatically updated.
// They are also not automatically kept however (use keep for that).
pin {
    // pin all libraries and plugins using the given versions
    versions = ["buildToolsVersion", "compileSdk", "minSdk", "targetSdk", "android-application", "kotlin-android"]
}

keep {
    // keep all libraries and plugins using the given versions
    versions = ["buildToolsVersion", "compileSdk", "minSdk", "targetSdk", "android-application", "kotlin-android"]
    // keep versions without any library or plugin reference
    keepUnusedVersions = true
    // keep all libraries that aren't used in the project
    keepUnusedLibraries = true
    // keep all plugins that aren't used in the project
    keepUnusedPlugins = true
}

}

def isNonStable = { String version -> def stableKeyword = ['RELEASE', 'FINAL', 'GA'].any { String -> keyword version.toUpperCase().contains(keyword) } def regex = /^[0-9,.v-]+(-r)?$/ return !stableKeyword && !(version ==~ regex) }

tasks.named("dependencyUpdates").configure { resolutionStrategy { componentSelection { configureEach { Task task -> if (isNonStable(task.candidate.version) && !isNonStable(task.currentVersion)) { reject('Release candidate') } } } } }

The build.gradle.kts (project level) is

plugins { alias(notation = libs.plugins.gradle.versions) alias(notation = libs.plugins.version.catalog.update) alias(notation = libs.plugins.realm.kotlin).apply(apply = false) } apply(from = rootProject.file("/buildscripts/toml-updater-config.gradle"))

The build.gradle.kts (app level) is

plugins { id(id = libs.plugins.realm.kotlin.get().pluginId) }

dependencies { implementation(libs.realm.sync) }

Output ./gradlew versionCatalogUpdate yields

Task :dependencyUpdates


: Project Dependency Updates (report to plain text file)

No dependencies found.

Gradle release-candidate updates:

Generated report file F:\AndroidStudioProjects\MyProject\build\dependencyUpdates\report.json

Generated report file F:\AndroidStudioProjects\MyProject\build\dependencyUpdates\report.xml

Generated report file F:\AndroidStudioProjects\MyProject\build\dependencyUpdates\report.txt

BUILD SUCCESSFUL in 1m 55s 2 actionable tasks: 2 executed

Please tell me where I am wrong. Many thanks.

hvisser commented 1 year ago

I think in this case because you are not using the correct syntax for adding the realm plugin, though it is specified correctly in the root build file. You should be using

plugins {
 alias(libs.plugins.realm.kotlin)
}

If after changing that you still don't get the updated versions, could you try running the command with --refresh-dependencies and attach the report.json file if that didn't work?

sandeepmassey commented 1 year ago

Dear Sir I only changed the toml-updater-config.gradle file as follows and everything works correctly now. Probably there was something unexpected happening in this groovy script.

versionCatalogUpdate {

// sort the catalog by key (default is true)
sortByKey.set(true)

// Referenced that are pinned are not automatically updated.
// They are also not automatically kept however (use keep for that).
pin {
    // pin all libraries and plugins using the given versions
    versions = ["buildToolsVersion", "compileSdk", "minSdk", "targetSdk", "android-application", "kotlin-android"]
}

keep {
    // keep all libraries and plugins using the given versions
    versions = ["buildToolsVersion", "compileSdk", "minSdk", "targetSdk", "android-application", "kotlin-android"]
    // keep versions without any library or plugin reference
    keepUnusedVersions.set(true)
    // keep all libraries that aren't used in the project
    keepUnusedLibraries.set(true)
    // keep all plugins that aren't used in the project
    keepUnusedPlugins.set(true)
}

}

def isNonStable = { String version -> def stableKeyword = ['RELEASE', 'FINAL', 'GA'].any { it -> version.toUpperCase().contains(it) } def regex = /^[0-9,.v-]+(-r)?$/ return !stableKeyword && !(version ==~ regex) }

tasks.named("dependencyUpdates").configure { resolutionStrategy { componentSelection { all { if (isNonStable(it.candidate.version) && !isNonStable(it.currentVersion)) { reject('Release candidate') } } } } }

Thanks

hvisser commented 1 year ago

I doubt that's related to the issue. Most likely the dependency cache got refreshed by now. Anyway, glad that it works now :)