1

I have a project with standard multi project maven with mixed scala / java modules.

When I open this project on IntelliJ it fails to recognise scala folders as sources / test-sources root folders.

.
|-- pom.xml
`-- src
    |-- it
    |   |-- resources
    |   |   `-- data.csv
    |   `-- scala  #### TEST SOURCES ###
    |       `-- com
    |           `-- my
    |               `-- example
    |                   `-- jetty
    |                       `-- JettyBasedServerIT.scala
    |-- main
    |   `-- scala #### SOURCES ###
    |       `-- com
    |           `-- my
    |               `-- example
    |                   `-- jetty
    |                       `-- JettyBasedServer.scala
    `-- test
        `-- scala #### TEST SOURCES ###
            `-- com
                `-- my
                    `-- example
                        `-- jetty
                            `-- MainArgumentsTest.scala

As a result, interdependencies are not recognized.

I have to go module by module and manually set the the sources folders.

Do you know how to do it automtically?

orshachar
  • 4,837
  • 14
  • 45
  • 68

2 Answers2

4

I got similar issues when I wanted to set maven submodules with scala in intelliJ. I eventually succeed with particular pom.xml. You may investigate this way.

Just for information I'll give you some extracts from my pom.xml that might be useful to you :

Parent pom.xml

<pluginManagement>
    <plugins>
            <!-- configure scala style -->
            <plugin>
                <groupId>org.scalastyle</groupId>
                <artifactId>scalastyle-maven-plugin</artifactId>
                <version>0.8.0</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>check</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <verbose>false</verbose>
                    <failOnViolation>true</failOnViolation>
                    <includeTestSourceDirectory>true</includeTestSourceDirectory>
                    <failOnWarning>false</failOnWarning>
                    <sourceDirectory>${basedir}/src/main/scala</sourceDirectory>
                    <testSourceDirectory>${basedir}/src/test/scala</testSourceDirectory>
                    <outputFile>${project.basedir}/target/scalastyle-output.xml</outputFile>
                    <outputEncoding>UTF-8</outputEncoding>
                </configuration>
            </plugin>

            <!-- set scala maven plugin version -->
            <plugin>
                <groupId>net.alchim31.maven</groupId>
                <artifactId>scala-maven-plugin</artifactId>
                <version>3.2.2</version>
                <configuration>
                    <scalaCompatVersion>${scala.binary.version}</scalaCompatVersion>
                    <scalaVersion>${scala.version}</scalaVersion>
                </configuration>

            </plugin>
    </plugins>
</pluginManagement>

Child pom.xml

<build>
        <plugins>

            <!-- Scala Compiler -->
            <plugin>
                <groupId>net.alchim31.maven</groupId>
                <artifactId>scala-maven-plugin</artifactId>
                <executions>
                    <!-- Run scala compiler in the process-resources phase, so that dependencies on
                        scala classes can be resolved later in the (Java) compile phase -->
                    <execution>
                        <id>scala-compile-first</id>
                        <phase>process-resources</phase>
                        <goals>
                            <goal>compile</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <jvmArgs>
                        <jvmArg>-Xms128m</jvmArg>
                        <jvmArg>-Xmx512m</jvmArg>
                    </jvmArgs>
                </configuration>
            </plugin>

            <!-- Adding scala source directories to build path -->
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>build-helper-maven-plugin</artifactId>
                <version>1.7</version>
                <executions>
                    <!-- Add src/main/scala to eclipse build path -->
                    <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>
                    <!-- Add src/test/scala to eclipse build path -->
                    <execution>
                        <id>add-test-source</id>
                        <phase>generate-test-sources</phase>
                        <goals>
                            <goal>add-test-source</goal>
                        </goals>
                        <configuration>
                            <sources>
                                <source>src/test/scala</source>
                            </sources>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

            <!-- Scala Code Style, most of the configuration done via plugin management -->
            <plugin>
                <groupId>org.scalastyle</groupId>
                <artifactId>scalastyle-maven-plugin</artifactId>
                <configuration>
                    <configLocation>${project.basedir}/../../tools/maven/scalastyle-config.xml</configLocation>
                </configuration>
            </plugin>

Unfortunately I couldn't say exactly which part is fondamental. Hope it could help.

ImbaBalboa
  • 851
  • 9
  • 23
1

Weird enough the problem was related to maven importer memory issue. I increased the import memory settings and re-imported the project and it worked like magic. enter image description here

orshachar
  • 4,837
  • 14
  • 45
  • 68
  • You can set this option in your pom.xml as you can see in my answer. – ImbaBalboa Apr 25 '17 at 13:01
  • @ImbaBalboa Thanks for your answer. I see that you configure the JVM args specifically of the java-maven-plugin which I already had and did not affect intellij. – orshachar Apr 25 '17 at 13:57