我想找出 all Maven 属性的值,因为它们适用于某些 Maven 项目。
mvn help:system
列出操作系统环境变量和 JVM 系统属性,但没有 Maven 属性。mvn help:evaluate
仅在交互模式下工作,这意味着我必须键入单个 Maven 属性(例如 ${project.build.outputDirectory}
)才能获取该属性的值。
我正在寻找一种方法来获取所有 Maven 属性及其值的完整列表。
作为解决方法,请将其添加到项目的
<plugins> ... </plugins>
内的 pom.xml
部分:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.7</version>
<executions>
<execution>
<phase>validate</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<tasks>
<echoproperties />
</tasks>
</configuration>
</execution>
</executions>
</plugin>
现在执行
mvn validate
。[echoproperties]
为前缀,将显示系统属性的完整列表,包括 Maven 设置的属性,例如 project.build.outputDirectory
、basedir
和 settings.localRepository
。
maven-help-plugin 可以做你想要的事情,只需用
-Dexpression=project.properties
调用它,这将打印有效 pom 的属性标签。
mvn help:evaluate -Dexpression=project.properties
当您只想要属性输出而不是 Maven 输出时,有奖励点
mvn help:evaluate -Dexpression=project.properties -q -DforceStdout
或使用显式版本,因为
-DforceStdout
自 3.1.0 版本开始工作
mvn org.apache.maven.plugins:maven-help-plugin:3.1.0:evaluate -Dexpression=project.properties -q -DforceStdout
不确定是否有帮助,但我在尝试做同样的事情时发现了这一点:
mvn com.github.ekryd.echo-maven-plugin:echo-maven-plugin:echo -Decho.message='${project.build.testOutputDirectory}'
从这里。
将以下内容添加到
${user.home}/.m2/settings.xml
:
<pluginGroups>
<pluginGroup>com.github.ekryd.echo-maven-plugin</pluginGroup>
</pluginGroups>
该命令可以缩短为:
mvn echo:echo -Decho.message='${project.build.testOutputDirectory}'
我不知道如何“正式”获得它们,但这里有一个解决方法。将
maven-antrun-plugin
添加到您的项目并运行 mvn test -X
。该插件将显示从 Maven 传递给它的所有属性。在我看来,这份清单很完整。
实际上project.build.outputDirectory在那里,但你需要在“编译”阶段执行,而不是在“验证”阶段执行。我想可用的属性还取决于特定插件执行目标的当前阶段,在本例中为“maven-antrun-plugin”。
<!-- Ant Run Plugin for debugging pom.xml and calling ant tasks -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>${ant.plugin.version}</version>
<executions>
<execution>
<phase>compile</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<tasks>
<echoproperties/>
</tasks>
</configuration>
</execution>
</executions>
</plugin>
下面列出了真正所有属性,不仅是
pom.xml
中定义的属性,还包括其他插件以编程方式定义的属性:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>3.4.0</version>
<executions>
<execution>
<id>list-properties</id>
<!-- Binds to the "validate" phase by default. -->
<goals>
<goal>bsh-property</goal>
</goals>
<configuration>
<source>
for (Map.Entry entry : project.getProperties().entrySet()) {
log.info(entry.getKey() + " = " + entry.getValue());
}
</source>
</configuration>
</execution>
</executions>
</plugin>
有同样的问题。通过 maven 更改了 findbugs 配置中的超时和 maxheap。
下面为我解决了这个问题:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>findbugs-maven-plugin</artifactId>
<version>3.0.2</version>
<configuration>
<maxHeap>2048</maxHeap>
<timeout>1800000</timeout>
</configuration>
</plugin>