简体   繁体   中英

Sun JPEGImageEncoder compilation in Gradle

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?

From what I can tell, the JDK compiler API (which is what the JavaCompile task uses) silently ignores the -XDignore.symbol.file flag (I've also seen this for some other options). For now, the only solution that I'm aware of is to fall back to the Ant based compiler, even though it's deprecated.

EDIT: Another option is to force the JavaCompile task to use the javac command line compiler:

compileJava {
    options.fork = true
    options.forkOptions.executable = "javac" // assumes that javac is on PATH
    options.compilerArgs << "-XDignore.symbol.file"
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM