【问题标题】:Compile scala classes with debug info through Maven通过 Maven 使用调试信息编译 scala 类
【发布时间】:2009-12-14 14:51:54
【问题描述】:
我有一个使用 Maven 和 maven-scala-plugin 编译的 scala 项目。我需要在编译的类中包含调试信息,我想知道有没有办法让 Maven 或 scala 插件来做到这一点。我发现 this page 听起来很可能,但不清楚将参数放在 pom.xml 中的哪个位置。
如果可能的话,我希望这个选项在 pom.xml 中而不是在命令行中指定。
【问题讨论】:
标签:
maven-2
scala
debugging
maven-plugin
【解决方案1】:
编译带有调试信息的.class 文件需要在maven-scala-plugin 级别完成。在maven-compiler-plugin 处执行此操作 - 这是我们在debug 选项的文档中看到的默认设置,默认为 true - 是无用的,因为它没有编译您的 Scala 源代码。
现在,如果我们查看 scalac man page,scalac 编译器有一个 –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 等),因为这不是您想要的 :)