|
1 | | -import kotlin.io.path.appendText |
2 | | -import kotlin.io.path.readText |
3 | | -import kotlin.io.path.writeText |
4 | | - |
5 | 1 | plugins { |
6 | 2 | id("java-library") |
7 | 3 | id("objectbox-publish") |
@@ -69,9 +65,20 @@ val javadocForWeb by tasks.registering(Javadoc::class) { |
69 | 65 | group = "documentation" |
70 | 66 | description = "Builds Javadoc incl. objectbox-java-api classes with web tweaks." |
71 | 67 |
|
| 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 | + |
72 | 79 | 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)) |
75 | 82 | }) |
76 | 83 |
|
77 | 84 | val srcApi = project(":objectbox-java-api").file("src/main/java/") |
@@ -104,33 +111,18 @@ val javadocForWeb by tasks.registering(Javadoc::class) { |
104 | 111 | source = filteredSources + fileTree(srcApi) |
105 | 112 |
|
106 | 113 | classpath = sourceSets.main.get().output + sourceSets.main.get().compileClasspath |
107 | | - setDestinationDir(javadocForWebDir.get().asFile) |
| 114 | + destinationDir = javadocForWebDir.get().asFile |
108 | 115 |
|
109 | 116 | title = "ObjectBox Java ${project.version} API" |
110 | 117 | (options as StandardJavadocDocletOptions).apply { |
111 | | - overview = "$projectDir/src/web/overview.html" |
112 | | - bottom = "Available under the Apache License, Version 2.0 - <i>Copyright © 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 © 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()) |
113 | 123 | } |
114 | 124 |
|
115 | 125 | 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 | | - |
134 | 126 | println("Javadoc for web created at $destinationDir") |
135 | 127 | } |
136 | 128 | } |
|
0 commit comments