Could I set source files' encoding separately?


(Alpha Hinex) #1

Some source files are encoding with GBK, and others with utf-8 in my project, how could I tell gradle to build it correctly? When I build project with default setting, I got a warning that some files with GBK error. And after I set java compile option like this:

tasks.withType(JavaCompile) {
     options.encoding = 'utf-8'
}

the files with utf-8 error. So I want to set encoding of source file, could I have some suggestion?

Kind regards, Hinex


(Peter Niederwieser) #2

You can set the encoding per ‘JavaCompile’ task. That’s how the Java compiler works. Best solution is to convert the files to use the same encoding.