0

我有一个带有混合 scala / java 模块的标准多项目 maven 项目。

当我在 IntelliJ 上打开这个项目时,它无法将 scala 文件夹识别为源/测试源根文件夹。

.
|-- 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

其结果是,不承认相互依赖。

我必须逐个模块并手动设置源文件夹。

你知道如何自动完成吗?

4

2 回答 2

4

当我想在 intelliJ 中使用 scala 设置 maven 子模块时,我遇到了类似的问题。我最终成功地使用了特定的 pom.xml。你可以这样调查。

仅供参考,我将从我的 pom.xml 中为您提供一些可能对您有用的摘录:

父 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>

子 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>

不幸的是,我不能确切地说哪一部分是基础的。希望它可以帮助。

于 2017-04-25T09:55:40.393 回答
1

很奇怪,这个问题与 Maven 导入程序内存问题有关。我增加了导入内存设置并重新导入了项目,它就像魔术一样工作。 在此处输入图像描述

于 2017-04-25T12:33:21.530 回答