Skip to content

Commit 72eef94

Browse files
Gradle: set file encoding globally, set it for all javadoc tasks #259
1 parent f76c9d8 commit 72eef94

File tree

6 files changed

+16
-6
lines changed

6 files changed

+16
-6
lines changed

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ gen/
1212
target/
1313
out/
1414
classes/
15-
gradle.properties
1615

1716
# Local build properties
1817
build.properties

.gitlab-ci.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,8 @@ variables:
1616
# Disable the Gradle daemon. Gradle may run in a Docker container with a shared
1717
# Docker volume containing GRADLE_USER_HOME. If the container is stopped after a job
1818
# Gradle daemons may get killed, preventing proper clean-up of lock files in GRADLE_USER_HOME.
19-
# Configure file.encoding to always use UTF-8 when running Gradle.
2019
# Use low priority processes to avoid Gradle builds consuming all build machine resources.
21-
GRADLE_OPTS: "-Dorg.gradle.daemon=false -Dfile.encoding=UTF-8 -Dorg.gradle.priority=low"
20+
GRADLE_OPTS: "-Dorg.gradle.daemon=false -Dorg.gradle.priority=low"
2221
GITLAB_REPO_ARGS: "-PgitlabUrl=$CI_SERVER_URL -PgitlabPrivateTokenName=Deploy-Token -PgitlabPrivateToken=$OBX_READ_PACKAGES_TOKEN"
2322
GITLAB_PUBLISH_ARGS: "-PgitlabPublishTokenName=Job-Token -PgitlabPublishToken=$CI_JOB_TOKEN"
2423
CENTRAL_PUBLISH_ARGS: "-PsonatypeUsername=$SONATYPE_USER -PsonatypePassword=$SONATYPE_PWD"

build.gradle.kts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,13 @@ allprojects {
8787
cacheChangingModulesFor(0, "seconds")
8888
}
8989
}
90+
91+
tasks.withType<Javadoc>().configureEach {
92+
// To support Unicode characters in API docs force the javadoc tool to use UTF-8 encoding.
93+
// Otherwise, it defaults to the system file encoding. This is required even though setting file.encoding
94+
// for the Gradle daemon (see gradle.properties) as Gradle does not pass it on to the javadoc tool.
95+
options.encoding = "UTF-8"
96+
}
9097
}
9198

9299
tasks.wrapper {

gradle.properties

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Gradle configuration
2+
# https://docs.gradle.org/current/userguide/build_environment.html
3+
4+
# To support Unicode characters in source code, set UTF-8 as the file encoding for the Gradle daemon,
5+
# which will make most Java tools use it instead of the default system file encoding. Note that for API docs,
6+
# the javadoc tool must be configured separately, see the root build script.
7+
# https://docs.gradle.org/current/userguide/common_caching_problems.html#system_file_encoding
8+
org.gradle.jvmargs=-Dfile.encoding=UTF-8

objectbox-java/build.gradle

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,6 @@ tasks.register('javadocForWeb', Javadoc) {
100100
destinationDir = file(javadocForWebDir)
101101

102102
title = "ObjectBox Java ${version} API"
103-
options.encoding = 'UTF-8' // Set UTF-8 encoding to support unicode characters used in docs
104103
options.overview = "$projectDir/src/web/overview.html"
105104
options.bottom = 'Available under the Apache License, Version 2.0 - <i>Copyright &#169; 2017-2024 <a href="https://objectbox.io/">ObjectBox Ltd</a>. All Rights Reserved.</i>'
106105

tests/objectbox-java-test/build.gradle.kts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@ tasks.withType<JavaCompile> {
1010
// Note: use release flag instead of sourceCompatibility and targetCompatibility to ensure only JDK 8 API is used.
1111
// https://docs.gradle.org/current/userguide/building_java_projects.html#sec:java_cross_compilation
1212
options.release.set(8)
13-
// Note: Gradle defaults to the platform default encoding, make sure to always use UTF-8 for UTF-8 tests.
14-
options.encoding = "UTF-8"
1513
}
1614

1715
// Produce Java 8 byte code, would default to Java 6.

0 commit comments

Comments
 (0)