Hi.
I’m checking JDK8u60’s bug fix of JDK-8079044 javac -parameters does not emit parameter names for lambda expressions with a project, 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.
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…
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…
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