javac - How can you get Gradle to fail the build when there's a non-UTF8 character in the source code? -


it's rare enough problem, i'd fail build when happens:

 /users/jundai/perforce/trunk/service/test/com/mycompany/priceformattingtests.java:93: error: unmappable character encoding utf-8        return new currencymodel("373959", new price("10.20", "eur"), "�10.20", new price("12.10", "usd"), "$12.10"); 

with ant or running javac on command-line, using -source 1.6 or -source 1.7 cause fail. using gradle, prints out error: (if sourcecompatibility set 6 or higher), build still successful.

i've tried various ways of getting -source argument javac command compilejava task, nothing i've tried seems able gradle report failure.

has else run this?

edit: more details:

if have file encoded in winansi: src/main/java/test.java:

 public class test {   public static void main(string[] args) {     system.out.println("testing utf-8 compilation: c’est drôle, tout à coup je ne sais pas quoi dire.");   } } 

then passes no errors or warnings using build.gradle, gradle 1.3, , java 1.7:

 apply plugin: 'java'  tasks.withtype(compile) {   options.encoding = "iso-8859-1" } 

output is:

 [1.9.3-p327] gradle$ gradle build :compilejava :processresources up-to-date :classes :jar :assemble :compiletestjava up-to-date :processtestresources up-to-date :testclasses up-to-date :test :check :build  build successful 

if remove options.encoding, or set utf-8, this:

 [1.9.3-p327] gradle$ gradle build :compilejava /users/jbateskobashigawa/play/gradle/src/main/java/test.java:3: error: unmappable character encoding utf8     system.out.println("testing utf-8 compilation: c�est dr�le, tout � coup je ne sais pas quoi dire.");                                                     ^ /users/jbateskobashigawa/play/gradle/src/main/java/test.java:3: error: unmappable character encoding utf8     system.out.println("testing utf-8 compilation: c�est dr�le, tout � coup je ne sais pas quoi dire.");                                                            ^ /users/jbateskobashigawa/play/gradle/src/main/java/test.java:3: error: unmappable character encoding utf8     system.out.println("testing utf-8 compilation: c�est dr�le, tout � coup je ne sais pas quoi dire.");                                                                      ^ :processresources up-to-date ... (more stuff) build successful 

setting sourcetypecompatibility between 1.5, 1.6, , 1.7 doesn't seem much. 1.5, when using -source on javac turns error warning:. gradle, it's still error:, interestingly doesn't recompiled on next build, whereas 1.6 , 1.7 does.

i've tried sorts of ways try pass -source javac when gradle building, none of them seem work:

doesn't build:

     options.compilerargs < '-source 1.7' 

builds, doesn't error out (same without flag):

     options.compilerargs << '-source'     options.compilerargs << '1.7' 

all of seems have fact gradle isn't using javac executable compile—it's using sort of jvm compile api has lot of convoluted code in it. if try replicate gradle seems doing, can create class compile class looks this: javax/tools/compiletest.java

you can reproduce problem using mini project: https://github.com/jun-dai/gradle_utf8_compilation_issue

does know of way around problem, short of parsing gradle build output , failing build based on particular error message?

it seems allow fail build:

     options.fork = true     options.forkoptions.executable = 'javac' 

not sure if has other ramifications, however, i'll give go.


Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -