Use BOM in dependencyResolutionManagement

Hi,

I have a multi module project where i have centralized some dependencies in a dependencies.gradle file that is applied in the settings.gradle (apply from: './dependencies.gradle')

I want to be able to use BOM files to determine dependency versions so that instead of doing

dependencyResolutionManagement {
  versionCatalogs {
    testLibs {
      def junitVersion = '5.12.0'
      library('junitJupiter', "org.junit.jupiter:junit-jupiter:$junitVersion")
      library('junitJupiterEngine', "org.junit.jupiter:junit-jupiter-engine:$junitVersion")
      library('junitJupiterApi', "org.junit.jupiter:junit-jupiter-api:$junitVersion")
    }
  }
}

I want to use the bom file so i dont need to specify the version for the individual artifacts i.e something like this:

dependencyResolutionManagement {
  versionCatalogs {
    testLibs {
      library('junitBom',  platform("org.junit:junit-bom:5.12.0"))
      library('junitJupiter', "org.junit.jupiter:junit-jupiter")
      library('junitJupiterEngine', "org.junit.jupiter:junit-jupiter-engine")
      library('junitJupiterApi', "org.junit.jupiter:junit-jupiter-api")
    }
  }
}

However platform cannot be used in this context:
Could not find method platform() for arguments [org.junit:junit-bom:5.12.0] on object of type org.gradle.api.internal.catalog.DefaultVersionCatalogBuilder.
Is there are way to do this?

Some points:

  • things you use with “apply from” are called legacy script plugins, have many quirks, and are better avoided
  • to use “trivial” version catalogs (not something calculated or similar) better use a TOML file than the API, that has various advantages
  • version catalogs are a collection of coordinates and versions, how a version catalog entry is used later on is a separate topic, this you cannot mark a version catalog entry as platform, as that is a use-site detail that does not belong to the version catalog
1 Like