This message was deleted.
# community-support
s
This message was deleted.
v
That error is thrown if you try to import multiple toml files into one catalog, which is not supported. You are pretty free how you want it. You e. g. can have one version catalog per build, or you can have one version catalog with all versions at the root project and include that in all the included builds, is any middle way.
s
Can you elaborate on how can I include a version catalog that is defined in the root project for the included builds?
The error does not exactly reflect what I’m trying to do. I am trying to include the same toml file into the same catalog. I think I get this is error because I have the same catalog being setup in multiple places. Which I suppose is not the correct practice.
v
It is the right practice if I got you right. Can you show what you tried? Optimally with an MCVE.
e
Can you elaborate on how can I include a version catalog that is defined in the root project for the included builds?
Something like this in your included build's settings.gradle.kts
Copy code
@Suppress("UnstableApiUsage")
dependencyResolutionManagement {
  versionCatalogs {
    create("libs") {
      from(files("../gradle/libs.versions.toml"))
    }
  }
}
s
Not exactly minimal but I have a repro project I’ve setup at https://github.com/satyarths/composite-build . I have an android project and a plugin project which I’m adding to a separate root project and trying to share the same version catalog amongst them .
Also I’m new to composite-builds so please do suggest if there is a better way to structure this 🙂 .
v
To start with, you should not use the
-all
distribution. In your situation it has no pros at all. It only wastes time, diskspace, and bandwidth for everyone running the build. The
-all
distribution only has one advantage and only if you use Groovy DSL and only while you edit or debug the build scripts. Even with Groovy DSL, it wastes the same things mentioned above for anyone or anything just executing the build. Using the
-all
distribution is mainly a work-around for an IDE bug that hopefully gets fixed one day. Another detail, but that is mainly optics, is that it is only unnecessary clutter to wrap
dependencyResolutionManagement
within
dependencyResolutionManagement
as you did it in multiple places there. Regarding the problem, it is because
gradle/libs.versions.toml
is automatically considered. So by importing "another" file into the "libs" catalog of your root
settings.gradle.kts
file you trigger the error. There could be a leniency added that this is allowed for the same file, but currently it is not. Just remove the declaration from the root
settings.gradle.kts
and it works.
s
Oh okay, I was using the all distribution so that I have access to sources. TIL that its not needed. The nested dependencyResolutionBlocks is just copy pasta 🙈 ..Will fix that. So is it that
gradle/libs.versions.toml
would be automatically considered or is there a file pattern that would be considered be default?
Also do you mean I need not define the versionCatalog in any other (
.gradle
)file? All the projects that are a part of the composite build would work?
v
gradle/libs.versions.toml
is exactly the one that is considered automatically. But only within that build. For the included builds you need to include manually like you have it if you want to use the same catalog.
I also created https://github.com/gradle/gradle/issues/21328 if you like to thumbs-up it
1
s
Thank you , that helped. I’ve got the setup working. Are there ways to share configuration across composite builds? These could include for example plugins , dependency resolution and properties. I’m not sure if that requirement makes sense though or if that could cause things to break .
v
The idiomatic way is to have in another included build convention plugins that do the shared logic and then in the other builds you can include that build and apply the convention plugin(s)
s
Ah yes . That’s better. Thank you !
Came across a good resource to understand version catalog usage at https://melix.github.io/blog/2021/03/version-catalogs-faq.html
👍 1
I was also reading into https://github.com/gradle/gradle/issues/16078 to understand if declaring plugins in the version catalog is supported or not. The thread mentions that this is not supported, however the last example shows a way to use it. So is the conclusion that it can work but is not officially supported 🤔?
v
There was a way in the beginning. I complained because it was inconsistent and confusing. Then they removed it. Latter they added a better way. So yes, you can declare plugins in version catalogs now. Better read the documentation instead of old tickets. :-)
s
Sure, I was searching the gradle documentation for information on this. And came across the ticket 😅 . Found the documentation at https://docs.gradle.org/current/userguide/platforms.html#sec:plugins.
v
Exactly