-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add BOM generation. #1569
Merged
Merged
Add BOM generation. #1569
Changes from 6 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
0e6c1ed
Add BOM generation for Java, Kotlin and Scala.
vbabanin 5f7b731
- Remove Kotlin and Scala BOM modules.
vbabanin 85746ba
Merge branch 'main' into JAVA-3808
vbabanin efde2d2
Merge branch 'main' into JAVA-3808
vbabanin 896ea18
Merge branch 'main' into JAVA-3808
vbabanin 078cd87
Add custom generation of Scala compile versions in BOM.
vbabanin 9f67290
Update bom/build.gradle.kts
vbabanin fec231d
Merge branch 'main' into JAVA-3808
vbabanin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
group = "org.mongodb" | ||
description = "This Bill of Materials POM simplifies dependency management when referencing multiple" + | ||
" MongoDB Java Driver artifacts in projects using Gradle or Maven." | ||
|
||
dependencies { | ||
constraints { | ||
api(project(":mongodb-crypt")) | ||
api(project(":driver-core")) | ||
api(project(":bson")) | ||
api(project(":bson-record-codec")) | ||
|
||
api(project(":driver-sync")) | ||
api(project(":driver-reactive-streams")) | ||
|
||
api(project(":bson-kotlin")) | ||
api(project(":bson-kotlinx")) | ||
api(project(":driver-kotlin-coroutine")) | ||
api(project(":driver-kotlin-sync")) | ||
|
||
api(project(":bson-scala")) | ||
api(project(":driver-scala")) | ||
} | ||
} | ||
vbabanin marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -76,9 +76,10 @@ ext { | |
def projectNamesNotToBePublished = ["driver-benchmarks", "driver-lambda", "driver-workload-executor", "graalvm-native-image-app", "util", | ||
"spock", "taglets"] | ||
def publishedProjects = subprojects.findAll { !projectNamesNotToBePublished.contains(it.name) } | ||
def scalaProjects = publishedProjects.findAll { it.name.contains('scala') } | ||
def javaProjects = publishedProjects - scalaProjects | ||
def projectsWithManifest = publishedProjects.findAll {it.name != 'driver-legacy' } | ||
def bomProjects = project(":bom") | ||
def scalaProjects = publishedProjects.findAll { it.name.contains('scala') } - bomProjects | ||
def javaProjects = publishedProjects - scalaProjects - bomProjects | ||
def projectsWithManifest = publishedProjects.findAll {it.name != 'driver-legacy' } - bomProjects | ||
|
||
configure(javaProjects) { project -> | ||
apply plugin: 'maven-publish' | ||
|
@@ -169,3 +170,98 @@ configure(projectsWithManifest) { project -> | |
jar configureJarManifestAttributes(project) | ||
} | ||
} | ||
|
||
configure(bomProjects) { project -> | ||
apply plugin: 'maven-publish' | ||
apply plugin: 'signing' | ||
apply plugin: 'java-platform' | ||
|
||
// Get the Scala versions from the project property. Only major.minor versions. | ||
def scalaVersions = project.findProperty("scalaVersions")?.split(",") | ||
?.collect { it.split("\\.")[0] + "." + it.split("\\.")[1] } | ||
|
||
assert scalaVersions != null && !scalaVersions.isEmpty() : "Scala versions must be provided as a comma-separated list" + | ||
" in the 'scalaVersions' project property" | ||
|
||
publishing { | ||
publications { | ||
mavenJava(MavenPublication) { | ||
artifactId = "bom".equals(project.archivesBaseName) ? "mongodb-driver-bom" : project.archivesBaseName | ||
from components.javaPlatform | ||
|
||
// Modify the generated POM to add multiple compile versions of driver-scala or bson-scala. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Great catch 👍 |
||
// Scala multi-version support generates only one for BOM. | ||
pom.withXml { | ||
def pomXml = asNode() | ||
|
||
def dependencyManagementNode = pomXml.get("dependencyManagement")?.getAt(0) | ||
assert dependencyManagementNode : "<dependencyManagement> node not found in the generated BOM POM" | ||
|
||
def dependenciesNode = dependencyManagementNode.get("dependencies")?.getAt(0) | ||
assert dependenciesNode : "<dependencies> node not found inside <dependencyManagement>" | ||
|
||
// Check if scala dependencies are present in the BOM. | ||
def existingScalaDeps = dependenciesNode.children().findAll { | ||
it.artifactId.text().contains("scala") | ||
} | ||
|
||
existingScalaDeps.each { existingDep -> | ||
String groupId = existingDep.groupId.text() | ||
String originalArtifactId = existingDep.artifactId.text() | ||
String artifactVersion = existingDep.version.text() | ||
|
||
// Add multiple versions with Scala suffixes for each Scala-related dependency. | ||
scalaVersions.each { scalaVersion -> | ||
// Remove existing Scala version suffix (_2.12, _2.13, etc.) | ||
String baseArtifactId = originalArtifactId.replaceAll("_\\d+\\.\\d+(\\.\\d+)?\$", "") | ||
String newArtifactId = "${baseArtifactId}_${scalaVersion}" | ||
|
||
// Skip if Scala dependency with this scalaVersion already exists in BOM. | ||
if(newArtifactId != originalArtifactId) { | ||
def dependencyNode = dependenciesNode.appendNode("dependency") | ||
dependencyNode.appendNode("groupId", groupId) | ||
dependencyNode.appendNode("artifactId", newArtifactId) | ||
dependencyNode.appendNode("version", artifactVersion) | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
repositories configureMavenRepositories(project) | ||
} | ||
|
||
afterEvaluate { | ||
publishing.publications.mavenJava.pom configurePom(project) | ||
signing { | ||
useInMemoryPgpKeys(findProperty("signingKey"), findProperty("signingPassword")) | ||
sign publishing.publications.mavenJava | ||
} | ||
} | ||
|
||
tasks.withType(GenerateModuleMetadata) { | ||
enabled = false | ||
} | ||
|
||
tasks.withType(GenerateMavenPom).configureEach { | ||
doLast { | ||
def xml = file(destination).text | ||
def root = new groovy.xml.XmlSlurper().parseText(xml) | ||
|
||
def dependencies = root.dependencyManagement.dependencies.children() | ||
assert dependencies.children().size() > 1 : "BOM must contain more then one <dependency> element:\n$destination" | ||
|
||
dependencies.each { dependency -> | ||
def groupId = dependency.groupId.text() | ||
assert groupId.startsWith('org.mongodb') : "BOM must contain only 'org.mongodb' dependencies, but found '$groupId':\n$destination" | ||
/* The <scope> and <optional> tags should be omitted in BOM dependencies. | ||
This ensures that consuming projects have the flexibility to decide whether a | ||
dependency is optional in their context. The BOM's role is to provide version information, | ||
not to dictate inclusion or exclusion of dependencies. */ | ||
assert dependency.scope.size() == 0 : "BOM must not contain <scope> elements in dependency:\n$destination" | ||
assert dependency.optional.size() == 0 : "BOM must not contain <optional> elements in dependency:\n$destination" | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: no ending new line.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Applied the suggestion in another comment: #1569 (comment). Thanks!