Gary Sieling

Fixing scala type errors in gradle (“incompatible types: inference variable E has incompatible bounds” + “cannot infer type-variable”)

I experienced an error, where gradle failed to build some Scala code using the ZincCompiler, with a Java 8 JDK:

FAILURE: Build failed with an exception.
  (cannot infer type-variable(s) K#1,V#1
  (actual and formal argument lists differ in length))

error: incompatible types: inference variable E has incompatible bounds

This error can be caused by having an older java in the JAVA_HOME, e.g.:

C:\Program Files (x86)\Java\jdk1.8.0_25

The fix for me was to update to:

C:\Program Files\Java\jdk1.8.0_60

If you run “java -version” and “javac -version” and they don’t match, you may have multiple paths to java in $PATH.

The best thing is to have this at the front:

%JAVA_HOME%/bin

Note that you may additionally have symlinks to java in one or both of these locations, in addition to things you’ve added:

c:\windows
c:\ProgramData\Oracle\Java\

For more information, this appears to match this issue with the ZincCompiler:
https://github.com/typesafehub/zinc/issues/82

If this doesn’t resolve the issue, and you know that your build works on some other machine, you can run “gradlew -d [task]” to get verbose output, and compare them.

You’ll see a section like this, which shows the classpath, all the paths on your machine, etc, which should help figure out what the difference is:

 Compiling with Zinc Scala compiler.

 Setup = {
    scala compiler = ...
    scala library = ...
    scala extra = {
       ...
    }

    sbt interface = ...
    compiler interface sources = ...
    java home = C:\Program Files (x86)\Java\jdk1.8.0_25
    fork java = true
    cache directory = C:\Users\gsieling\.zinc\0.3.7
 }
 Inputs = {
    classpath = {
       ...
    }
    sources = {
       ...
    }
  }
    output directory = ...
    scalac options = {
       -deprecation
       -unchecked
       -feature
    }
    javac options = {
       -d
         ...
       -g
       -encoding
       UTF-8
       -XDuseUnsharedTable=true
    }
    cache file = ...
    analysis map = {
       ...
    }
    force clean = false
    java only = false
    compile order = Mixed
    incremental compiler options = {
       transitive step = 3
       recompile all fraction = 0.5
       debug relations = false
       debug api = false
       api dump = 
       api diff context size = 5
       transactional = false
       backup directory = 
       recompile on macro def = true
       name hashing = true
    }
    output relations = 
    output products = 
 }
Exit mobile version