Is there any way to use versionFor() in a plugins ...
# refreshversions
d
Is there any way to use versionFor() in a plugins block at the root build.gradle.kts in a multi-module project? The IDE gives an error to use an explicit form, and the build just has an Unresolved reference: versionFor...
v
Unlikely. Maybe better use a version catalog. The
plugins { ... }
block is special. It is extracted from the build script and applied to a dummy project to find out which type-safe accessors need to be generated for the set of applied plugins. You could maybe try to use the fully-qualified form instead of an import, but I highly doubt it will work.
d
Ok, thanks! It's a pity that refreshVersionMigrate doesn't transfer refreshVersion's references to version catalog format, it only transfers the strings there... I could use it only for dagger/hilt gradle plugin, but as far as I know they don't officially support version catalogs for composite builds... I'm currently using a symliinked versions.properties file...
Thanks for the info, though!
By any chance, would you have any idea why Intellij shows: even though I have 2.26.1 in my root project with apply false?
v
Who is "they"?
d
they is refreshVersions
v
Well, I have it, but as their comments are removed when running again, you have to handle each of the composed builds sequentially
d
Unless it's not this:|
Copy code
plugins {
    id("com.google.dagger.hilt.android") version "2.46.1" apply false
}
v
So run it on one project, do the upgrades, run on the next, and so on
> even though I have 2.26.1 in my root project with apply false? Hard to guess, look at a build
--scan
if you can
🤔 1
d
Yeah, I did that for versions.properties, so it works the same way? I can symlink the libs.versions.toml across projects and it won't remove the other project's deps?
I'll give scan a try, thanks!
uyues
v
It never removes dependencies, it just adds comments about possible version updates.
👍🏼 1
At least in version catalog, no idea about the properties file, never used it.
So yes, you could symlink it, or you just configure Gradle to use the file from the other path. No need to use symlinks that might not work everywhere.
d
I had tried once upon a time to configure gradle to use the file from the other path, it didn't work... maybe it's fixed now, but I guess for now it's easier to use symlinks... but you're right, one day I should figure it out... I'm having enough gradle problems right now with dagger/hilt 🤕... I looked at the scan, it showed the right version. I guess we can't always believe Intellij...
v
You should be able to, if the sync was successful
Copy code
versionCatalogs {
    create("libs") {
        from(files("../libs.versions.toml"))
    }
}
or similar always worked fine for me actually
Oh, actually I was wrong, refreshVersions does not properly support referenced version catalog files, symlinks should probably ok though. For the referenced one I actually have a work-around like this in the settings script:
Copy code
gradle.rootProject {
    tasks.configureEach {
        if (name == "refreshVersions") {
            doFirst {
                copy {
                    from(gradle.parent!!.rootProject.file("gradle/libs.versions.toml"))
                    into("gradle")
                }
            }
            doLast {
                // work-around for <https://github.com/jmfayard/refreshVersions/issues/661>
                // and <https://github.com/jmfayard/refreshVersions/issues/663>
                file("gradle/libs.versions.toml").apply {
                    readText()
                        .replace("⬆ =", " ⬆ =")
                        .replace("]\n\n", "]\n")
                        .replace("""(?s)^(.*)(\n\Q[plugins]\E[^\[]*)(\n.*)$""".toRegex(), "$1$3$2")
                        .also { writeText(it) }
                }
                copy {
                    from("gradle/libs.versions.toml")
                    into(gradle.parent!!.rootProject.file("gradle"))
                }
                delete("gradle")
            }
        }
    }
}
🤒 1
d
Well, thanks for sharing! Maybe refreshVersions should provide this as a drop-in somehow...
v
No, it should fix the issues it works-around