如何将现有的Maven Java项目转换为Scala IDE的Scala项目?

时间:2016-06-07 08:01:50

标签: eclipse scala maven

库有一个我从github克隆的示例项目。它是一个Java项目,使用Maven进行依赖项管理。我想在项目中添加一些Scala代码。我正在使用Eclipse Scala IDE。

1 个答案:

答案 0 :(得分:0)

默认情况下,Maven不支持Scala,您需要启用scala-maven-plugin。这是我使用的pom.xml的<plugins>部分中的配置:

    <plugins>

        <!-- other plugins ... -->

        <!-- set scala plugin before compiler plugin -->
        <plugin>
            <groupId>net.alchim31.maven</groupId>
            <artifactId>scala-maven-plugin</artifactId>
            <version>${scala.plugin.version}</version>
            <configuration>
                <recompileMode>incremental</recompileMode>
                <javacArgs>
                    <javacArg>-Xlint:unchecked</javacArg>
                    <javacArg>-Xlint:deprecation</javacArg>
                    <javacArg>-encoding</javacArg>
                    <javacArg>${compiler.encoding}</javacArg>
                </javacArgs>
            </configuration>
            <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.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <executions>
                <execution>
                    <phase>compile</phase>
                    <goals>
                        <goal>compile</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>

    </plugins>

之后,将您的Scala代码放在src/main/scala文件夹中,并在src/test/scala中进行测试,您应该没问题。

我认为当前的插件版本是3.2.1。这是指向official documentation的链接。