Gradle with utf-8 with BOM

I am trying to build an app with gradle, all of my file needs to be in UTF-8 with BOM, I have tried this solution:

compileJava.options.encoding = 'UTF-8'

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

In my build.gradle and this is the new error I get :

settings.gradle’: 1: Invalid variable name. Must start with a letter but was: ?rootProject

I don’t know if there is a solution but I really need to keep the file in UTF-8 with BOM.