I have Groovy code with UTF-8 encoding and need the generated Groovydoc HTML to use the same. But how do I configure this in Gradle?
2 Answers
The Groovydoc tool, and hence also Gradle's Groovydoc
task, doesn't currently support an encoding
option. Setting the file.encoding
system property for the Gradle JVM should work though. You can do this via the GRADLE_OPTS
environment variable, or by adding systemProp.file.encoding=utf-8
to gradle.properties
.

- 121,412
- 21
- 324
- 259
-
Thanks for the tip, but it didn't work. Something changed when I did export GRADLE_OPTS="-Dfile.encoding=UTF-8" before gradle groovydoc, but it still could not produce a Norwegian 'Ø'. I run on Mac and gradle --version gives this: ------------------------------------------------------------ Gradle 1.2 ------------------------------------------------------------ Gradle build time: Wednesday, September 12, 2012 10:46:02 AM UTC Groovy: 1.8.6 Ant: Apache Ant(TM) version 1.8.4 compiled on May 22 2012 Ivy: 2.2.0 JVM: 1.6.0_35 (Apple Inc. 20.10-b01-428) OS: Mac OS X 10.8.1 x86_64 Any more tips? – Lars Høidahl Nov 22 '12 at 20:14
-
1From what I've seen, `-Dfile.encoding` is the only chance. Unsure why it wouldn't work. I've already filed an issue to add an `encoding` option to Groovydoc. – Peter Niederwieser Nov 23 '12 at 16:11
-
1Of course you'll have to set the `file.encoding` system property to whatever encoding you use for your source files (which might not be UTF-8). Groovydoc will use this encoding both for reading source files and for writing HTML. Not sure if it declares the encoding in the HTML. – Peter Niederwieser Nov 23 '12 at 16:22
-
My source files are UTF-8 for sure. I the problem is that it doesn't declare the encoding in the HTML. – Lars Høidahl Nov 24 '12 at 20:09
-
You can easily verify this by setting the browser's encoding explicitly. And then you can write a little task that declares the encoding in the HTML. – Peter Niederwieser Nov 26 '12 at 17:04
-
Thanks, that worked. Need to write that task though, but it's worth it to get my name spelled correctly :-) – Lars Høidahl Nov 27 '12 at 21:58
Surprisingly, this issue is still relevant after six years and a lot of Gradle versions :)
I've run into this issue when I had added Unicode characters (namely arrows) to my Groovydoc overview file and tried to assemble Groovydoc on a machine with default Windows-1251 encoding.
As of Gradle 4.10.2, one can use additional options for Groovydoc by providing its own implementation of AntGroovydoc
to the groovydoc
task via its setAntGroovydoc
method. But as this method is considered internal, it would be a bit hacky solution. Besides, AntGroovydoc
is clearly not designed for extension and its subclassing would require a lot of copy-paste from the original class.

- 134
- 2
- 13