Skip to content

Commit 3142928

Browse files
authored
use gradle java-platform in grpc-bom; Fixes #5530 (#11875)
* use gradle java-platform in grpc-bom; Fixes #5530 * fix withXml * explicitly exclude grpc-compiler
1 parent 199a7ea commit 3142928

File tree

1 file changed

+18
-26
lines changed

1 file changed

+18
-26
lines changed

bom/build.gradle

+18-26
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,32 @@
11
plugins {
2+
id 'java-platform'
23
id "maven-publish"
34
}
45

56
description = 'gRPC: BOM'
67

8+
gradle.projectsEvaluated {
9+
def projectsToInclude = rootProject.subprojects.findAll {
10+
return it.name != 'grpc-compiler'
11+
&& it.plugins.hasPlugin('java')
12+
&& it.plugins.hasPlugin('maven-publish')
13+
&& it.tasks.findByName('publishMavenPublicationToMavenRepository')?.enabled
14+
}
15+
dependencies {
16+
constraints {
17+
projectsToInclude.each { api it }
18+
}
19+
}
20+
}
21+
722
publishing {
823
publications {
924
maven(MavenPublication) {
10-
// remove all other artifacts since BOM doesn't generates any Jar
11-
artifacts = []
12-
25+
from components.javaPlatform
1326
pom.withXml {
14-
// Generate bom using subprojects
15-
def internalProjects = [
16-
project.name,
17-
'grpc-compiler',
18-
]
19-
20-
def dependencyManagement = asNode().appendNode('dependencyManagement')
21-
def dependencies = dependencyManagement.appendNode('dependencies')
22-
rootProject.subprojects.each { subproject ->
23-
if (internalProjects.contains(subproject.name)) {
24-
return
25-
}
26-
if (!subproject.hasProperty('publishMavenPublicationToMavenRepository')) {
27-
return
28-
}
29-
if (!subproject.publishMavenPublicationToMavenRepository.enabled) {
30-
return
31-
}
32-
def dependencyNode = dependencies.appendNode('dependency')
33-
dependencyNode.appendNode('groupId', subproject.group)
34-
dependencyNode.appendNode('artifactId', subproject.name)
35-
dependencyNode.appendNode('version', subproject.version)
36-
}
27+
def dependencies = asNode().dependencyManagement.dependencies.last()
3728
// add protoc gen (produced by grpc-compiler with different artifact name)
29+
// not sure how to express "<type>pom</type>" in gradle, kept in XML
3830
def dependencyNode = dependencies.appendNode('dependency')
3931
dependencyNode.appendNode('groupId', project.group)
4032
dependencyNode.appendNode('artifactId', 'protoc-gen-grpc-java')

0 commit comments

Comments
 (0)