使用Maven创建最基本的Scala项目?

问题描述 投票:11回答:1

我使用Maven 3创建一个新的Scala项目。据我所知,使用Maven创建新项目的方法是:

mvn archetype:generate

也许我错过了一些东西,但我找不到一个提供最简单的Scala项目的选项(例如lein new app ...为Clojure收到的那个)。这里有什么帮助?

scala maven clojure maven-3
1个回答
15
投票

你应该能够使用mvn archetype:generate。你可以选择,例如,org.scala-tools.archetypes:scala-archetype-simple。您需要在mvn archetype:generate命令的输出中输入原型名称旁边的数字编号,因为编号可能会随时间而变化。还有其他选项,如eu.stratosphere:quickstart-scala记录的this article

但是,它们可能有点过时了。我个人更喜欢手动编写我的pom.xml文件。作为参考,这里是一个用于Scala 2.11.6和Scalatest 2.2.5的最小pom文件:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.example</groupId>
  <artifactId>my-artifact</artifactId>
  <version>1.0-SNAPSHOT</version>

  <properties>
    <encoding>UTF-8</encoding>
    <scala.version>2.11.6</scala.version>
  </properties>

  <dependencies>
    <dependency>
      <groupId>org.scala-lang</groupId>
      <artifactId>scala-library</artifactId>
      <version>${scala.version}</version>
    </dependency>

    <dependency>
      <groupId>org.scalatest</groupId>
      <artifactId>scalatest_2.11</artifactId>
      <version>2.2.5</version>
      <scope>compile</scope>
    </dependency>
  </dependencies>

  <build>
    <plugins>
      <plugin>
        <groupId>org.scala-tools</groupId>
        <artifactId>maven-scala-plugin</artifactId>
        <version>2.15.2</version>
        <executions>
          <execution>
            <goals>
              <goal>compile</goal>
              <goal>testCompile</goal>
            </goals>
          </execution>
        </executions>
      </plugin>

      <plugin>
        <groupId>org.scalatest</groupId>
        <artifactId>scalatest-maven-plugin</artifactId>
        <version>1.0</version>
        <configuration>
        </configuration>
        <executions>
          <execution>
            <id>test</id>
            <goals>
              <goal>test</goal>
            </goals>
          </execution>
        </executions>
      </plugin>

    </plugins>

  </build>
</project>
© www.soinside.com 2019 - 2024. All rights reserved.