0

I want to know the default value that gradle/javac is using for -encoding option.

I tried below -

tasks.withType(JavaCompile) {
    println 'Compiler args: ' + options.compilerArgs
    println 'encoding args: ' + options.encoding
}

and the corresponding output is -

Compiler args: []
encoding args: null

The thing is I want to know the default value for this option on my platform before I set it explicitly. I know how to explicitly set the java compile -encoding option value using gradle?

compileJava {  //uncomment the value you want to use.
    options.encoding = "windows-1252"
    //options.encoding = "UTF-8"
    //options.encoding = "US-ASCII"
}

But my intent is to find the default value. Any suggestions?

Note: This Question is not about the runtime option -Dfile.encoding but is instead about the compile time option -encoding.

CodeBot
  • 33
  • 5
  • Wouldn't it be the same as `Charset.systemDefault()`? If not, I can't think *why* not. Plus, why would you want to set it explicitly? The only reason to do that would be when the source files are in an encoding foreign to your system. And then, you wouldn't care what the default was – g00se Jun 20 '23 at 19:42
  • @g00se, the return value of `Charset.systemDefault()` can be controller by jvm option `-Dfile.encoding=UTF-8` etc. What I am asking is about `javac -encoding UTF-8 Some.java`. Right i want to use a different encoding then whats default on my machine as the files are in a different encoding from my system default. – CodeBot Jun 20 '23 at 19:59
  • I think you misunderstand. I *know* that (what I meant to say) `Charset.defaultCharset()` is connected with `file.encoding`. What I'm saying is that it's going to likely be the same. If your files are encoded outside the system default then why not just set the correct encoding? – g00se Jun 20 '23 at 20:08
  • @g00se, if my Some.java is encoded in UTF-8 and my OS/System default is windows-1252, then right at the compile stage I have to give the correct encoding type using `-encoding UTF-8`. Else want goes in to the Some.class is not predictable. And I want to log the System default through gradle before I set it to say UTF-8 – CodeBot Jun 20 '23 at 20:14
  • `gradle -q properties` ? – g00se Jun 20 '23 at 20:50
  • `Or batch convert all to utf-8 – g00se Jun 20 '23 at 21:07
  • @g00se - though i found above command useful. `./gradlew properties | grep encoding` returned nothing. – CodeBot Jun 20 '23 at 22:08
  • I don't think it's possible unless it's already been passed explicitly – g00se Jun 20 '23 at 22:31
  • `I don't think it's possible unless it's already been passed explicitly` <- I would like to agree to this as `javac` itself does not seem to have an option to get this info or all the default values it's taking. +1. Anyone, plz correct if my findings on `javac` are not correct. With `java.exe` we can use `java -XshowSettings` to show default values/settings it uses. – CodeBot Jun 21 '23 at 05:20
  • Yes, so now you have to ask, logically, how is it going to make the decision? I refer you to what I said earlier. Which is are you using? – g00se Jun 21 '23 at 07:12
  • @g00se - I meant, i agree to your point. And the rest was explanation of what I found in mean time after posting this Q. Thanks for all your comments. – CodeBot Jun 21 '23 at 08:32
  • Sorry, that was meant to say - "which OS are you using?" – g00se Jun 21 '23 at 08:47
  • @g00se - local/dev is windows 10 for few and MacOS latest for others. Builds are in Linux in docker image gradle-openjdk11:2022.11.LTS.2 and runtime is docker image of openjdk11-jre – CodeBot Jun 22 '23 at 05:39
  • MacRoman used to be a thing. All that should be asy to script convert if you know the source encoding – g00se Jun 22 '23 at 07:41
  • @g00se - thanks for your continuous involvement.. I could get past the issue just by passing the encoding value to compiler with the one my source is encoded with. Knowing the default would have been informative but that is not blocking me. – CodeBot Jun 22 '23 at 08:07

0 Answers0