Gradle : Something like Maven Parent POM

In our company, many of the different projects use similar technology stack and will have many common features.
So, we want to maintain the common features, dependencies etc. in one common file and refer it in the other projects.
In maven, it is something like creating a separate maven project with the common dependency information and refer that in the other projects as .

I want to do something similar to the maven parent project in gradle, which can be used by all different projects.
I googled for that, but could not find a concise information on how to do that.
We are not allowed to use external thirdparty plugins.

It would be great if someone could explain it how to do that.

Just create commons module with all dependencies you need and use that as a dependency in your projects, like so:

// settings.gradle:
include “:commons”
include “:first-project-uses-commons”
include “:second-project-uses-commons”

// build.gradle
project(“:commons”) {
  dependencies {
    compile ....
  }
}
project(“:first-project-uses-commons”) {
  dependencies {
    compile project(“:commons”)
  }
}
project(“:second-project-uses-commons”) {
  dependencies {
    compile project(“:commons”)
  }
}

If you need reuse some project in different projects not in same tree look at the documentation for included-builds

Gradle can propose u also other way to do same using configurations, such as allprojects or subptojects

You can maintain Maven BOM in Gradle:


https://plugins.gradle.org/plugin/io.spring.dependency-management

Gradle 4.6 introduced core support for importing BOMs without the need for third party plugins

https://docs.gradle.org/4.6/release-notes.html#bom-import

Do we have any new features or strategies that should be followed to implement the concept of maven parentPom in Gradle? What is the recommended solution to do so?

There is no need to.
You should not follow the advice from this thread as they are heavily outdated except for the last one.
But if you want to centrally declare versions and coordinates, use a version catalog.
If you want to similar build configuration for multiple projects, use convention plugins.
If you want to consume a BOM, use the built-in BOM support.

1 Like