Skip to content

Commit f4724d7

Browse files
committed
Aggregate javadoc using build-logic
This PR has a few parts to it: 1. Adds a new `build-logic` module to organize our build logic. 2. Adds two convention plugins. - `sentry.javadoc` publishes the javadoc to a consumable configuration. - `sentry.javadoc.aggregate` consumes the published javadoc and aggregates them in the root build folder. 3. Deletes the `stylesheet.css`. This was causing the javadoc to look unusable. Deleting it fixes this. 4. Each subproject publishes the javadoc to its own subfolder. The previous behavior would overwrite the javadoc with each new project in the same directory which meant some parts of the javadoc were unreachable. The producer/consumer configuration is based on this blog post: https://www.liutikas.net/2024/12/11/Together-In-Isolation.html It should be project isolation compatible.
1 parent 8295b2f commit f4724d7

43 files changed

Lines changed: 142 additions & 595 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

build-logic/build.gradle.kts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
plugins {
2+
`kotlin-dsl`
3+
}
4+
5+
repositories {
6+
gradlePluginPortal()
7+
}

build-logic/settings.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
rootProject.name = "build-logic"
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package io.sentry.gradle
2+
3+
import org.gradle.api.DefaultTask
4+
import org.gradle.api.file.DirectoryProperty
5+
import org.gradle.api.file.FileCollection
6+
import org.gradle.api.file.FileSystemOperations
7+
import org.gradle.api.provider.Property
8+
import org.gradle.api.tasks.InputFiles
9+
import org.gradle.api.tasks.Internal
10+
import org.gradle.api.tasks.OutputDirectory
11+
import org.gradle.api.tasks.TaskAction
12+
import javax.inject.Inject
13+
14+
15+
abstract class AggregateJavadoc @Inject constructor(
16+
@get:Internal val fs: FileSystemOperations
17+
) : DefaultTask(){
18+
@get:InputFiles
19+
abstract val javadocFiles: Property<FileCollection>
20+
21+
@get:OutputDirectory
22+
abstract val outputDir: DirectoryProperty
23+
24+
@TaskAction
25+
fun aggregate() {
26+
javadocFiles.get().forEach { file ->
27+
fs.copy {
28+
// get the parts of the path and get the third to last part to use as the directory name for the output
29+
val parts = file.path.split('/')
30+
val projectName = parts[parts.size - 4]
31+
from(file)
32+
// We use the project name as the output directory name so that each javadoc goes into its own directory
33+
into(outputDir.get().file(projectName))
34+
}
35+
}
36+
}
37+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import org.gradle.api.attributes.Category
2+
import org.gradle.api.attributes.LibraryElements
3+
import org.gradle.kotlin.dsl.creating
4+
import org.gradle.kotlin.dsl.getValue
5+
import org.gradle.kotlin.dsl.named
6+
import io.sentry.gradle.AggregateJavadoc
7+
8+
val javadocConsumer by configurations.creating {
9+
isCanBeConsumed = false
10+
isCanBeResolved = true
11+
attributes {
12+
attribute(Category.CATEGORY_ATTRIBUTE, objects.named(Category.DOCUMENTATION))
13+
attribute(LibraryElements.LIBRARY_ELEMENTS_ATTRIBUTE, objects.named("javadoc"))
14+
}
15+
}
16+
17+
subprojects {
18+
javadocConsumer.dependencies.add(dependencies.create(this))
19+
}
20+
21+
val javadocCollection = javadocConsumer.incoming.artifactView { lenient(true) }.files
22+
23+
tasks.register("aggregateJavadoc", AggregateJavadoc::class) {
24+
group = "documentation"
25+
description = "Aggregates Javadocs from all subprojects into a single directory."
26+
javadocFiles.set(javadocCollection)
27+
outputDir.set(layout.buildDirectory.dir("docs/javadoc"))
28+
}
29+
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
val javadocConfig : Configuration by configurations.creating {
2+
isCanBeResolved = false
3+
isCanBeConsumed = true
4+
5+
attributes {
6+
attribute(Category.CATEGORY_ATTRIBUTE, objects.named(Category.DOCUMENTATION))
7+
attribute(LibraryElements.LIBRARY_ELEMENTS_ATTRIBUTE, objects.named("javadoc"))
8+
}
9+
}
10+
11+
tasks.withType<Javadoc>().configureEach {
12+
setDestinationDir(project.layout.buildDirectory.file("docs/javadoc").get().asFile)
13+
title = "${project.name} $version API"
14+
val opts = options as StandardJavadocDocletOptions
15+
opts.quiet()
16+
opts.encoding = "UTF-8"
17+
opts.memberLevel = JavadocMemberLevel.PROTECTED
18+
opts.links = listOf(
19+
"https://docs.oracle.com/javase/8/docs/api/",
20+
"https://docs.spring.io/spring-framework/docs/current/javadoc-api/",
21+
"https://docs.spring.io/spring-boot/docs/current/api/"
22+
)
23+
}
24+
25+
artifacts {
26+
add(javadocConfig.name, tasks.named("javadoc"))
27+
}

build.gradle.kts

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ plugins {
2727
alias(libs.plugins.errorprone) apply false
2828
alias(libs.plugins.gradle.versions) apply false
2929
alias(libs.plugins.spring.dependency.management) apply false
30+
id("sentry.javadoc.aggregate")
3031
}
3132

3233
buildscript {
@@ -246,31 +247,6 @@ spotless {
246247
}
247248
}
248249

249-
tasks.register("aggregateJavadocs", Javadoc::class.java) {
250-
setDestinationDir(project.layout.buildDirectory.file("docs/javadoc").get().asFile)
251-
title = "${project.name} $version API"
252-
val opts = options as StandardJavadocDocletOptions
253-
opts.quiet()
254-
opts.encoding = "UTF-8"
255-
opts.memberLevel = JavadocMemberLevel.PROTECTED
256-
opts.stylesheetFile(file("$projectDir/docs/stylesheet.css"))
257-
opts.links = listOf(
258-
"https://docs.oracle.com/javase/8/docs/api/",
259-
"https://docs.spring.io/spring-framework/docs/current/javadoc-api/",
260-
"https://docs.spring.io/spring-boot/docs/current/api/"
261-
)
262-
subprojects
263-
.filter { !it.name.contains("sample") && !it.name.contains("integration-tests") }
264-
.forEach { proj ->
265-
proj.tasks.withType<Javadoc>().forEach { javadocTask ->
266-
source += javadocTask.source
267-
classpath += javadocTask.classpath
268-
excludes += javadocTask.excludes
269-
includes += javadocTask.includes
270-
}
271-
}
272-
}
273-
274250
tasks.register("buildForCodeQL") {
275251
subprojects
276252
.filter {

0 commit comments

Comments
 (0)