17 Replies Last post: May 6, 2011 8:27 PM by Pavel Fatin  
Andreas Joseph Krogh Newbie 39 posts since
Jul 12, 2005
Currently Being Moderated

Apr 30, 2011 10:51 AM

Getting compiler-errors in IDEA but not when using Maven

Anyone can explain why compiling in IDEA gives compiler-error on valid code, which maven compiles just fine?

 

The java-code is (in maven-module A):


public class Fisk {
    public static class A {
    }
    public static A A
= new A();
}

 

The following JAVA-code is example of usage:

 

    Fisk.A a = new Fisk.A();
   
Fisk.A b = Fisk.A;

Then in maven-module B, which has A as dependency the following code results in compiler-error in IDEA (but works in maven):

 

    val fisk = new Fisk.A()
   
val strupp: Fisk.A = Fisk.A

I posted a question regarding this here:

http://stackoverflow.com/questions/5830032/scala-java-incompatibility-referencing-static-fields-in-a-class-with-the-same-nam

 

And filed a ticket here: http://youtrack.jetbrains.net/issue/SCL-3146

Jason Zaugg Novice 106 posts since
Oct 20, 2009
Currently Being Moderated
Apr 30, 2011 11:02 AM in response to: Andreas Joseph Krogh
Re: Getting compiler-errors in IDEA but not when using Maven

You could add this to your log.xml in the IDEA installation to log out the compiler command line:

 

<category name="#org.jetbrains.plugins.scala.compiler">
        <priority value="DEBUG"/>
        <appender-ref ref="FILE"/>
    </category>

 

Or post a zip of a minimal project that demonstrates the problem.

 

-jason

Pavel Fatin JetBrains 279 posts since
Nov 12, 2009
Currently Being Moderated
May 6, 2011 2:54 PM in response to: Andreas Joseph Krogh
Re: Getting compiler-errors in IDEA but not when using Maven

I'm now looking into the problem...

Pavel Fatin JetBrains 279 posts since
Nov 12, 2009
Currently Being Moderated
May 6, 2011 3:45 PM in response to: Andreas Joseph Krogh
Re: Getting compiler-errors in IDEA but not when using Maven

The root of the problem is some bug in scalac Java parser / typer (and it's a good idea to report the bug to Scala's issue tracker).

 

To invoke the bug, you need to feed both given .java & .scala files into scalac (move Fish.java next to FishTest.scala, run "mvn compile" and you will get the same error).

 

When there're two separate modules, Maven compiles them sequentially: it runs javac first for the Java module, and then it runs scalac for the second, so Scala compiler uses binary .class files instead of Java sources (and thus scalac bug bypassed). However, Maven (of course) won't to compile those files within a single module.

 

By default, Scala plugin for IDEA compiles Scala files in the first place, but you may uncheck "Project Settings / Scala Compiler / Compile Scala files first" to switch the order, so you will be able to compile your sample files (even in a single module).

 

P.S. Many thanks to Jason Zaugg for clarifying the problem and fixing "Compile Scala files first" setting.

Jason Zaugg Novice 106 posts since
Oct 20, 2009
Currently Being Moderated
May 6, 2011 3:51 PM in response to: Pavel Fatin
Re: Getting compiler-errors in IDEA but not when using Maven

If you select 'Compile Java Files first', why do we include the .java files from other modules in the batch of files passed to Scalac? Should we just limit it to .java files from the current module?

Pavel Fatin JetBrains 279 posts since
Nov 12, 2009
Currently Being Moderated
May 6, 2011 3:57 PM in response to: Jason Zaugg
Re: Getting compiler-errors in IDEA but not when using Maven

In the sample project "test-scala" module has an explicit dependency on "test-java" one.

Jason Zaugg Novice 106 posts since
Oct 20, 2009
Currently Being Moderated
May 6, 2011 7:32 PM in response to: Andreas Joseph Krogh
Re: Getting compiler-errors in IDEA but not when using Maven

I agree, I still don't see the need to ever pass .java files from downstream modules to scalac.

Pavel Fatin JetBrains 279 posts since
Nov 12, 2009
Currently Being Moderated
May 6, 2011 7:57 PM in response to: Jason Zaugg
Re: Getting compiler-errors in IDEA but not when using Maven

It seems that there's no need to pass external .java files to scalac except when there's a mutual module dependency.

Jason Zaugg Novice 106 posts since
Oct 20, 2009
Currently Being Moderated
May 6, 2011 7:59 PM in response to: Pavel Fatin
Re: Getting compiler-errors in IDEA but not when using Maven

Oh wow, I didn't know that was possible! Sounds simultaneously evil and convenient...

Pavel Fatin JetBrains 279 posts since
Nov 12, 2009
Currently Being Moderated
May 6, 2011 10:55 PM in response to: Jason Zaugg
Re: Getting compiler-errors in IDEA but not when using Maven

In reality, I'm unsure whether we need to pass .java files or not.

 

Current implementation of project compilation is, undoubtedly, based on it's own historical prerequisites, and  some of them I know nothing about.

 

The issue needs further investigation.

Pavel Fatin JetBrains 279 posts since
Nov 12, 2009
Currently Being Moderated
May 6, 2011 4:22 PM in response to: Andreas Joseph Krogh
Re: Getting compiler-errors in IDEA but not when using Maven

It's worth to point-out that it'll be impossible to compile files with Java-Scala circular dependencies when "Compile Scala files first" is turned off.

Pavel Fatin JetBrains 279 posts since
Nov 12, 2009
Currently Being Moderated
May 6, 2011 4:09 PM in response to: Andreas Joseph Krogh
Re: Getting compiler-errors in IDEA but not when using Maven

BTW, you don't need to include dependency on scala-compiler in scala/pom.xml (if you don't use Scalac classes directly in your code).

More Like This

  • Retrieving data ...