3

I have a project with mixed Java and Scala sources, following the instructions on this page, which works when running Maven from the command line.

However, people using IDEs like IDEA and Netbeans have problems resolving Scala classes in Java code (but not the other way around, thanks to the nice plugins available). Is there a way to resolve them?

Note: I can build from the command line just fine; the Scala classes are compiled before the Java classes. I just want the IDE to recognize this as well. I could create a separate module for the Scala classes to resolve this problem, but it seems like overkill to me.

Note: In IDEA, I have "Compile Scala classes first" and that still does not do the trick.

Update: Here are the versions I'm using: scala-library 2.8.0 maven-scala-plugin 2.12 IDEA 9.0 Ultimate with latest scala plugin from plugin repos Netbeans 6.9 with scala nightly plugin

Pascal Thivent
  • 562,542
  • 136
  • 1,062
  • 1,124
retiman
  • 33
  • 3

2 Answers2

1

Which versions (of Scala, the IDEs, the Scala plugins) are you using?

I had the same issues when I started using Scala 2.7 around 9 months ago. While I haven't tried a mixed project recently, my understanding was that the issues would be resolved in Scala 2.8. It may be worth trying Eclipse 3.5.2 with Scala 2.8 -- my impression is that the Eclipse plugin is keeping up with changes in 2.8 better than the other IDE plugins (but I could be wrong).

Aaron Novstrup
  • 20,967
  • 7
  • 70
  • 108
  • Yup. Eclipse 3.5.2 with Scala 2.8 is working well for me. I can resolve Scala classes within Java code. Thanks! – retiman Aug 03 '10 at 01:56
  • @retiman I wonder if using the EAP version of IDEA would work. I recently ported a 2.7.7 codebase to 2.8, and switching to the EAP version resolved a bunch of issues for me. – Aaron Novstrup Aug 16 '10 at 19:26
  • @RavishBhagdev This question/answer is really out-dated. I suggest posting your own question to get a more timely answer. – Aaron Novstrup Aug 22 '14 at 15:56
1

I have being trying to figure out how to work with Eclipse Indigo + Scala IDE 2.9, m2eclipse, mix of scala 2.9 + jdk1.7 without luck.

I found out that using maven eclipse plugin (mvn eclipse:eclipse) and importing the project as eclipse project (not maven project) with the below customization cleaned up the error marks.

<plugin>
    <groupId>org.scala-tools</groupId>
    <artifactId>maven-scala-plugin</artifactId>

    <executions>
        <execution>
            <id>scala-compile-first</id>
            <phase>process-resources</phase>
            <goals>
                <goal>add-source</goal>
                <goal>compile</goal>
            </goals>
        </execution>
        <execution>
            <id>scala-test-compile</id>
            <phase>process-test-resources</phase>
            <goals>
                <goal>testCompile</goal>
            </goals>
        </execution>
    </executions>
</plugin>

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>build-helper-maven-plugin</artifactId>

    <executions>
        <execution>
            <id>add-source</id>
            <phase>generate-sources</phase>
            <goals>
                <goal>add-source</goal>
            </goals>
            <configuration>
                <sources>
                    <source>src/main/scala</source>
                </sources>
            </configuration>
        </execution>
        <execution>
            <id>add-test-source</id>
            <phase>generate-sources</phase>
            <goals>
                <goal>add-test-source</goal>
            </goals>
            <configuration>
                <sources>
                    <source>src/test/scala</source>
                </sources>
            </configuration>
        </execution>
    </executions    
</plugin>

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-eclipse-plugin</artifactId>
    <version>2.8</version>

    <configuration>
        <downloadSources>true</downloadSources>
        <downloadJavadocs>true</downloadJavadocs>
        <projectnatures>
            <projectnature>org.scala-ide.sdt.core.scalanature</projectnature>
            <projectnature>org.eclipse.jdt.core.javanature</projectnature>
        </projectnatures>
        <buildcommands>
            <buildcommand>org.scala-ide.sdt.core.scalabuilder</buildcommand>
        </buildcommands>
        <classpathContainers>
            <classpathContainer>org.scala-ide.sdt.launching.SCALA_CONTAINER"</classpathContainer>
            <classpathContainer>org.eclipse.jdt.launching.JRE_CONTAINER</classpathContainer>
        </classpathContainers>
        <excludes>
            <exclude>org.scala-lang:scala-library</exclude>
            <exclude>org.scala-lang:scala-compiler</exclude>
        </excludes>
        <sourceIncludes>
            <sourceInclude>**/*.scala</sourceInclude>
            <sourceInclude>**/*.java</sourceInclude>
        </sourceIncludes>
    </configuration>
</plugin>
Edson
  • 61
  • 4