Is there any example on how to use gradle version ...
# gradle
h
Is there any example on how to use gradle version catalog toml where the BOM of spring boot is defined as platform so I don’t need to specify any version of the dependencies that is already provided by that BOM? And how do I override/pin just one version let’s say for the H2 database (com.h2databsse) to an older version? And add additional dependencies that are not there in the spring boot BOM?
Note I'm working with a multi module project. And not all subprojects needs spring boot, but would like to have the dependency version from spring boot to be applied to some of the subprojects. Other subprojects are dependent on spring boot.
v
Either use the constant in the spring boot plugin that has the BOM coordinates for the
platform(...)
call, or redeclare it in your version catalog and use that, up to you. For libs with versions coming from the BOM, just declare then without version in the catalog, much like when directly doing it in the build script. For the additional dependencies, just declare them as usual in the version catalog. Regarding downgrading a version from the BOM, this has nothing to do with version catalogs. Version catalogs are not platforms. They do not directly influence resolution. They are just a catalog of libraries and plugins to choose from. So to downgrade a version use the usual ways like strict versions: https://docs.gradle.org/current/userguide/dependency_downgrade_and_exclude.html
c
Here's an example with the Compose BOM: you add the version to the BOM, and specify no version for everything covered by the DOM: https://gitlab.com/opensavvy/decouple/-/blob/110-gradle/gradle/libs.versions.toml#L57
h
Thanks I'll take a look at it.
Still unsure of this is the way to go, I would like to define that BOM_COORDINATES in the toml file. Or shouldn't I do that there?
Copy code
[versions]
kotlin = "1.8.0"
spring-boot-version = "3.0.4"
spring-boot-management = "1.1.0"

[libraries]
spring-boot-bom = { module = "org.springframework.boot.gradle.plugin.SpringBootPlugin.BOM_COORDINATES" }

[bundles]

[plugins]
spring-boot = { id = "org.springframework.boot", version.ref = "spring-boot-version" }
spring-dependencymanager = { id = "io.spring.dependency-management", version.ref = "spring-boot-management" }
kotlin-lang = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin" }
kotlin-spring = { id = "org.jetbrains.kotlin.plugin.spring", version.ref = "kotlin" }
And maybe I don't need dependency-management from SprnigBoot as I'm using this gradle version catalog.
v
You cannot use
BOM_COORDINATES
in the version catalog. Either you put the actual coordinates into your version catalog, or you use that constant. And you should remove the Spring Dependency Management plugin. It is a relict from former times when Gradle had no built-in BOM support. Even its maintainer recommends not to use it anymore.
Whether you use the spring dependency management plugin or not has nothing to do with whether you use the version catalog or not. Even without version catalog, you should not use it.
h
Seems like I need more than just an hour to figure this out. Hope I’ve some time this weekend to get a simple project to compile.
752 Views