Skip to content

Commit be68161

Browse files
Merge branch '215-gradle-kts-scripts' into 'dev'
Gradle: convert remaining scripts to Kotlin #215 See merge request objectbox/objectbox-java!158
2 parents b0270f1 + 69b16de commit be68161

File tree

9 files changed

+324
-297
lines changed

9 files changed

+324
-297
lines changed

objectbox-java-api/build.gradle

Lines changed: 0 additions & 34 deletions
This file was deleted.
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
plugins {
2+
id("java-library")
3+
id("objectbox-publish")
4+
}
5+
6+
// Note: use release flag instead of sourceCompatibility and targetCompatibility to ensure only JDK 8 API is used.
7+
// https://docs.gradle.org/current/userguide/building_java_projects.html#sec:java_cross_compilation
8+
tasks.withType<JavaCompile> {
9+
options.release.set(8)
10+
}
11+
12+
val javadocJar by tasks.registering(Jar::class) {
13+
dependsOn(tasks.javadoc)
14+
archiveClassifier.set("javadoc")
15+
from("build/docs/javadoc")
16+
}
17+
18+
val sourcesJar by tasks.registering(Jar::class) {
19+
from(sourceSets.main.get().allSource)
20+
archiveClassifier.set("sources")
21+
}
22+
23+
// Set project-specific properties.
24+
publishing {
25+
publications {
26+
getByName<MavenPublication>("mavenJava") {
27+
from(components["java"])
28+
artifact(sourcesJar)
29+
artifact(javadocJar)
30+
pom {
31+
name.set("ObjectBox API")
32+
description.set("ObjectBox is a fast NoSQL database for Objects")
33+
}
34+
}
35+
}
36+
}
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
import kotlin.io.path.appendText
2+
import kotlin.io.path.readText
3+
import kotlin.io.path.writeText
4+
15
plugins {
26
id("java-library")
37
id("objectbox-publish")
@@ -6,27 +10,26 @@ plugins {
610

711
// Note: use release flag instead of sourceCompatibility and targetCompatibility to ensure only JDK 8 API is used.
812
// https://docs.gradle.org/current/userguide/building_java_projects.html#sec:java_cross_compilation
9-
tasks.withType(JavaCompile).configureEach {
13+
tasks.withType<JavaCompile> {
1014
options.release.set(8)
1115
}
1216

13-
ext {
14-
javadocForWebDir = "$buildDir/docs/web-api-docs"
15-
}
17+
val javadocForWebDir = "$buildDir/docs/web-api-docs"
18+
val essentialsVersion: String by rootProject.extra
1619

1720
dependencies {
18-
api project(':objectbox-java-api')
19-
implementation "org.greenrobot:essentials:$essentialsVersion"
20-
api 'com.google.code.findbugs:jsr305:3.0.2'
21+
api(project(":objectbox-java-api"))
22+
implementation("org.greenrobot:essentials:$essentialsVersion")
23+
api("com.google.code.findbugs:jsr305:3.0.2")
2124

2225
// https://github.com/spotbugs/spotbugs/blob/master/CHANGELOG.md
23-
compileOnly 'com.github.spotbugs:spotbugs-annotations:4.7.3'
26+
compileOnly("com.github.spotbugs:spotbugs-annotations:4.7.3")
2427
}
2528

2629
spotbugs {
27-
ignoreFailures = true
28-
showStackTraces = true
29-
excludeFilter = file("spotbugs-exclude.xml")
30+
ignoreFailures.set(true)
31+
showStackTraces.set(true)
32+
excludeFilter.set(file("spotbugs-exclude.xml"))
3033
}
3134

3235
tasks.spotbugsMain {
@@ -36,7 +39,7 @@ tasks.spotbugsMain {
3639
}
3740

3841
// Note: used for the Maven javadoc artifact, a separate task is used to build API docs to publish online
39-
javadoc {
42+
tasks.javadoc {
4043
// Internal Java APIs
4144
exclude("**/io/objectbox/Cursor.java")
4245
exclude("**/io/objectbox/KeyValueCursor.java")
@@ -60,19 +63,19 @@ javadoc {
6063
}
6164

6265
// Note: use packageJavadocForWeb to get as ZIP.
63-
tasks.register('javadocForWeb', Javadoc) {
64-
group = 'documentation'
65-
description = 'Builds Javadoc incl. objectbox-java-api classes with web tweaks.'
66+
tasks.register<Javadoc>("javadocForWeb") {
67+
group = "documentation"
68+
description = "Builds Javadoc incl. objectbox-java-api classes with web tweaks."
6669

67-
javadocTool = javaToolchains.javadocToolFor {
70+
javadocTool.set(javaToolchains.javadocToolFor {
6871
// Note: the style changes only work if using JDK 10+, 17 is the LTS release used to publish this
69-
languageVersion = JavaLanguageVersion.of(17)
70-
}
72+
languageVersion.set(JavaLanguageVersion.of(17))
73+
})
7174

72-
def srcApi = project(':objectbox-java-api').file('src/main/java/')
73-
if (!srcApi.directory) throw new GradleScriptException("Not a directory: ${srcApi}", null)
75+
val srcApi = project(":objectbox-java-api").file("src/main/java/")
76+
if (!srcApi.isDirectory) throw GradleException("Not a directory: $srcApi")
7477
// Hide internal API from javadoc artifact.
75-
def filteredSources = sourceSets.main.allJava.matching {
78+
val filteredSources = sourceSets.main.get().allJava.matching {
7679
// Internal Java APIs
7780
exclude("**/io/objectbox/Cursor.java")
7881
exclude("**/io/objectbox/KeyValueCursor.java")
@@ -94,80 +97,86 @@ tasks.register('javadocForWeb', Javadoc) {
9497
exclude("**/io/objectbox/sync/server/JwtConfig.java")
9598
exclude("**/io/objectbox/sync/server/SyncServerOptions.java")
9699
}
97-
source = filteredSources + srcApi
100+
source = filteredSources + fileTree(srcApi)
98101

99-
classpath = sourceSets.main.output + sourceSets.main.compileClasspath
100-
destinationDir = file(javadocForWebDir)
102+
classpath = sourceSets.main.get().output + sourceSets.main.get().compileClasspath
103+
setDestinationDir(file(javadocForWebDir))
101104

102-
title = "ObjectBox Java ${version} API"
103-
options.overview = "$projectDir/src/web/overview.html"
104-
options.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>'
105+
title = "ObjectBox Java ${project.version} API"
106+
(options as StandardJavadocDocletOptions).apply {
107+
overview = "$projectDir/src/web/overview.html"
108+
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>"
109+
}
105110

106111
doLast {
107112
// Note: frequently check the vanilla stylesheet.css if values still match.
108-
def stylesheetPath = "$destinationDir/stylesheet.css"
109-
110-
// Primary background
111-
ant.replace(file: stylesheetPath, token: "#4D7A97", value: "#17A6A6")
112-
113-
// "Active" background
114-
ant.replace(file: stylesheetPath, token: "#F8981D", value: "#7DDC7D")
115-
116-
// Hover
117-
ant.replace(file: stylesheetPath, token: "#bb7a2a", value: "#E61955")
118-
113+
val stylesheetPath = "$destinationDir/stylesheet.css"
114+
115+
// Adjust the CSS stylesheet
116+
117+
// Change some color values
118+
// The stylesheet file should be megabytes at most, so read it as a whole
119+
val stylesheetFile = kotlin.io.path.Path(stylesheetPath)
120+
val originalContent = stylesheetFile.readText()
121+
val replacedContent = originalContent
122+
.replace("#4D7A97", "#17A6A6") // Primary background
123+
.replace("#F8981D", "#7DDC7D") // "Active" background
124+
.replace("#bb7a2a", "#E61955") // Hover
125+
stylesheetFile.writeText(replacedContent)
119126
// Note: in CSS stylesheets the last added rule wins, so append to default stylesheet.
120127
// Code blocks
121-
file(stylesheetPath).append("pre {\nwhite-space: normal;\noverflow-x: auto;\n}\n")
128+
stylesheetFile.appendText("pre {\nwhite-space: normal;\noverflow-x: auto;\n}\n")
122129
// Member summary tables
123-
file(stylesheetPath).append(".memberSummary {\noverflow: auto;\n}\n")
130+
stylesheetFile.appendText(".memberSummary {\noverflow: auto;\n}\n")
124131
// Descriptions and signatures
125-
file(stylesheetPath).append(".block {\n" +
132+
stylesheetFile.appendText(".block {\n" +
126133
" display:block;\n" +
127134
" margin:3px 10px 2px 0px;\n" +
128135
" color:#474747;\n" +
129136
" overflow:auto;\n" +
130137
"}")
131138

132-
println "Javadoc for web created at $destinationDir"
139+
println("Javadoc for web created at $destinationDir")
133140
}
134141
}
135142

136-
tasks.register('packageJavadocForWeb', Zip) {
137-
dependsOn javadocForWeb
138-
group = 'documentation'
139-
description = 'Packages Javadoc incl. objectbox-java-api classes with web tweaks as ZIP.'
143+
tasks.register<Zip>("packageJavadocForWeb") {
144+
dependsOn("javadocForWeb")
145+
group = "documentation"
146+
description = "Packages Javadoc incl. objectbox-java-api classes with web tweaks as ZIP."
140147

141-
archiveFileName = "objectbox-java-web-api-docs.zip"
142-
destinationDirectory = file("$buildDir/dist")
148+
archiveFileName.set("objectbox-java-web-api-docs.zip")
149+
destinationDirectory.set(file("$buildDir/dist"))
143150

144-
from file(javadocForWebDir)
151+
from(file(javadocForWebDir))
145152

146153
doLast {
147-
println "Javadoc for web packaged to ${file("$buildDir/dist/objectbox-java-web-api-docs.zip")}"
154+
println("Javadoc for web packaged to ${file("$buildDir/dist/objectbox-java-web-api-docs.zip")}")
148155
}
149156
}
150157

151-
tasks.register('javadocJar', Jar) {
152-
dependsOn javadoc
153-
archiveClassifier.set('javadoc')
154-
from 'build/docs/javadoc'
158+
val javadocJar by tasks.registering(Jar::class) {
159+
dependsOn("javadoc")
160+
archiveClassifier.set("javadoc")
161+
from("build/docs/javadoc")
155162
}
156163

157-
tasks.register('sourcesJar', Jar) {
158-
from sourceSets.main.allSource
159-
archiveClassifier.set('sources')
164+
val sourcesJar by tasks.registering(Jar::class) {
165+
from(sourceSets.main.get().allSource)
166+
archiveClassifier.set("sources")
160167
}
161168

162169
// Set project-specific properties.
163-
publishing.publications {
164-
mavenJava(MavenPublication) {
165-
from components.java
166-
artifact sourcesJar
167-
artifact javadocJar
168-
pom {
169-
name = 'ObjectBox Java (only)'
170-
description = 'ObjectBox is a fast NoSQL database for Objects'
170+
publishing {
171+
publications {
172+
getByName<MavenPublication>("mavenJava") {
173+
from(components["java"])
174+
artifact(sourcesJar)
175+
artifact(javadocJar)
176+
pom {
177+
name.set("ObjectBox Java (only)")
178+
description.set("ObjectBox is a fast NoSQL database for Objects")
179+
}
171180
}
172181
}
173182
}

objectbox-kotlin/build.gradle

Lines changed: 0 additions & 80 deletions
This file was deleted.

0 commit comments

Comments
 (0)