Skip to content

Commit c8d5834

Browse files
authored
Fix source/doc jar publication (#3060)
1 parent f931f10 commit c8d5834

File tree

1 file changed

+28
-33
lines changed

1 file changed

+28
-33
lines changed

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

Lines changed: 28 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,41 @@ abstract class PublicationPlugin : Plugin<Project> {
2626
definedVersion
2727
}
2828

29+
// Create placeholder jars to satisfy Central Portal validation.
30+
// See https://central.sonatype.org/publish/requirements/#supply-javadoc-and-sources
31+
val readmePath = "$rootDir/gradle/"
32+
val sourcePlaceholderJar =
33+
tasks.register("sourcePlaceholderJar", Jar::class.java) {
34+
archiveBaseName.set("${localGradleProperty("POM_NAME").get()}")
35+
archiveVersion.set(this@with.version.toString())
36+
archiveClassifier.set("sources")
37+
from(layout.projectDirectory.file("$readmePath/README-sources.md")) {
38+
into("")
39+
rename { "README.md" }
40+
}
41+
}
42+
43+
val docsPlaceholderJar =
44+
tasks.register("docsPlaceholderJar", Jar::class.java) {
45+
archiveBaseName.set("${localGradleProperty("POM_NAME").get()}")
46+
archiveVersion.set(this@with.version.toString())
47+
archiveClassifier.set("javadoc")
48+
from(layout.projectDirectory.file("$readmePath/README-javadoc.md")) {
49+
into("")
50+
rename { "README.md" }
51+
}
52+
}
53+
2954
extensions.configure<PublishingExtension> {
3055
publications {
3156
register<MavenPublication>("maven") {
3257
groupId = localGradleProperty("POM_GROUP_ID").get()
3358
version = version.toString()
3459
artifactId = localGradleProperty("POM_ARTIFACT_ID").get()
3560

61+
artifact(sourcePlaceholderJar)
62+
artifact(docsPlaceholderJar)
63+
3664
pom {
3765
name.set(localGradleProperty("POM_NAME"))
3866
description.set(providers.gradleProperty("POM_DESCRIPTION"))
@@ -117,44 +145,11 @@ abstract class PublicationPlugin : Plugin<Project> {
117145
sign(the<PublishingExtension>().publications["maven"])
118146
isRequired = enableSigning && !version.toString().endsWith("SNAPSHOT")
119147
}
120-
121-
project.createPlaceholderJarTasks()
122148
}
123149

124150
// TODO: remove this once https://github.com/gradle/gradle/issues/23572 is fixed
125151
fun Project.localGradleProperty(name: String): Provider<String> =
126152
provider {
127153
if (hasProperty(name)) property(name)?.toString() else null
128154
}
129-
130-
// Create placeholder jars to satisfy Central Portal validation.
131-
// See https://central.sonatype.org/publish/requirements/#supply-javadoc-and-sources
132-
private fun Project.createPlaceholderJarTasks() {
133-
val readmePath = "$rootDir/gradle/"
134-
val sourcePlaceholderJar =
135-
tasks.register("sourcePlaceholderJar", Jar::class.java) {
136-
archiveBaseName.set("${localGradleProperty("POM_NAME").get()}")
137-
archiveVersion.set(this@createPlaceholderJarTasks.version.toString())
138-
archiveClassifier.set("sources")
139-
from(layout.projectDirectory.file("$readmePath/README-sources.md")) {
140-
into("")
141-
rename { "README.md" }
142-
}
143-
}
144-
145-
val docsPlaceholderJar =
146-
tasks.register("docsPlaceholderJar", Jar::class.java) {
147-
archiveBaseName.set("${localGradleProperty("POM_NAME").get()}")
148-
archiveVersion.set(this@createPlaceholderJarTasks.version.toString())
149-
archiveClassifier.set("javadoc")
150-
from(layout.projectDirectory.file("$readmePath/README-javadoc.md")) {
151-
into("")
152-
rename { "README.md" }
153-
}
154-
}
155-
156-
tasks.named("publishMavenPublicationToMavenCentralRepository") {
157-
dependsOn(sourcePlaceholderJar, docsPlaceholderJar)
158-
}
159-
}
160155
}

0 commit comments

Comments
 (0)