Skip to content
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

Update TOML files in dependency projects (without declaring dependencies) #65

Closed
GeorgHoffmeyer opened this issue Aug 4, 2022 · 7 comments
Labels
enhancement New feature or request

Comments

@GeorgHoffmeyer
Copy link

We use the version catalog, to share versions across multiple projects. For that we have a dependancy-managment project, which just publishs the toml file to our artifact repository.

I now want to use the version-catalog-update plugin to update the toml file. To do so, I must define all versions in the catalog as a dependencie in my buidl.gradle.

It would be great if I could just use the toml file and update everything that is defined in that file, no matter if it is used as a dependency or not.

@hvisser hvisser added the enhancement New feature or request label Aug 4, 2022
@hvisser
Copy link
Contributor

hvisser commented Aug 4, 2022

Yeah that makes sense, however it's more or less backwards to what this plugin is currently doing (the versions plugin is actually doing all of the dependency resolving, based on what is used in the project). Ideally we'd still want to go through that plugin so that any component selection rules etc are the same, otherwise the plugin would need its own mechanism for detecting updates and rules around how to select those, duplicating the functionality of the versions plugn.

@hvisser hvisser changed the title Updating also unuses dependencies Update TOML files in dependency projects (without declaring dependencies) Aug 4, 2022
@hvisser
Copy link
Contributor

hvisser commented Aug 4, 2022

I think you might be able to do this today, if you use the versions catalog api to add all the libraries in your toml file(s) as a dependency, something like this:

val versionCatalog = extensions.getByType<VersionCatalogsExtension>().named("libs")

dependencies {
    versionCatalog.libraryAliases.forEach {alias ->
        versionCatalog.findLibrary(alias).ifPresent {
            implementation(it)
        }
    }
}

You'd need to do something similar for plugins (by their plugin id) which might be trickier. But once you have those added the update should work as normal.

@hvisser
Copy link
Contributor

hvisser commented Aug 11, 2022

Did the workaround I mentioned work for you @GeorgHoffmeyer? If it does I think the plugin does not need more additional support for now.

@GeorgHoffmeyer
Copy link
Author

Yes it worked for the dependencies. For plugins I have no solution yet.

@hvisser
Copy link
Contributor

hvisser commented Aug 12, 2022

I think the easiest way for handling plugins would be add them to your build script in the plugin block with apply false. I don't know of any Gradle APIs that can add a plugin by its plugin id like the plugin block does.

@hvisser
Copy link
Contributor

hvisser commented Aug 19, 2022

I'm going to close this for now, given that this more or less works with a bit of Gradle scripting added

@jhansche
Copy link

This can also be done by adding it to a different configuration (not implementation, which will influence the published dependencies):

val dummy by configurations.creating {
    isCanBeResolved = true
}
dependencies {
    // use whatever name was in settings.gradle; or "libs" for the default gradle/libs.versions.toml catalog
    versionCatalogs.named("publishedLibs").apply {
        libraryAliases.forEach { alias ->
            findLibrary(alias).ifPresent {
                addProvider(dummy.name, it)
            }
        }
        pluginAliases.forEach { alias ->
            findPlugin(alias).ifPresent {
                val mapped: Provider<Dependency> = it.map { plugin ->
                    // assumes that we can find the plugin using the .gradle.plugin marker:
                    create("${plugin.pluginId}:${plugin.pluginId}.gradle.plugin:${plugin.version.requiredVersion}")
                }
                addProvider(dummy.name, mapped)
            }
        }
    }
}

This allows the DependencyUpdatesTask to pick it up automatically and include the updates in that report.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants