Skip to content

Commit d1bffff

Browse files
Gradle: run javadoc using JDK 21, customize using new CSS variables
Thew new buildenv image uses JDK 21, so use that to run javadoc. The new default stylesheet has switched to CSS variables, so override them to customize the docs theme (also officially supported).
1 parent b2f6a63 commit d1bffff

File tree

2 files changed

+80
-27
lines changed

2 files changed

+80
-27
lines changed

objectbox-java/build.gradle.kts

Lines changed: 19 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
import kotlin.io.path.appendText
2-
import kotlin.io.path.readText
3-
import kotlin.io.path.writeText
4-
51
plugins {
62
id("java-library")
73
id("objectbox-publish")
@@ -69,9 +65,20 @@ val javadocForWeb by tasks.registering(Javadoc::class) {
6965
group = "documentation"
7066
description = "Builds Javadoc incl. objectbox-java-api classes with web tweaks."
7167

68+
// Register used files as inputs so task is re-run if they change
69+
// https://docs.gradle.org/current/userguide/incremental_build.html
70+
val customOverview = layout.projectDirectory.file("src/web/overview.html")
71+
inputs.file(customOverview)
72+
.withPropertyName("customOverview")
73+
.withPathSensitivity(PathSensitivity.NONE)
74+
val customStylesheet = layout.projectDirectory.file("src/web/objectbox-stylesheet.css")
75+
inputs.file(customStylesheet)
76+
.withPropertyName("customStylesheet")
77+
.withPathSensitivity(PathSensitivity.NONE)
78+
7279
javadocTool.set(javaToolchains.javadocToolFor {
73-
// Note: the style changes only work if using JDK 10+, 17 is the LTS release used to publish this
74-
languageVersion.set(JavaLanguageVersion.of(17))
80+
// Note: the style changes only work if using JDK 10+, 21 is the LTS release used to publish this
81+
languageVersion.set(JavaLanguageVersion.of(21))
7582
})
7683

7784
val srcApi = project(":objectbox-java-api").file("src/main/java/")
@@ -104,33 +111,18 @@ val javadocForWeb by tasks.registering(Javadoc::class) {
104111
source = filteredSources + fileTree(srcApi)
105112

106113
classpath = sourceSets.main.get().output + sourceSets.main.get().compileClasspath
107-
setDestinationDir(javadocForWebDir.get().asFile)
114+
destinationDir = javadocForWebDir.get().asFile
108115

109116
title = "ObjectBox Java ${project.version} API"
110117
(options as StandardJavadocDocletOptions).apply {
111-
overview = "$projectDir/src/web/overview.html"
112-
bottom = "Available under the Apache License, Version 2.0 - <i>Copyright &#169; 2017-2025 <a href=\"https://objectbox.io/\">ObjectBox Ltd</a>. All Rights Reserved.</i>"
118+
overview = customOverview.toString()
119+
bottom = "Available under the Apache License, Version 2.0 - <i>Copyright &#169; 2017-2026 <a href=\"https://objectbox.io/\">ObjectBox Ltd</a>. All Rights Reserved.</i>"
120+
// Customize the default stylesheet https://docs.oracle.com/en/java/javase/21/javadoc/javadoc-css-themes.html
121+
// Note: the javadoc option is "--add-stylesheet", but addStringOption already ads a single dash ("-")
122+
addStringOption("-add-stylesheet", customStylesheet.toString())
113123
}
114124

115125
doLast {
116-
// Note: frequently check the vanilla stylesheet.css if values still match.
117-
val stylesheetPath = "$destinationDir/stylesheet.css"
118-
119-
// Adjust the CSS stylesheet
120-
121-
// Change some color values
122-
// The stylesheet file should be megabytes at most, so read it as a whole
123-
val stylesheetFile = kotlin.io.path.Path(stylesheetPath)
124-
val originalContent = stylesheetFile.readText()
125-
val replacedContent = originalContent
126-
.replace("#4D7A97", "#17A6A6") // Primary background
127-
.replace("#F8981D", "#7DDC7D") // "Active" background
128-
.replace("#bb7a2a", "#E61955") // Hover
129-
stylesheetFile.writeText(replacedContent)
130-
// Note: in CSS stylesheets the last added rule wins, so append to default stylesheet.
131-
// Make code blocks scroll instead of stick out on small width
132-
stylesheetFile.appendText("pre {\n overflow-x: auto;\n}\n")
133-
134126
println("Javadoc for web created at $destinationDir")
135127
}
136128
}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/*
2+
CSS variables to override, taken from the default stylesheet generated in build/docs/javadoc/stylesheet.css
3+
They are also documented at https://docs.oracle.com/en/java/javase/21/javadoc/javadoc-css-themes.html
4+
*/
5+
:root {
6+
/*!* body, block and code fonts *!*/
7+
/*--body-font-family: 'DejaVu Sans', Arial, Helvetica, sans-serif;*/
8+
/*--block-font-family: 'DejaVu Serif', Georgia, "Times New Roman", Times, serif;*/
9+
/*--code-font-family: 'DejaVu Sans Mono', monospace;*/
10+
/*!* Base font sizes for body and code elements *!*/
11+
/*--body-font-size: 14px;*/
12+
/*--code-font-size: 14px;*/
13+
/*!* Text colors for body and block elements *!*/
14+
/*--body-text-color: #353833;*/
15+
/*--block-text-color: #474747;*/
16+
/* Background colors for various structural elements */
17+
/*--body-background-color: #ffffff;*/
18+
/*--section-background-color: #f8f8f8;*/
19+
/*--detail-background-color: #ffffff;*/
20+
/* Colors for navigation bar and table captions */
21+
--navbar-background-color: #17A6A6;
22+
/*--navbar-text-color: #ffffff;*/
23+
/* Background color for subnavigation and various headers */
24+
/*--subnav-background-color: #dee3e9;*/
25+
/* Background and text colors for selected tabs and navigation items */
26+
--selected-background-color: #7DDC7D;
27+
/*--selected-text-color: #253441;*/
28+
/*--selected-link-color: #1f389c;*/
29+
/* Background colors for generated tables */
30+
/*--even-row-color: #ffffff;*/
31+
/*--odd-row-color: #eeeeef;*/
32+
/* Text color for page title */
33+
/*--title-color: #2c4557;*/
34+
/* Text colors for links */
35+
/*--link-color: #4A6782;*/
36+
--link-color-active: #E61955;
37+
/* Snippet colors */
38+
/*--snippet-background-color: #ebecee;*/
39+
/*--snippet-text-color: var(--block-text-color);*/
40+
/*--snippet-highlight-color: #f7c590;*/
41+
/* Border colors for structural elements and user defined tables */
42+
/*--border-color: #ededed;*/
43+
/*--table-border-color: #000000;*/
44+
/* Search input colors */
45+
/*--search-input-background-color: #ffffff;*/
46+
/*--search-input-text-color: #000000;*/
47+
/*--search-input-placeholder-color: #909090;*/
48+
/* Highlight color for active search tag target */
49+
/*--search-tag-highlight-color: #ffff00;*/
50+
/* Adjustments for icon and active background colors of copy-to-clipboard buttons */
51+
/*--copy-icon-brightness: 100%;*/
52+
/*--copy-button-background-color-active: rgba(168, 168, 176, 0.3);*/
53+
/* Colors for invalid tag notifications */
54+
/*--invalid-tag-background-color: #ffe6e6;*/
55+
/*--invalid-tag-text-color: #000000;*/
56+
}
57+
58+
/* Make code blocks scroll instead of stick out on small width */
59+
pre {
60+
overflow-x: auto;
61+
}

0 commit comments

Comments
 (0)