简体   繁体   中英

How can I use gradle versions file for multimodule gradle app?

I have a composite project with a structure like:

--+ composite
  |    |
  |    +- gradle
  |
  +-- application1
  |    |
  |    +- gradle
  |
  +-- application2
  |    |
  |    +- gradle
  |
  +-- application3
  |    |
  |    +- gradle

Each gradle dir has it's own libs.versions.toml file, but i want to make a single one under the root (composite) to maintain the dependency versions it a centralized way.

How can I lik the version from root file?

For example, I'm adding dependency at build.gradle.kts file at application1 like implementation("org.springdoc:springdoc-openapi-ui:${rootProject.libs.versions.openapi.get()}") , but i can't access root properties - only ext.

I'm not quite experienced at such cases. Could anyone please help with this?

If you are using subprojects, it should work to reference the catalog of the root project. If you are using composite builds, try specifying the version catalog file for each project explicitly.

See: https://docs.gradle.org/current/userguide/platforms.html#sec:sharing-catalogs

Use this for each project in the composite build - adjust the path as needed so all projects share the same file:

dependencyResolutionManagement {
    versionCatalogs {
        libs {
            from(files("../gradle/libs.versions.toml"))
        }
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM