I have a Gradle project which uses Spring\'s dependency management plugin to define a list of dependency versions. I am also using the Maven plugin to deploy the project to
In Gradle 6+ versions, we can use Gradle Java Platform Plugin to publish a maven-bom without many configurations and scripting.
group 'test.platform.simple.bom'
version '1.0.0-SNAPSHOT'
repositories {
maven {
mavenCentral()
}
}
apply plugin: 'java-platform'
apply plugin: 'maven-publish'
javaPlatform {
allowDependencies()
}
dependencies {
constraints {
api 'cglib:cglib-nodep:3.2.4'
api 'junit:junit:4.12'
// runtime 'org.postgresql:postgresql:42.2.5' <-- runtime constraint
// api project(":core") <-- constraint from local project
// api platform('com.fasterxml.jackson:jackson-bom:2.9.8') <-- constraint from another platform
}
}
publishing {
publications {
maven(MavenPublication) {
from components.javaPlatform
}
}
}
Dependencies to be managed can be defined under dependencies as api or runtime constraints. Constraints can be utilized to manage dependencies from a local project as well as from another platform/bom. Please note that we need to configure a Maven publication that uses the javaPlatform component to get it published as a maven bom artifact.