# It seems that javac compiler options is not passed to compileJava task on Gradle2.6 with JDK8u60

**URL:** <https://discuss.gradle.org/t/it-seems-that-javac-compiler-options-is-not-passed-to-compilejava-task-on-gradle2-6-with-jdk8u60/11271>\
**Category:** Help/Discuss\
**Created:** [August 20, 2015, 7:41pm UTC](https://discuss.gradle.org/t/it-seems-that-javac-compiler-options-is-not-passed-to-compilejava-task-on-gradle2-6-with-jdk8u60/11271 "2015-08-20T19:41:39Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Shinya\_Mochida](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/shinya_mochida/32/2393_2.png) [@Shinya\_Mochida](https://discuss.gradle.org/u/Shinya_Mochida)\
**Post date:** [August 20, 2015, 7:41pm UTC](https://discuss.gradle.org/t/it-seems-that-javac-compiler-options-is-not-passed-to-compilejava-task-on-gradle2-6-with-jdk8u60/11271/1 "2015-08-20T19:41:39Z")

</div>

Hi.

I’m checking JDK8u60’s bug fix of [JDK-8079044 javac -parameters does not emit parameter names for lambda expressions](https://bugs.openjdk.java.net/browse/JDK-8079044) with [a project](https://github.com/benjiman/lambda-type-references), which requires `javac` option `-parameters` to work correctly, as subprojects. But It seems that Gradle’s compiler setting `compileJava.options.compilerArgs` is not passed to the subproject’s `compileJava` task.

The project structure is as follows.

```gradle
rootProject
+-setting.gradle
+-build.gradle
+-src
| +-main
| | +-groovy
| | +-my.pkg
| +-test
| +-groovy
| +-my.pkg
+-type-ref
  +-src
    +-main
    | +-java
    | +-com.benjiweber.typeref
    +-test
      +-java
        +-com.benjiweber.typeref

```

My build script is…

```groovy
plugins {
    id 'groovy'
    id 'idea'
}

ext {
    jdkLevel = 1.8
    encoding = 'UTF-8'
}

subprojects {
    apply plugin: 'java'
    repositories {
        mavenCentral()
    }
}

repositories {
    mavenCentral()
}

dependencies {
    compile project(':type-ref')
    compile 'org.codehaus.groovy:groovy:2.3.10'
    testCompile 'junit:junit:4.12'
    testCompile ('org.spockframework:spock-core:1.0-groovy-2.3') {
        exclude module: 'groovy-all'
        exclude module: 'junit'
    }
}

tasks.withType(JavaCompile).each {
    it.sourceCompatibility = jdkLevel
    it.targetCompatibility = jdkLevel
    it.options.encoding = encoding
}

project(':type-ref') {
    dependencies {
        testCompile 'junit:junit:4.12'
        testCompile 'org.mockito:mockito-all:1.9.5'
    }
    compileJava {
        sourceCompatibility = jdkLevel
        targetCompatibility = jdkLevel
        // this subproject requires -parameters option
        options.compilerArgs << '-parameters'
        options.encoding = encoding
    }
}

```

(The `type-ref` subproject is the project, I mentioned before.)

The root project has a test using `type-ref` project library, and when I run the tests, it fails with error message…

```gradle
Caused by: java.lang.IllegalStateException: You need to compile with javac -parameters for parameter reflection to work; You also need java 8u60 or newer to use it with lambdas
	at com.benjiweber.typeref.NamedValue.checkParametersEnabled(NamedValue.java:13)
	at com.benjiweber.typeref.NamedValue.name(NamedValue.java:8)

```

The error message says that the subproject is not compiled with option `-parameters`.

How do I pass compiler option(`compileJava.options.compilerArgs`)?

* * *

OS | Mac OSX 10.10.4  
JDK | 8u60  
Gradle | 2.6

---

<div class="post-metadata">

**Author:** ![sterling](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/sterling/32/5395_2.png) [@sterling](https://discuss.gradle.org/u/sterling)\
**Post date:** [August 21, 2015, 11:18pm UTC](https://discuss.gradle.org/t/it-seems-that-javac-compiler-options-is-not-passed-to-compilejava-task-on-gradle2-6-with-jdk8u60/11271/2 "2015-08-21T23:18:33Z")

</div>

The tests failed initially for me because the classes being tested were not compiled with `-parameters` (the test sources, not the main sources).

You should change your `type-ref` project to configure all of the compile tasks of type `JavaCompile` to use `-parameters` since the tests are looking for parameter names from test classes:

```gradle
tasks.withType(JavaCompile) { 
     sourceCompatibility = jdkLevel
     targetCompatibility = jdkLevel
     // this subproject requires -parameters option
     options.compilerArgs << '-parameters'
     options.encoding = encoding
}

```

`compileJava` only configures the task used to compile the main sources (there’s a corresponding `compileTestJava` too).

I would probably set the source/target compatibility on the project level vs on the compile task.

I would also not use `tasks.withType(JavaCompile).` **each** because that iterates over the task container at that point in time vs over all of the tasks of type `JavaCompile` that are ever created. Just remove the `.each` and that will be better.

---

<div class="post-metadata">

**Author:** ![Shinya\_Mochida](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/shinya_mochida/32/2393_2.png) [@Shinya\_Mochida](https://discuss.gradle.org/u/Shinya_Mochida)\
**Post date:** [August 22, 2015, 12:25am UTC](https://discuss.gradle.org/t/it-seems-that-javac-compiler-options-is-not-passed-to-compilejava-task-on-gradle2-6-with-jdk8u60/11271/3 "2015-08-22T00:25:44Z")

</div>

Thanks!

It works fine.
