Skip to content

Commit 86410bb

Browse files
committed
Update pom.xml definition to account for BOM & local project dependencies
1 parent 8d8cfeb commit 86410bb

File tree

1 file changed

+33
-5
lines changed

1 file changed

+33
-5
lines changed

build-logic/src/main/kotlin/Deployment.kt

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,15 @@
33
import groovy.util.Node
44
import org.gradle.api.NamedDomainObjectCollection
55
import org.gradle.api.Project
6+
import org.gradle.api.artifacts.Dependency
7+
import org.gradle.api.artifacts.ProjectDependency
68
import org.gradle.api.plugins.ExtensionAware
79
import org.gradle.api.plugins.ExtraPropertiesExtension
810
import org.gradle.api.publish.PublishingExtension
911
import org.gradle.api.publish.maven.MavenPublication
1012
import org.gradle.api.tasks.SourceSet
1113
import org.gradle.api.tasks.SourceSetContainer
14+
import org.gradle.configurationcache.extensions.capitalized
1215
import org.gradle.jvm.tasks.Jar
1316
import org.gradle.kotlin.dsl.withGroovyBuilder
1417
import org.gradle.plugins.signing.SigningExtension
@@ -208,12 +211,17 @@ private fun MavenPublication.applyPublicationDetails(
208211
dependencies
209212
.mapValues { entry -> entry.value.filter { it.name != "unspecified" } }
210213
.forEach { (scope, dependencies) ->
211-
dependencies.forEach {
214+
dependencies.forEach { dep ->
212215
with(dependenciesNode.appendNode("dependency")) {
213-
appendNode("groupId", it.group)
214-
appendNode("artifactId", it.name)
215-
appendNode("version", it.version)
216-
appendNode("scope", scope)
216+
if (dep is ProjectDependency) {
217+
appendProjectDependencyCoordinates(dep)
218+
} else {
219+
appendExternalDependencyCoordinates(dep)
220+
}
221+
222+
// Rewrite scope definition for BOM dependencies
223+
val isBom = "-bom" in dep.name
224+
appendNode("scope", if (isBom) "import" else scope)
217225
}
218226
}
219227
}
@@ -223,6 +231,26 @@ private fun MavenPublication.applyPublicationDetails(
223231
}
224232
}
225233

234+
private fun Node.appendProjectDependencyCoordinates(dep: ProjectDependency) {
235+
// Find the external coordinates for the given project dependency
236+
val projectName = dep.name
237+
238+
val config = Artifacts.Instrumentation::class.java
239+
.getMethod("get${projectName.capitalized()}")
240+
.invoke(Artifacts.Instrumentation)
241+
as Deployed
242+
243+
appendNode("groupId", config.groupId)
244+
appendNode("artifactId", config.artifactId)
245+
appendNode("version", config.latestStableVersion)
246+
}
247+
248+
private fun Node.appendExternalDependencyCoordinates(dep: Dependency) {
249+
appendNode("groupId", dep.group)
250+
appendNode("artifactId", dep.name)
251+
dep.version?.let { appendNode("version", it) }
252+
}
253+
226254
private fun MavenPublication.configurePom(deployConfig: Deployed) = also {
227255
pom {
228256
// Name and description cannot be set directly through the property, since they somehow aren't applied

0 commit comments

Comments
 (0)