gpt4 book ai didi

maven - 在 Maven 构建中使用依赖项命令行参数

转载 作者:行者123 更新时间:2023-12-02 00:44:52 24 4
gpt4 key购买 nike

我在 Maven 生命周期的验证阶段使用 findbugs-maven-plugin。即它在 mvn clean install 上运行。这是我在父 pom.xml 中的代码(在多模块项目中)。

 <plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>findbugs-maven-plugin</artifactId>
<version>3.0.0</version>
<executions>
<execution>
<id>findbugs</id>
<phase>verify</phase>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
<configuration>
<findbugsXmlOutputDirectory>target/findbugs</findbugsXmlOutputDirectory>
<failOnError>false</failOnError>
</configuration>
</plugin>

<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>xml-maven-plugin</artifactId>
<version>1.0</version>
<executions>
<execution>
<phase>verify</phase>
<goals>
<goal>transform</goal>
</goals>
</execution>
</executions>
<configuration>
<transformationSets>
<transformationSet>
<dir>target/findbugs</dir>
<outputDir>target/findbugs</outputDir>
<stylesheet>plain.xsl</stylesheet>
<fileMappers>
<fileMapper implementation="org.codehaus.plexus.components.io.filemappers.FileExtensionMapper">
<targetExtension>.html</targetExtension>
</fileMapper>
</fileMappers>
</transformationSet>
</transformationSets>
</configuration>
<dependencies>
<dependency>
<groupId>com.google.code.findbugs</groupId>
<artifactId>findbugs</artifactId>
<version>2.0.0</version>
</dependency>
</dependencies>
</plugin>

这工作正常,并且在每个模块目标中生成 html 文件。不过,我想更进一步,能够在 Maven 构建期间使用 findbugs 允许的参数(例如 onlyAnalyze)。我不想在 pom.xml 中添加配置。

我希望构建过程保持不变,除非我通过某些命令指定我只想分析一个类,例如通过运行:

mvn clean install -Dfindbugs:onlyAnalyze=MyClass

你知道我可以做到这一点的方法吗?

最佳答案

这是调用独立目标的方法:plugin-prefix:goalgroupId:artifactId:version:goal 以确保版本正确。在您的情况下: findbugs:findbugs

使用-Dkey=value,您可以设置插件参数如果它们是公开的。 http://mojo.codehaus.org/findbugs-maven-plugin/findbugs-mojo.html不显示该选项。只是为了比较:http://mojo.codehaus.org/findbugs-maven-plugin/help-mojo.html确实有这样的选择。这里它仍然被称为带有 ${key}Expression,现在它生成为仅带有 keyUser property

如果您希望从命令行设置 onlyAnalyze,请要求 mojo 团队修复该问题,或执行以下操作:

<project>
<properties>
<findbugs.onlyAnalyze>false</findbugs.onlyAnalyze> <!-- default value -->
</properties>

<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>findbugs-maven-plugin</artifactId>
<version>3.0.0</version>
</plugin>
<configuration>
<onlyAnalyze>${findbugs.onlyAnalyze}</onlyAnalyze>
</configuration>
</plugins>
</build>
</project>

现在您可以调用mvn findbugs:findbugs -Dfindbugs.onlyAnalyze=true

关于maven - 在 Maven 构建中使用依赖项命令行参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25430162/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com