如何在不更改 pom.xml 的情况下使用 Maven 在调试模式下进行编译?

How to compile in debug mode using maven without making changes to pom.xml?

我正在尝试 运行 在 spring 启动应用程序上进行一些漏洞扫描(Veracode)。但是,扫描提供程序建议 运行 使用在 pom.xml 文件中使用以下内容在调试模式下编译的二进制文件进行扫描。

<build>
  <plugins>
    <plugin> 
      <artifactId>maven-compiler-plugin</artifactId> 
      <configuration>
        <debug>true</debug>
        <debuglevel>lines,vars,source</debuglevel>
      </configuration>
    </plugin>
  </plugins>
</build>

但是,我们使用相同的 pom.xml 进行生产部署,我们不需要调试级别的 jar。

有没有办法通过将一些参数传递给 mvn 命令来创建调试 jar?

我认为可以在命令行中使用 -D 设置参数,如下所示:

mvn compile -Dmaven.compiler.debug=true -Dmaven.compiler.debuglevel=lines,vars,source

您可以使用配置文件。

<profiles>
  <profile>
    <id>debug</id>
    <build>
      <plugins>
        <plugin> 
          <artifactId>maven-compiler-plugin</artifactId> 
          <configuration>
            <debug>true</debug>
            <debuglevel>lines,vars,source</debuglevel>
          </configuration>
        </plugin>
      </plugins>
    </build>
  </profile>
</profile>

配置文件在 mvn 命令中激活,例如 mvn ... -Pdebug