Re: [scala-ide-user] Phantom errors in mixed Java/Scala Maven based project

469 views
Skip to first unread message

iulian dragos

unread,
May 28, 2013, 5:27:01 AM5/28/13
to scala-i...@googlegroups.com
Hi Eyal,

First question is: do you use the `m2e-scala` Eclipse plugin?

I cannot reproduce your exact setup, but cyclic dependencies like this one have to be "broken" by compiling Scala and Java sources together. The Scala compiler can do that, and there are options in Eclipse for choosing this mode of operation. You can find them on the Scala Compiler page, on the "Build Manager" Tab. Make sure the choice is "Mixed". I can build fine a project with two classes, one Scala and one Java, that reference each-other.

I am surprised the build succeeds in Maven, but I am not a big expert on that (I see "scala-compile-first", which makes me think it's a not using the "mixed" mode). Maybe DavidB, the author of `scala-maven-plugin` can help, he's following this mailing list.

cheers,
iulian



On Tue, May 28, 2013 at 9:56 AM, Eyal Allweil <eyal.a...@gmail.com> wrote:
We have an existing Java/Maven based project, and are interested in incrementally adopting Scala. One coworker, using IntelliJ, added some Scala code into a single Eclipse project/Maven module. The Scala code both depends on Java classes in the same project, and some of the Java classes depend on it, in other words, a circular dependency within this project/module. The maven build is successful, and the project builds and runs in IntelliJ, but we can't get it to work on any Eclipse/Scala IDE configuration regularly. The best we've achieved is that the project builds and runs with three "phantom" errors:

This would be acceptable, except that upon doing a Project->Clean All, Eclipse detects compilation errors -Java not recognizing the Scala classes, normally - and I don't have a system of steps that systematically return me to the desired state in which it builds and runs.

I've followed the steps in this tutorial to set up a fresh Scala IDE environment: http://scala-ide.org/docs/tutorials/m2eclipse/index.html

I've put the "build" section of our pom.xml below - you can see that we're using the maven-compile-plugin, maven-war-plugin, and maven-jar-plugin, scala-maven-plugin and eclipse-m2e.

If anyone can help us get a consistently working Scala IDE environment, we would really appreciate it - our other option is to go with IntelliJ, but most of us are used to and prefer Eclipse.

Thanks in advance!

    <build>
        <plugins>
            <plugin>
                <groupId>org.jacoco</groupId>
                <artifactId>jacoco-maven-plugin</artifactId>
                <version>0.6.1.201212231917</version>
                <configuration>
                    <haltOnFailure>false</haltOnFailure>
                    <check>
                        <classRatio>0</classRatio>
                        <instructionRatio>0</instructionRatio>
                        <methodRatio>0</methodRatio>
                        <branchRatio>0</branchRatio>
                        <complexityRatio>0</complexityRatio>
                        <lineRatio>0</lineRatio>
                    </check>
                </configuration>
                <executions>
                    <execution>
                        <id>prepare-agent</id>
                        <goals>
                            <goal>prepare-agent</goal>
                        </goals>
                    </execution>
                    <execution>
                        <id>check</id>
                        <goals>
                            <goal>check</goal>
                        </goals>
                    </execution>
                    <execution>
                        <id>report</id>
                        <phase>prepare-package</phase>
                        <goals>
                            <goal>report</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>2.4</version>
                <configuration>
                    <source>1.7</source>
                    <target>1.7</target>
                </configuration>
                <executions>
                    <execution>
                        <phase>compile</phase>
                        <goals>
                            <goal>compile</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>pl.project13.maven</groupId>
                <artifactId>git-commit-id-plugin</artifactId>
                <version>1.9</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>revision</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <generateGitPropertiesFile>true</generateGitPropertiesFile>
                    <generateGitPropertiesFilename>src/main/resources/git.properties</generateGitPropertiesFilename>
                </configuration>
            </plugin>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <version>2.4</version>
                <configuration>
                    <archive>
                        <manifest>
                            <addDefaultImplementationEntries>true</addDefaultImplementationEntries>
                        </manifest>
                        <manifestEntries>
                            <Implementation-Build>${buildNumber}</Implementation-Build>
                            <Build-Date>${timestamp}</Build-Date>
                        </manifestEntries>
                    </archive>
                </configuration>
            </plugin>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-war-plugin</artifactId>
                <version>2.2</version>
                <configuration>
                    <archive>
                        <manifest>
                            <addDefaultImplementationEntries>true</addDefaultImplementationEntries>
                        </manifest>
                        <manifestEntries>
                            <Implementation-Build>${buildNumber}</Implementation-Build>
                            <Build-Date>${timestamp}</Build-Date>
                        </manifestEntries>
                    </archive>
                </configuration>
            </plugin>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <version>2.4</version>
                <executions>
                    <execution>
                        <id>copy</id>
                        <phase>package</phase>
                    </execution>
                </executions>
            </plugin>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.13</version>
                <configuration>
                    <includes>
                        <include>**/*Test*.java</include>
                    </includes>
                </configuration>
            </plugin>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-site-plugin</artifactId>
                <version>3.1</version>
                <configuration>

                    <reportPlugins>
                        <plugin>
                            <groupId>org.apache.maven.plugins</groupId>
                            <artifactId>maven-project-info-reports-plugin</artifactId>
                            <version>2.4</version>
                            <reportSets>
                                <reportSet>
                                    <reports>
                                        <report>cim</report>
                                        <report>distribution-management</report>
                                        <report>index</report>
                                        <report>issue-tracking</report>
                                        <report>modules</report>
                                        <report>project-team</report>
                                        <report>scm</report>
                                        <report>summary</report>
                                    </reports>
                                </reportSet>
                            </reportSets>
                        </plugin>

                        <plugin>
                            <groupId>org.apache.maven.plugins</groupId>
                            <artifactId>maven-changelog-plugin</artifactId>
                            <version>2.2</version>
                        </plugin>

                        <plugin>
                            <groupId>org.codehaus.mojo</groupId>
                            <artifactId>findbugs-maven-plugin</artifactId>
                            <version>2.3.2</version>
                            <configuration>
                                <findbugsXmlOutput>true</findbugsXmlOutput>
                                <xmlOutput>true</xmlOutput>
                            </configuration>
                        </plugin>

                        <plugin>
                            <groupId>org.apache.maven.plugins</groupId>
                            <artifactId>maven-pmd-plugin</artifactId>
                            <version>2.7.1</version>
                            <configuration>
                                <minimumTokens>100</minimumTokens>
                                <aggregate>true</aggregate>
                                <targetJdk>1.7</targetJdk>
                            </configuration>
                        </plugin>

                        <plugin>
                            <groupId>org.apache.maven.plugins</groupId>
                            <artifactId>maven-dependency-plugin</artifactId>
                            <version>2.4</version>
                        </plugin>
                    </reportPlugins>

                </configuration>
            </plugin>
<plugin>
        <groupId>net.alchim31.maven</groupId>
        <artifactId>scala-maven-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>
        </plugins>

        <pluginManagement>
            <plugins>
                <!--This plugin's configuration is used to store Eclipse m2e settings
                only. It has no influence on the Maven build itself. -->
                <plugin>
                    <groupId>org.eclipse.m2e</groupId>
                    <artifactId>lifecycle-mapping</artifactId>
                    <version>1.0.0</version>
                    <configuration>
                        <lifecycleMappingMetadata>
                            <pluginExecutions>
                                <pluginExecution>
                                    <pluginExecutionFilter>
                                        <groupId>pl.project13.maven</groupId>
                                        <artifactId>git-commit-id-plugin</artifactId>
                                        <versionRange>
                                            [1.9,)
                                        </versionRange>
                                        <goals>
                                            <goal>revision</goal>
                                        </goals>
                                    </pluginExecutionFilter>
                                    <action>
                                        <ignore/>
                                    </action>
                                </pluginExecution>
                            </pluginExecutions>
                        </lifecycleMappingMetadata>
                    </configuration>
                </plugin>
            </plugins>
        </pluginManagement>

        <resources>
            <resource>
                <directory>${project.basedir}/src/main/resources</directory>
                <filtering>true</filtering>
                <excludes>
                    <exclude>**/*.orig</exclude>
                </excludes>
            </resource>
        </resources>
        <testResources>
            <testResource>
                <directory>${project.basedir}/src/test/resources</directory>
                <filtering>true</filtering>
            </testResource>
        </testResources>
        <finalName>${project.artifactId}</finalName>
    </build>

--
You received this message because you are subscribed to the Google Groups "Scala IDE User" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scala-ide-use...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 



--
« Je déteste la montagne, ça cache le paysage »
Alphonse Allais

David Bernard

unread,
May 29, 2013, 3:33:43 AM5/29/13
to scala-i...@googlegroups.com
Hi Iulian,

IIRC it's no longer required to run scalac->javac->scalac for mixed project. And because scalac is able to parse an use .java (+/- like .class) the configuration used is this pom.xml (scalac -> javac) is fine.

Hi Eyal,

For a valid code on maven / intellij, can you share the errors reported into eclipse ?

/davidB

David Bernard

unread,
May 29, 2013, 3:44:52 AM5/29/13
to scala-i...@googlegroups.com
2. import has maven project into eclipse .../samples/prj-scala-cycle-java
3. on src/test/scala/samples/AppTest.java : Run as "Scala JUnit Test"


Eyal Allweil

unread,
May 30, 2013, 1:19:59 PM5/30/13
to scala-i...@googlegroups.com
Hi Julian,

I am using the m2e-scala plugin, and my buildmanager choice is mixed and sbt. I'm not sure myself about all the niceties of our maven build, but does work, and consistently.

Eyal Allweil

unread,
May 30, 2013, 1:23:15 PM5/30/13
to scala-i...@googlegroups.com
Hi David,

No, I don't have errors in this project, and the Scala Junit test runs successfully.

In my project I have two kinds of errors:

I have errors like these four, consistently (they don't disappear) - but they don't really prevent me from working, compiling, and running my project.

error while loading JsonSerialize$Inclusion, class file '/home/eyal/.m2/repository/org/codehaus/jackson/jackson-mapper-asl/1.9.4/jackson-mapper-asl-1.9.4.jar(org/codehaus/jackson/map/annotate/JsonSerialize$Inclusion.class)' is broken (class java.lang.UnsupportedOperationException/addChild inapplicable for <none>)    eyal-proj-ws        Unknown    Scala Problem

error while loading com.vidmind.annotations., class file '/home/eyal/wildfire/server/entities/target/classes/com/vidmind/annotations/FilteringPolicy$Policy.class' is broken (class java.lang.UnsupportedOperationException/addChild inapplicable for <none>)    eyal-proj-ws        Unknown    Scala Problem

error while loading FilteringPolicy$Policy, class file '/home/eyal/wildfire/server/entities/target/classes/com/vidmind/annotations/FilteringPolicy$Policy.class' is broken (class java.lang.UnsupportedOperationException/addChild inapplicable for <none>)    eyal-proj-ws        Unknown    Scala Problem

error while loading org.codehaus.jackson.map.annotate., class file '/home/eyal/.m2/repository/org/codehaus/jackson/jackson-mapper-asl/1.9.4/jackson-mapper-asl-1.9.4.jar(org/codehaus/jackson/map/annotate/JsonSerialize$Inclusion.class)' is broken (class java.lang.UnsupportedOperationException/addChild inapplicable for <none>)    eyal-proj-ws        Unknown    Scala Problem

And I have compilation errors, in my the Java classes, that are caused by the Eclipse "forgetting" the existence of the Scala classes they depend on. The weird thing is that sometimes, by cleaning, removing and adding the scala nature, and doing "update from maven", I can make them go away- but I don't have a consistent method of doing this. These errors are the ones that prevent me from working.

By the way, thanks for helping me out with this- there's an entire team of Eclipse devs like me that appreciate it :-)

Brian Kent

unread,
Dec 24, 2013, 1:47:18 PM12/24/13
to scala-i...@googlegroups.com
Was there ever any resolution here? I am having the exact same issue...

Eyal Allweil

unread,
Dec 26, 2013, 10:51:04 AM12/26/13
to scala-i...@googlegroups.com
My Java-Scala compilation problems pretty much all went away after I upgraded my Scala-IDE. I've since upgraded to the first milestone of version 4, but I think it started working when I updated to version 3 - don't remember if 3.00, 3.01, or 3.02. I also have the "maven integration for scala ide" installed, version 0.4.3.201303250910.

I don't remember making more changes to my pom.xmls, but I can look into that if you're using the same version of Scala IDE and still encountering these problems.


--
You received this message because you are subscribed to a topic in the Google Groups "Scala IDE User" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/scala-ide-user/N_DfMWqEUig/unsubscribe.
To unsubscribe from this group and all its topics, send an email to scala-ide-use...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/scala-ide-user/67625b84-472e-4ed7-a4bd-afd76b4debd6%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages