I stumbled upon an interesting issue in the Depend...
# community-support
t
I stumbled upon an interesting issue in the Dependency Analysis Gradle Plugin (github.com/autonomousapps/dependency-analysis-gradle-plugin/issues/1990) which basically comes down to the issue that it there is no semantic relationship between a library that is declared without version in
libs.versions.toml
and the bill-of-material that will do the job via a
platform(…)
declaration encoded anywhere. Developers basically stumble upon the same issue all the time when they forget to specify the BOM alongside the dependency that they want to use. Would it therefor be a useful extension to introduce a
bom.ref
in addition to
version.ref
, just that the former needs to point to another artifact that is then used to align the versions?
p
A little bit unrelated but if the producer also uses Gradle and dependency constraints, you don't need a BOM: https://jakewharton.com/defuse-the-compose-bom/
v
I doubt that the version catalog will get something like
bom.ref
. It intentionally is just a catalog of coordinates and versions without semantic meaning. You can use an entry in different ways. With different attributes for example (like using as bom or as library, or requesting a specific artifact, and so on). So I doubt such a semantic addition will make it into the version catalog. Also, if you use a bom for version alignment, that is not the right way anyway. If a set of libraries depends that you use the same version amongst all of them, then that project should properly publish the alignment information using the Gradle Module Metadata. Because just because you use in your projects the libraries without version and specify a BOM to supply the versions, you can still depend on some other library that depends on one of those libraries in a newer version, and then only that library is used in a newer version while the others still use the version from the BOM. Of course you could force-downgrade then, but that library might then not work properly if it really needs the version it declares it needs. If the project properly publishes the version alignment, then all the modules would be upgraded due to that one transitive dependency and thus you get a consistent set of dependencies. So imho the much better way forward would be to bring all such multi-module projects to properly publish version alignment metadata for the benefit of all Gradle consumers. See blog.gradle.org/alignment-with-gradle-module-metadata for more information on that.
t
sort of related. I’ve been meaning to write this up as a blog post, but I wrote a new plugin recently that helps with this, the platform-builder plugin. The readme explains the basics of how to use it. Essentially, it allows you to create a “bom” or platform from the resolved dependency graph. If you then apply this platform to all of your projects via a convention plugin, then you have solved the version alignment problem (or that’s the goal; feel free to file issues). I’ve used this with success at a recent client engagement. We treated most of the version catalog as the source of constraints, but that’s kind of a naive approach with some edge cases
t
I see the BOM Compose and others provide rather as a bike-shed-free alternative to provide individual dependencies, i.e. like some kind of “common distribution”. If I rely completely on Gradle Module Data (under the assumption these are correctly published), then yes, things would maybe continue to compile and work together, but I’d still have to take care / track / bump the version of many individual artifacts. And AndroidX libraries are in general specifically problematic here, because some of their artifact groups adhere to the “same group id = same version” paradigm, while others don’t (e.g.
androidx.core
or
androidx.test
). Yes, for the latter they don’t even provide a BOM, but from my understanding the reason why Google introduced the Compose BOM in first place was also to give the individual artifacts the possibility to evolve independently from another, with different versions, so my fear is that we’ll see this kind of version chaos in Compose as well.
@tony Interestingly before there where version catalogues I had a central “platform” definition in a platform module through which I dependency-locked and shared all of my dependencies (by hand). Then version catalogues came along and provided the new default “go-to” solution that was also fully supported by automations like dependabot. Now we go back to platforms again because we figure dependency alignment is (more) important than easy dependency declaration.
For dependency updating / locking I now use a common convention plugin that implements
configurations.all { resolutionStrategy { eachDependency { … } } }
where I list things that I want to have globally aligned.
t
I think updating your common convention to also universally apply all the BOMs you care about would also be worth doing. I’ve benchmarked it, and unnecessary constraints (those that are never “used”) don’t hurt performance, so there’s no downside. And the upside is you won’t need any
platform(...)
declarations in your build scripts
t
Hrm, never thought of that - you’re right, that might be a useful technique. Thanks!
✊ 1