【问题标题】:Creating the most basic Scala project with Maven?用 Maven 创建最基本的 Scala 项目?
【发布时间】:2016-08-31 00:57:36
【问题描述】:

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

mvn archetype:generate

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

【问题讨论】:

标签: scala maven clojure maven-3


【解决方案1】:

您应该可以使用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>

【讨论】:

    【解决方案2】:

    主要的 Scala 原型在最知名的地址下看起来已停产。 这个原型看起来好多了:

    https://github.com/davidB/scala-archetype-simple

    暂时使用它:

    mvn archetype:generate -DarchetypeGroupId=net.alchim31.maven -DarchetypeArtifactId=scala-archetype-simple
    

    【讨论】:

    • 不幸的是,这个原型自 2018 年 11 月以来也没有更新过 :(
    猜你喜欢
    • 1970-01-01
    • 2014-04-12
    • 2012-09-12
    • 2018-11-24
    • 2013-05-15
    • 2020-01-14
    • 2017-06-16
    • 2011-09-26
    • 1970-01-01
    相关资源
    最近更新 更多