# Invalid flag message with gradle - clarification needed

**URL:** <https://discuss.gradle.org/t/invalid-flag-message-with-gradle-clarification-needed/22490>\
**Category:** Help/Discuss\
**Created:** [April 28, 2017, 11:09am UTC](https://discuss.gradle.org/t/invalid-flag-message-with-gradle-clarification-needed/22490 "2017-04-28T11:09:58Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![sabkrish](https://avatars.discourse-cdn.com/v4/letter/s/9f8e36/32.png) [@sabkrish](https://discuss.gradle.org/u/sabkrish)\
**Post date:** [April 28, 2017, 11:09am UTC](https://discuss.gradle.org/t/invalid-flag-message-with-gradle-clarification-needed/22490/1 "2017-04-28T11:09:58Z")

</div>

Hi,

I’m a newbie in gradle. I noticed some behaviour with gradle which i wanted to clarify.

1. In the this code, the javac options i add appear with double quotes in the front and back of the option in the compiler-options text file. Hence javac fails with a invalid flag message.

project(’:com.test’) {  
def dJar = project(’:com.best’).jar.outputs.files.getFiles()  
def addReads = "–add-reads com.test=ALL-UNNAMED"  
def modulePath = "–module-path " + dJar.getAt(0)

```
    tasks.withType(JavaCompile) {
    options.fork = true
    options.forkOptions.executable = '/home/sabari/java_builds/java9/bin/javac'

    options.compilerArgs << addReads
    options.compilerArgs << modulePath

    }

    dependencies {
    compile project(':com.best')
    }

```

}

**Output of java-compiler-args.txt: (truncated)**  
-classpath  
/home/sabari/sample-codes/java9/com.best/build/libs/com.best.jar  
"–add-reads com.test=ALL-UNNAMED"  
"–module-path /home/sabari/sample-codes/java9/com.best/build/libs/com.best.jar"  
/home/sabari/sample-codes/java9/com.test/src/main/java/com.test/com/test/Hi.java  
/home/sabari/sample-codes/java9/com.test/src/main/java/com.test/module-info.java

**Output of build:**  
javac: invalid flag: --add-reads com.test=ALL-UNNAMED  
Usage: javac

whereas when i add like this (below code), it works. Is my earlier way of using incorrect?

project(’:com.test’) {  
def dJar = project(’:com.best’).jar.outputs.files.getFiles()  
def addReads = "com.test=ALL-UNNAMED"  
def modulePath = dJar.getAt(0)

```
    tasks.withType(JavaCompile) {
    options.fork = true
    options.forkOptions.executable = '/home/sabari/java_builds/java9/bin/javac'

options.compilerArgs << '--add-reads'
    options.compilerArgs << addReads
options.compilerArgs << '--module-path'
    options.compilerArgs << modulePath

    }

    dependencies {
    compile project(':com.best')
    }

```

}

1. While debugging the problem #1, i was trying to add “-help” javac option to check if it’s working. It worked only when i fork a process for javac.

**This code worked:**

project(’:com.test’) {  
def dJar = project(’:com.best’).jar.outputs.files.getFiles()  
def addReads = "com.test=ALL-UNNAMED"  
def modulePath = dJar.getAt(0)

```
    tasks.withType(JavaCompile) {
    options.fork = true
    options.forkOptions.executable = '/home/sabari/java_builds/java9/bin/javac'

options.compilerArgs << '--add-reads'
    options.compilerArgs << addReads
options.compilerArgs << '--module-path'
    options.compilerArgs << modulePath
options.compilerArgs << '-help'

    }

    dependencies {
    compile project(':com.best')
    }

```

}

**This code failed to work:** // Here, as i understand, it uses Java Compiler API from javax.tools package to compile the code.

project(’:com.test’) {  
def dJar = project(’:com.best’).jar.outputs.files.getFiles()  
def addReads = "com.test=ALL-UNNAMED"  
def modulePath = dJar.getAt(0)

```
    tasks.withType(JavaCompile) {
   // options.fork = true
   // options.forkOptions.executable = '/home/sabari/java_builds/java9/bin/javac'

options.compilerArgs << '--add-reads'
    options.compilerArgs << addReads
options.compilerArgs << '--module-path'
    options.compilerArgs << modulePath
options.compilerArgs << '-help'

    }

    dependencies {
    compile project(':com.best')
    }

```

}

Output: invalid flag: -help

Again, is there anything wrong in the usage?

---

<div class="post-metadata">

**Author:** ![jjustinic](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/jjustinic/32/9005_2.png) [@jjustinic](https://discuss.gradle.org/u/jjustinic)\
**Post date:** [April 28, 2017, 12:48pm UTC](https://discuss.gradle.org/t/invalid-flag-message-with-gradle-clarification-needed/22490/2 "2017-04-28T12:48:23Z")

</div>

The difference between your usages is whether you provide one or two arguments for `--add-reads` and `--module-path`. As far as the API is concerned, `options.compilerArgs` is a collection of all compiler args, which requires that you provide `--add-reads` and `com.test=ALL-UNNAMED` as two separate arguments (they’re separate but related).

You can still use your declared variables if you update them to store separate items.

```
def addReads = ["--add-reads", "com.test=ALL-UNNAMED"]
def modulePath = ["--module-path", dJar.getAt(0)]
```
