Skip to content

Commit f8b02c8

Browse files
committed
Attach missing POM information to Gradle Plugin Marker artifact
1 parent 0805609 commit f8b02c8

File tree

1 file changed

+50
-32
lines changed

1 file changed

+50
-32
lines changed

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

Lines changed: 50 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -72,15 +72,21 @@ fun Project.configureDeployment(deployConfig: Deployed) {
7272
// For other projects, a new publication must be created instead
7373
if (isGradlePlugin) {
7474
all {
75-
if (this is MavenPublication && name == "pluginMaven") {
75+
if (this !is MavenPublication) return@all
76+
77+
if (name == "pluginMaven") {
7678
applyPublicationDetails(
77-
project = this@configureDeployment,
78-
deployConfig = deployConfig,
79-
isAndroid = isAndroid,
80-
androidSourcesJar = androidSourcesJar,
81-
javadocJar = javadocJar
79+
project = this@configureDeployment,
80+
deployConfig = deployConfig,
81+
isAndroid = isAndroid,
82+
androidSourcesJar = androidSourcesJar,
83+
javadocJar = javadocJar
8284
)
8385
}
86+
87+
// Always extend POM details to satisfy Maven Central's POM validation
88+
// (they require a bunch of metadata for each POM, which isn't filled out by default)
89+
configurePom(deployConfig)
8490
}
8591
} else {
8692
create("release", MavenPublication::class.java)
@@ -157,8 +163,45 @@ private fun MavenPublication.applyPublicationDetails(
157163
artifact(androidSourcesJar)
158164
artifact(javadocJar)
159165

166+
// Attach dependency information
160167
pom {
161-
name.set(deployConfig.artifactId)
168+
withXml {
169+
with(asNode()) {
170+
// Only add dependencies manually if there aren't any already
171+
if (children().filterIsInstance<Node>()
172+
.none { it.name().toString().endsWith("dependencies") }
173+
) {
174+
val dependenciesNode = appendNode("dependencies")
175+
val dependencies =
176+
project.configurations.getByName("implementation").allDependencies +
177+
project.configurations.getByName("runtimeOnly").allDependencies
178+
179+
dependencies
180+
.filter { it.name != "unspecified" }
181+
.forEach {
182+
with(dependenciesNode.appendNode("dependency")) {
183+
appendNode("groupId", it.group)
184+
appendNode("artifactId", it.name)
185+
appendNode("version", it.version)
186+
appendNode("scope", "runtime")
187+
}
188+
}
189+
}
190+
}
191+
}
192+
}
193+
}
194+
195+
private fun MavenPublication.configurePom(deployConfig: Deployed) {
196+
pom {
197+
// Name cannot be set directly through the property, since it somehow isn't applied to Gradle Plugin Marker's POM
198+
// (maybe that plugin removes it somehow). Therefore, use the XML builder for this node as it's still required by Maven Central
199+
withXml {
200+
with(asNode()) {
201+
appendNode("name").setValue(deployConfig.artifactId)
202+
}
203+
}
204+
162205
description.set(deployConfig.description)
163206
url.set(Artifacts.githubUrl)
164207

@@ -181,31 +224,6 @@ private fun MavenPublication.applyPublicationDetails(
181224
developerConnection.set("scm:git:ssh://github.com/${Artifacts.githubRepo}.git")
182225
url.set("${Artifacts.githubUrl}/tree/main")
183226
}
184-
185-
withXml {
186-
with(asNode()) {
187-
// Only add dependencies manually if there aren't any already
188-
if (children().filterIsInstance<Node>()
189-
.none { it.name().toString().endsWith("dependencies") }
190-
) {
191-
val dependenciesNode = appendNode("dependencies")
192-
val dependencies =
193-
project.configurations.getByName("implementation").allDependencies +
194-
project.configurations.getByName("runtimeOnly").allDependencies
195-
196-
dependencies
197-
.filter { it.name != "unspecified" }
198-
.forEach {
199-
with(dependenciesNode.appendNode("dependency")) {
200-
appendNode("groupId", it.group)
201-
appendNode("artifactId", it.name)
202-
appendNode("version", it.version)
203-
appendNode("scope", "runtime")
204-
}
205-
}
206-
}
207-
}
208-
}
209227
}
210228
}
211229

0 commit comments

Comments
 (0)