Skip to content

Commit 1605270

Browse files
authored
Fix javadoc missing generated API (#200)
Move Dokka configuration to the `jvm-library` plugin, which is applied before `test-suites`, and stop passing a fixed source root for Dokka so that generated API source set is included. Also fix some configuration avoidance smells. When refactoring build logic into plugins, Dokka stopped recognizing the correct source set. #199 fixed this by passing a specific source root to Dokka, but this caused the resulting javadoc to not include the generated API. Bisecting shows that moving the test suite setup (456f769), making test suites be set up before Dokka, was when the issue started.
1 parent 20a64fd commit 1605270

File tree

6 files changed

+58
-54
lines changed

6 files changed

+58
-54
lines changed

build-logic/build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ gradlePlugin {
1818

1919
dependencies {
2020
implementation("org.jetbrains.kotlin:kotlin-gradle-plugin:1.9.23")
21+
implementation("org.jetbrains.dokka:dokka-gradle-plugin:1.9.20")
2122
implementation("org.openapitools:openapi-generator-gradle-plugin:7.4.0")
2223
"functionalTestImplementation"(project)
2324
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,49 @@
11
package com.gabrielfeo
22

3+
import org.jetbrains.dokka.DokkaConfiguration.Visibility.PUBLIC
4+
import org.jetbrains.dokka.gradle.DokkaTask
5+
import java.net.URL
6+
37
plugins {
48
id("org.jetbrains.kotlin.jvm")
9+
id("org.jetbrains.dokka")
510
`java-library`
611
}
12+
13+
val repoUrl: Provider<String> = providers.gradleProperty("repo.url")
14+
15+
java {
16+
withSourcesJar()
17+
withJavadocJar()
18+
toolchain {
19+
languageVersion.set(JavaLanguageVersion.of(11))
20+
vendor.set(JvmVendorSpec.AZUL)
21+
}
22+
}
23+
24+
tasks.withType<DokkaTask>().configureEach {
25+
dokkaSourceSets.all {
26+
sourceRoot("src/main/kotlin")
27+
sourceLink {
28+
localDirectory.set(file("src/main/kotlin"))
29+
remoteUrl.set(repoUrl.map { URL("$it/blob/$version/src/main/kotlin") })
30+
remoteLineSuffix.set("#L")
31+
}
32+
jdkVersion.set(11)
33+
suppressGeneratedFiles.set(false)
34+
documentedVisibilities.set(setOf(PUBLIC))
35+
perPackageOption {
36+
matchingRegex.set(""".*\.internal.*""")
37+
suppress.set(true)
38+
}
39+
externalDocumentationLink("https://kotlinlang.org/api/kotlinx.coroutines/")
40+
externalDocumentationLink("https://square.github.io/okhttp/4.x/okhttp/")
41+
externalDocumentationLink("https://square.github.io/retrofit/2.x/retrofit/")
42+
externalDocumentationLink("https://square.github.io/moshi/1.x/moshi/")
43+
externalDocumentationLink("https://square.github.io/moshi/1.x/moshi-kotlin/")
44+
}
45+
}
46+
47+
tasks.named<Jar>("javadocJar") {
48+
from(tasks.dokkaHtml)
49+
}

build-logic/src/main/kotlin/com/gabrielfeo/test-suites.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ kotlin {
3434
}
3535

3636
// TODO Unapply test-fixtures and delete the source set, since we're not publishing it?
37-
components.getByName<AdhocComponentWithVariants>("java").apply {
37+
components.named<AdhocComponentWithVariants>("java") {
3838
withVariantsFromConfiguration(configurations["testFixturesApiElements"]) { skip() }
3939
withVariantsFromConfiguration(configurations["testFixturesRuntimeElements"]) { skip() }
4040
}

build.gradle.kts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +0,0 @@
1-
plugins {
2-
id("org.jetbrains.dokka") version "1.9.20" apply false
3-
}

gradle.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ group=com.gabrielfeo
22
artifact=develocity-api-kotlin
33
version=2024.1.0
44
develocity.version=2024.1
5+
repo.url=https://github.com/gabrielfeo/develocity-api-kotlin
56
org.gradle.jvmargs=-Xmx5g
67
org.gradle.caching=true
78
# Becomes default in Gradle 9.0

library/build.gradle.kts

Lines changed: 12 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -8,57 +8,18 @@ plugins {
88
id("com.gabrielfeo.kotlin-jvm-library")
99
id("com.gabrielfeo.develocity-api-code-generation")
1010
id("com.gabrielfeo.test-suites")
11-
id("org.jetbrains.dokka")
1211
`java-library`
1312
`maven-publish`
1413
signing
1514
kotlin("jupyter.api") version "0.12.0-181"
1615
}
1716

18-
val repoUrl = "https://github.com/gabrielfeo/develocity-api-kotlin"
19-
20-
java {
21-
withSourcesJar()
22-
withJavadocJar()
23-
toolchain {
24-
languageVersion.set(JavaLanguageVersion.of(11))
25-
vendor.set(JvmVendorSpec.AZUL)
26-
}
27-
}
28-
29-
tasks.withType<DokkaTask>().configureEach {
30-
dokkaSourceSets.register("main") {
31-
sourceRoot("src/main/kotlin")
32-
sourceLink {
33-
localDirectory.set(file("src/main/kotlin"))
34-
remoteUrl.set(URL("$repoUrl/blob/$version/src/main/kotlin"))
35-
remoteLineSuffix.set("#L")
36-
}
37-
jdkVersion.set(11)
38-
suppressGeneratedFiles.set(false)
39-
documentedVisibilities.set(setOf(PUBLIC))
40-
perPackageOption {
41-
matchingRegex.set(""".*\.internal.*""")
42-
suppress.set(true)
43-
}
44-
externalDocumentationLink("https://kotlinlang.org/api/kotlinx.coroutines/")
45-
externalDocumentationLink("https://square.github.io/okhttp/4.x/okhttp/")
46-
externalDocumentationLink("https://square.github.io/retrofit/2.x/retrofit/")
47-
externalDocumentationLink("https://square.github.io/moshi/1.x/moshi/")
48-
externalDocumentationLink("https://square.github.io/moshi/1.x/moshi-kotlin/")
49-
}
50-
}
51-
5217
tasks.processJupyterApiResources {
5318
libraryProducers = listOf(
5419
"com.gabrielfeo.develocity.api.internal.jupyter.DevelocityApiJupyterIntegration",
5520
)
5621
}
5722

58-
tasks.named<Jar>("javadocJar") {
59-
from(tasks.dokkaHtml)
60-
}
61-
6223
tasks.named<Test>("integrationTest") {
6324
environment("DEVELOCITY_API_LOG_LEVEL", "DEBUG")
6425
}
@@ -94,6 +55,7 @@ dependencies {
9455
val libraryPom = Action<MavenPom> {
9556
name.set("Develocity API Kotlin")
9657
description.set("A library to use the Develocity API in Kotlin")
58+
val repoUrl = providers.gradleProperty("repo.url")
9759
url.set(repoUrl)
9860
licenses {
9961
license {
@@ -110,27 +72,27 @@ val libraryPom = Action<MavenPom> {
11072
}
11173
}
11274
scm {
113-
val basicUrl = repoUrl.substringAfter("://")
114-
connection.set("scm:git:git://$basicUrl.git")
115-
developerConnection.set("scm:git:ssh://$basicUrl.git")
116-
url.set("https://$basicUrl/")
75+
val basicUrl = repoUrl.map { it.substringAfter("://") }
76+
connection.set(basicUrl.map { "scm:git:git://$it.git" })
77+
developerConnection.set(basicUrl.map { "scm:git:ssh://$it.git" })
78+
url.set(basicUrl.map { "https://$it/" })
11779
}
11880
}
11981

12082
publishing {
12183
publications {
122-
create<MavenPublication>("develocityApiKotlin") {
84+
register<MavenPublication>("develocityApiKotlin") {
12385
artifactId = "develocity-api-kotlin"
12486
from(components["java"])
12587
pom(libraryPom)
12688
}
12789
// For occasional maven local publishing
128-
create<MavenPublication>("unsignedDevelocityApiKotlin") {
90+
register<MavenPublication>("unsignedDevelocityApiKotlin") {
12991
artifactId = "develocity-api-kotlin"
13092
from(components["java"])
13193
pom(libraryPom)
13294
}
133-
create<MavenPublication>("relocation") {
95+
register<MavenPublication>("relocation") {
13496
artifactId = "gradle-enterprise-api-kotlin"
13597
pom {
13698
libraryPom(this)
@@ -165,10 +127,10 @@ publishing {
165127
fun isCI() = System.getenv("CI").toBoolean()
166128

167129
signing {
168-
sign(
169-
publishing.publications["develocityApiKotlin"],
170-
publishing.publications["relocation"],
171-
)
130+
val signedPublications = publishing.publications.matching {
131+
!it.name.contains("unsigned", ignoreCase = true)
132+
}
133+
sign(signedPublications)
172134
if (isCI()) {
173135
useInMemoryPgpKeys(
174136
project.properties["signing.secretKey"] as String?,

0 commit comments

Comments
 (0)