-
-
Notifications
You must be signed in to change notification settings - Fork 107
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for Versions Catalogs gradle/libs.versions.toml
#509
Conversation
If your project is using Gradle 7.0, you can use instead [Gradle versions catalog](https://docs.gradle.org/current/userguide/platforms.html) ```bash $ ./gradlew refreshVersionsCatalog > Task :refreshVersionsCatalog new file: gradle/libs.versions.toml modified: settings.gradle.kts modified: versions.properties ``` The generated versions catalog looks like this: ```toml ## Generated by $ ./gradlew refreshVersionsCatalog [libraries] browser = "androidx.browser:browser:_" cardview = "androidx.cardview:cardview:_" okhttp = "com.squareup.okhttp3:okhttp:_" junit = "junit:junit:_" ``` Like with buildSrcLibs, you get type-safe accessors available in the IDE: <img width="949" alt="refreshVersions_–_build_gradle_kts__sample-kotlin_" src="https://user-images.githubusercontent.com/459464/128611606-4ce90b01-475d-402a-b223-1757a1c51deb.png">
# Conflicts: # sample-kotlin/build.gradle.kts # sample-kotlin/gradle/wrapper/gradle-wrapper.properties # sample-kotlin/versions.properties
Cool! Tried out the snapshot. :) it inlines all the versions into
if I run it outputs something like this:
Now we have duplicated versions and the
Maybe it should remove the |
with something like this:
it seems to just ignore the |
Also, it doesn't seem to work nicely with Configuration cache.
|
If I have something like this, it seems to just remove these libraries altogether.
|
I have this in
and I use some of the after I run when I run: if fails because |
@yogurtearl thanks a lot for trying out the snapshot! I initially thought the task Thanks for your reports on the configuration cache, I will have a look. |
Now, we are testing with realistic data when it comes to the versions retrieved from the repos, and this will help ensure we are going in a code path that does the proper filtering. Also, we are now testing for the migration into the version catalog of dependencies that don't have a version specified (e.g. because specified by a BoM). Yes, the tests are currently failing.
The freshly introduced overload will be testable without having to perform network calls, which means we will be able to use static, and fake data. Most importantly, the new overload doesn't depend on global mutable state, but only from the arguments it has been passed.
We no longer allocate on each call. This commit also removes the unused parameter of the hasHardcodedVersion function which always had the default value of emptySet().
Just one line to fix it, unbelievable!
This avoids unnecessary calculations
The problem was that the RefreshVersionsExtension was directly touching RefreshVersionsConfigHolder, whose instance is reused by Gradle across runs. Now, the rejectVersionIf predicate defaults to null, is taken each time the plugin is applied to be set on the RefreshVersionsConfigHolder, so if it's been removed, it's set back to null as it should.
In case someone relies on the reset behavior later (though current code doesn't), the behavior will be correct and will avoid potential memory leaks.
I did further testing, and after my latest commits, it doesn't seem to introduce regressions, so I think we will keep the flag enabled by default. |
…introduce test to ensure it's never empty, and properly formatted.
This optimization will make upgrading refreshVersions slightly faster when there's no potential dependency notations that have been removed since last run.
I don't know why the CI is failing, since it's giving 404 Not Found errors when I try to look… I reported the issue to GitHub support. On my machine the I was ready to merge this. |
GitHub Actions got fixed, and I added the missing opt-in that is not required as the Gradle 7.5.1 update updated Kotlin. Now is time to merge! |
pog |
Hello & bonjour,
What?
Resolves #333
Add support for Versions Catalogs
gradle/libs.versions.toml
in all our tasks (refreshVersions, refreshVersionsMigrate, refreshVersionsCleanup, refreshVersionsCatalog)Why?
First class support for Gradle versions catalogs, removing fear of plugin lock-in for our users.
Testing?
You can test it in your own project, because I published a snapshot version on Sonatype
Setup refreshVersions
"0.41.0-SNAPSHOT"
as in https://jmfayard.github.io/refreshVersions/setup/#if-you-want-to-use-a-snapshot-versionThen:
How?
./gradlew refreshVersionsCatalog
generategradle/libs.versions.toml
"_"
--versions
option is used--all
is used[plugins]
sectionversions
entry and useversion.ref
for the dependencyversions
section should be on topgradle/libs.versions.toml
#509 (comment)./gradlew refreshVersionsMigrate
gradle/libs.versions.toml
--toml
should migrate to dependencies fromlibs.versions.toml
before built in dependenciesbuild.gradle
files inside aresources
orbuild
directory./gradlew refreshVersions
"_"
versions.ref = "xxx"
gradle/libs.versions.toml
gradle/libs.versions.toml
#509 (comment)./gradlew refreshVersionsCleanup
should remove comments ingradle/libs.versions.toml
sample-kotlin
"0.41.0-SNAPSHOT"
@LouisCad
to review it when it's not draft anymore