[Solved] Help with references in rt.jar

I have a rather old project that uses Ant, that I’m trying to migrate to Gradle. However, I seem to have hit an issue where the code is trying to import import sun.swing.table.*;, yet Gradle can’t seem to find the symbols which are in $JAVA_HOME/lib/rt.jar.

The .java file that I’m trying to compile is this:

 * This Java source file was generated by the Gradle 'init' task.
package sample.build;

import sun.swing.table.*;

public class Library {
    public boolean someLibraryMethod() {
        return true;

The output of ./gradlew build is:

 ./gradlew build

> Task :compileJava FAILED
/private/tmp/sample-build/src/main/java/sample/build/Library.java:6: error: package sun.swing.table does not exist
import sun.swing.table.*;
1 error

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':compileJava'.
> Compilation failed; see the compiler error output for details.

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

1 actionable task: 1 executed
Exit 1

Any help would be great.

System details

  • Java: 1.8.0_171
  • Gradle Version: 5.2
  • OS: Mac OS X

These are all the things that I would be looking at on my own machine if I got the same message you’re getting:

  • java -version
  • echo $JAVA_HOME
  • gradle -version
  • gradle --scan --stacktrace check
  • ant --version

Are you able to share the output of any of those?

All of them would be ideal. But only as much as you’re comfortable with sharing publicly, naturally.

I was able to resolve this by adding the following block to build.gradle:

tasks.withType(JavaCompile) {
  options.fork = true
  options.forkOptions.executable = 'javac'
  options.compilerArgs << '-XDignore.symbol.file'

See - Java compiler ignore.symbol.file for the source of the modifications.

Hey that’s awesome! Thanks for sharing your solution :+1: