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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/37047186/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-22 08:16:29  来源:igfitidea点击:

Creating the most basic Scala project with Maven?

scalamavenclojuremaven-3

提问by shakedzy

I use Maven 3 to create a new Scala project. As far as I understand, the way to create a new project with Maven is by:

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

mvn archetype:generate

Maybe I'm missing out something, but I couldn't find even one option that offers the simplest Scala project (like the one received by lein new app ...for Clojure, for example). Any help here?

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

回答by Mifeet

You should be able to use mvn archetype:generate. You can choose, e.g., org.scala-tools.archetypes:scala-archetype-simple. You need to put in the number number next to the archetype name in the output of your mvn archetype:generatecommandbecause the numbering can change over time. There are also other options like eu.stratosphere:quickstart-scalaas documented in this article.

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

They may be somewhat outdated, though. I personally prefer writing my pom.xmlfiles manually. For reference, here is a minimal pom file for use with Scala 2.11.6 and Scalatest 2.2.5:

不过,它们可能有些过时。我个人更喜欢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>