Skip to content

Commit c809b11

Browse files
committed
Fix javadoc publication for multiplatform build
1 parent 7055b18 commit c809b11

File tree

2 files changed

+24
-20
lines changed

2 files changed

+24
-20
lines changed

buildSrc/src/main/kotlin/ru/nsk/maven-publish.gradle.kts

+23-20
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,6 @@ plugins {
99
signing
1010
}
1111

12-
java {
13-
// maven central requires these .jar files even if they are empty
14-
withSourcesJar()
15-
withJavadocJar()
16-
}
17-
1812
/**
1913
* Local configuration with credentials is stored in local.properties file that is not under vcs.
2014
* local.properties file structure sample:
@@ -30,21 +24,25 @@ val localProperties = Properties().apply {
3024
if (file.exists()) load(file.reader())
3125
}
3226

33-
publishing {
34-
35-
val (resolvedGroupId, resolvedVersion) = if (project.group == Versions.libraryJitPackGroup) {
36-
// JitPack passes this in arguments
37-
project.group.toString() to project.version.toString()
38-
} else {
39-
rootProject.group.toString() to rootProject.version.toString()
27+
afterEvaluate {
28+
tasks.create<Jar>("javadocJar") {
29+
archiveClassifier.set("javadoc")
30+
from(tasks.named("dokkaHtml"))
4031
}
32+
}
33+
34+
publishing {
35+
val resolvedGroupId = if (project.group == Versions.libraryJitPackGroup)
36+
project.group.toString() // JitPack passes this as arguments
37+
else
38+
rootProject.group.toString()
4139

4240
// Publication is created by multiplatform plugin itself
4341
// this code references it and configures
4442
publications.withType<MavenPublication> {
45-
artifactId = project.name
46-
groupId = resolvedGroupId
47-
version = resolvedVersion
43+
afterEvaluate {
44+
artifact(tasks.named("javadocJar"))
45+
}
4846

4947
pom {
5048
name.set(project.name)
@@ -97,7 +95,7 @@ publishing {
9795
}
9896
}
9997

100-
private val executable = localProperties.getProperty("signing.gnupg.executable")
98+
val executable = localProperties.getProperty("signing.gnupg.executable")
10199
if (executable != null) {
102100
ext.set("signing.gnupg.executable", executable)
103101

@@ -114,14 +112,19 @@ if (executable != null) {
114112
}
115113
}
116114
} else { // try getting from environment (GitHub flow)
117-
val signingKeyId: String? by project // must be the last 8 digits of the key
118115
val signingKey: String? by project
119116
val signingPassword: String? by project
120117

121-
if (signingKeyId != null && signingKey != null && signingPassword != null) {
118+
if (signingKey != null && signingPassword != null) {
122119
signing {
123-
useInMemoryPgpKeys(signingKeyId, signingKey, signingPassword)
120+
useInMemoryPgpKeys(signingKey, signingPassword)
124121
sign(publishing.publications)
125122
}
126123
}
124+
}
125+
126+
// workaround for gradle warning about task order. should be removed with gradle 8
127+
val signingTasks = tasks.withType<Sign>()
128+
tasks.withType<AbstractPublishToMaven>().configureEach {
129+
dependsOn(signingTasks)
127130
}

gradle.properties

+1
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
kotlin.code.style=official
2+
org.gradle.jvmargs=-Xmx1g

0 commit comments

Comments
 (0)