1

I need to compile a code which uses com.sun.image.codec.jpeg package and its friends. I know, I know, its our company legacy code and we need to compile it as is. My problem is - Eclipse compile those files without problem, it just works. IDEA do the same - compile and works. The problem is Gradle - it gives me errors like

error: package com.sun.image.codec.jpeg does not exist

I know - add -XDignore.symbol.file to compilator.

I did

compileJava.options.compilerArgs.add '-XDignore.symbol.file'

in my build.grade, I turned verbose mode and I see parameter gets passed correctly

20:28:16.148 [DEBUG] [org.gradle.api.internal.tasks.compile.NormalizingJavaCompiler] Compiler arguments: -d C:\workspace\blabla -g -XDignore.symbol.file -classpath C:\workspace\blabla_lots_of_jars.jar  C:\workspace\tons_of_java_files.java
20:28:16.153 [INFO] [org.gradle.api.internal.tasks.compile.jdk6.Jdk6JavaCompiler] Compiling with JDK Java compiler API.

But compilation fails. On the other question I found that I should add to gradle file a line

compileJava.options.useAnt = true

which makes, you guessed, that everything compiles. The debug log is a bit different, but shows that also params are passed correctly

21:50:34.101 [DEBUG] [org.gradle.api.internal.project.ant.AntLoggingAdapter] [ant:javac] Compilation arguments:
'-d'
'C:\workspace\blabla'
'-classpath'
'tons_of_jars'
'-target'
'1.7'
'-g'
'-XDignore.symbol.file'
'-source'
'1.7'

But useAnt will be removed and its seems like a dirty hack.

I use newest Gradle (1.8) and jdk1.7.0_25 on Win8 - but I doubt it matters

How can I make Gradle properly compile my sources and respect my compilation parameters?

4

1 回答 1

2

据我所知,JDK 编译器 API(这是JavaCompile任务使用的)默默地忽略了该-XDignore.symbol.file标志(我也看到了其他一些选项)。目前,我知道的唯一解决方案是回退到基于 Ant 的编译器,即使它已被弃用。

编辑:另一种选择是强制JavaCompile任务使用javac命令行编译器:

compileJava {
    options.fork = true
    options.forkOptions.executable = "javac" // assumes that javac is on PATH
    options.compilerArgs << "-XDignore.symbol.file"
}
于 2013-10-01T20:08:30.573 回答