代码之家  ›  专栏  ›  技术社区  ›  David

通过maven使用调试信息编译scala类

  •  3
  • David  · 技术社区  · 16 年前

    我有一个scala项目,我用maven和 maven-scala-plugin 编译。我需要在编译类中包含调试信息,我想知道有没有一种方法可以让Maven或scala插件这样做。我找到了 this page 这听起来是可能的,但不清楚在pom.xml中把参数放在哪里。

    如果可能的话,我希望这个选项是在pom.xml中指定的,而不是在命令行中指定的。

    1 回复  |  直到 16 年前
        1
  •  9
  •   Pascal Thivent    16 年前

    编译 .class 包含调试信息的文件需要在 maven-scala-plugin 水平。在 maven-compiler-plugin -这是我们在文档中可以看到的默认值。 debug 默认为true的选项是无用的,因为它没有编译您的scala源代码。

    现在,如果我们看看 scalac man page , the 斯卡拉克 编译器有一个 –g 可采用以下值的选项:

    他说:“这是一个很好的选择。” none “不生成调试信息,
    source “只生成源文件属性,
    line “生成源和行号信息,
    vars “生成源、行号和局部变量信息,
    notc “生成以上所有内容,不会执行尾调用优化。

    好消息是 scala:compile 有一个不错的 args 可用于传递的可选参数 编译器附加参数 . 所以,使用它并传递 -g 对于scala编译器的选项,您只需按如下方式配置maven插件:

      <plugin>
        <groupId>org.scala-tools</groupId>
        <artifactId>maven-scala-plugin</artifactId>
        <version>2.9.1</version>
        <executions>
          <execution>
            <goals>
              <goal>compile</goal>
              <goal>testCompile</goal>
            </goals>
          </execution>
        </executions>
        <configuration>
          <args>
            <arg>-g:notc</arg>
          </args>
          ...
        </configuration>
      </plugin>
    

    我跳过了配置的其他部分(例如 repositories , pluginRepositories 等)因为这不是你想要的。)

    推荐文章