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

Plugin version management in version catalog #37

Open
malcolmSansen opened this issue Jun 28, 2024 · 6 comments
Open

Plugin version management in version catalog #37

malcolmSansen opened this issue Jun 28, 2024 · 6 comments
Labels

Comments

@malcolmSansen
Copy link

From this issue : #19

The new setup for the plugin is really great , and having all the plugins in one place is very convenient.
However, I'm wondering if it's possible to use the TOML version catalogs to have all the version, dependencies and plugins in a single location.
I attempted to use the TOML version catalogs within gradle/plugins/build.gradle.kts, but it doesn't seem to work, or perhaps I'm doing it incorrectly.

Could you please provide guidance on how to achieve this, if it's possible?

@jjohannes
Copy link
Owner

jjohannes commented Jun 30, 2024

Thanks for the feedback!

Yes it is possible to use the catalog there. But you have to use the [libraries] section for the plugins as well, because in the convention plugin approach, we define the plugin dependencies in a dependencies block just like other dependencies. I think this may be a bit confusing sometimes. But I don't think it's a bad idea. Here is how it would work:

  • Add a gradle/plugins/settings.gradle.kts file to configure that the gradle/plugins build should use the catalog. This is needed, because from the perspective of gradle/plugins, the standard catalog location would be gradle/plugins/gradle/libs.versions.toml.
dependencyResolutionManagement {
    versionCatalogs.register("libs") {
        from(files("../libs.versions.toml"))
    }
}
[libraries]
# Java libraries
...

# Gradle plugins
gradle-plugin-dependency-analysis = { module = "com.autonomousapps:dependency-analysis-gradle-plugin", version = "1.32.0" }
gradle-plugin-spotless = { module = "com.diffplug.spotless:spotless-plugin-gradle", version = "6.25.0" }
...
dependencies {
    implementation(libs.gradle.plugin.dependency.analysis)
    implementation(libs.gradle.plugin.spotless)
    ...
}

@jjohannes jjohannes changed the title Plugin version management Plugin version management in version catalog Jun 30, 2024
@malcolmSansen
Copy link
Author

Thank you for the answer it's working great.
I was missing the part in gradle/plugins/settings.gradle.kts.

I think it could be great to include it in this project too. I found it really nice to have everything in one place and I believe this it what the version catalog feature was created for.

@jlink
Copy link

jlink commented Sep 27, 2024

Not sure if my question is related or if I should open a different issue:
I'd like to use version management when adding project dependencies in plugins. Eg in file gradle/plugins/main/src/main/kotlin/my-convention.gradle.kts I'd like to replace

dependencies {
    api("org.apiguardian:apiguardian-api:1.1.2")
}

with

dependencies {
    api(libs.apiguardian)
}

given that my libs.versions.toml contains:

[versions]
apiguardian = "1.1.2"

[libraries]
apiguardian = { module = "org.apiguardian:apiguardian-api", version.ref = "apiguardian" }

The solution suggested above seems not to cover this scenario.

@malcolmSansen
Copy link
Author

From this discussion : https://discuss.gradle.org/t/using-version-catalog-plugins-in-convention-plugins/45660/6
And this related issue: gradle/gradle#17963
It's not currently possible.

but you could simplify with :

dependencies {
    api("apiguardian-api")
}

if you have follow the previous answer and have this in your gradle/plugins/build.gradle.kts:

dependencies {
    api(libs.apiguardian)
}

@jlink
Copy link

jlink commented Sep 29, 2024

@malcolmSansen Thanks for the suggestion. I couldn't get it to work and I'm not sure it's worth going into the details since it'd be a hack anyways.

I'm wondering why the concept of "one single library catalogue for everything" seems to be a no-brainer for me and is still so difficult to achieve in a build tool like Gradle. It may not be such a good idea in the first place.

@malcolmSansen
Copy link
Author

I'm not sure about it, but it seems that this features is more complicated to implements than we might expecting. Also it's still kind of new so maybe in a few version it will be better.

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

No branches or pull requests

3 participants