build error in Intellij, but no error on "ant build"

Answered

I have a project that is built with Ant. I can run "ant build tests" without a build error from the CLI. If I run a single JUnit test from Intellij (open file context menu on test file (e.g. PostfixExpressionCFABuilderTest.java) and selet "Run 'PostfixExpressionCFABuilderTest'"), I get a build error (shown in tab "Build" in the messages tool window):

/path/to/cpachecker/src/org/sosy_lab/cpachecker/cfa/CProgramScope.java
Error:(335, 25) java: incompatible types: cannot infer type-variable(s) T
(argument mismatch; java.lang.Class is not a functional interface)

 

How could that be? Is a build process other than "ant build" run? Why is there an error? Does it use another compiler? How can I configure Intellij to run the single test without build errors?

0
8 comments

Ant and IntelliJ IDEA build processes are completely different and can use different JDK version and compiler options.

Make sure your project is using exactly the same java version that works in the command line in the Ant build.

0

I added a target to build.xml

<target name="print-version">
    <echo>Java/JVM version: ${ant.java.version}</echo>
    <echo>Java/JVM detail version: ${java.version}</echo>
</target>

and run "ant print-version" which outputs

print-version:
    [echo] Java/JVM version: 1.8
    [echo] Java/JVM detail version: 1.8.0_151

Intellij shows in tab "Build" in the messages tool window:

Information:javac 1.8.0_151 was used to compile java sources

It seems they are using the same SDK. Is there a more reliable way to check?

0

Check the build.log: https://intellij-support.jetbrains.com/hc/articles/207241085.

Your IntelliJ IDEA project may also build different set of files with different dependencies and options, so it's hard to say what's the problem without a sample project to reproduce it.

For example, your Ant build can skip the files which IntelliJ IDEA tries to compile and fails.

0

What am I looking for in the build.log?

I suppose it is a bug in the compiler as described here. If Intellij uses the same compiler as Ant, there should be no build error.

CPAChecker is not a minimal sample project, but it is open source and could be used to reproduce the error. The .idea directory is tracked in the VCS.

0

Ant doesn't seem to use the vanilla javac for compilation, instead it uses 

<!-- We use error-prone as the compiler, cf. http://errorprone.info/ -->
com.google.errorprone.ErrorProneAntCompilerAdapter

As the error is reported by the javac compiler, it's not a problem of IntelliJ IDEA, it's a problem of the code or a bug in the compiler.

Most likely, the behavior is different because of the different compiler.

0

I tried to use the Error-prone Compiler Integration plugin for Intellij, but it throws an unhandled exception.

After that, I tried to configure the run configuration of my test to use Ant to build: I added "Run Ant target 'build'" to "Before launch" and removed the regular "Build" configuration from "Before launch". However, Ant fails with errors (OutOfMemoryError: GC overhead limit exceeded) even though I can run it without errors using (Build > CPAChecker > build).

0

You can try increasing the heap size here: 

0

Thanks, that worked. I guess this is a good solution. Even though I'd prefer that Intellij uses the same compiler (configuration) for code analysis as Ant. But I guess that's not easily possible. I would have to maintain two configurations (Ant and Intellij).

0

Please sign in to leave a comment.