Source file encoding is another example of a tiny problem that needs a surprisingly big amount of Gradle code. There is a pretty old issue for this, so if you think that the code below is too complicated (like I do), please vote for it.
Gradle uses the platform encoding as default encoding for Java files (like the Java compiler does), which is a bad choice for platform-independent applications. To change this, add the following snipplet to your
This is because we have at least two instances of a
JavaCompile task (“compileJava” and “compileTestJava”), and the encoding must be applied to all of them.
Note that early versions of Gradle use type
GroovyCompile tasks have different encoding settings for Java and Groovy files:
In the current case, the
groovyOptions.encoding line is optional, since UTF-8 is the default encoding for Groovy files.
Intellij IDEA integration
Again, no out-of-the-box encoding support with the IDEA plugin. We must add a new XML node to the XML project file:
The sample code is based on this Gradle goodness posting and tested with IDEA 14.comments powered by Disqus