为每个报告插件调用的 Maven "process-classes" 阶段(多次执行)
Maven "process-classes" phase called for each reporting plugin (multiple executions)
我有一个 Maven 工件,其中包含在编译时计算的数据
这是通过使用exec-maven-plugin
调用生成class实现的。
这在构建工件时被正确执行,但是当添加报告插件时,执行发生多次,显着减慢速度。
采取以下pom.xml
:
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.me</groupId>
<artifactId>test</artifactId>
<version>0.0.1-SNAPSHOT</version>
<properties>
<main.class>test.Runner</main.class>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>${maven.compiler.source}</maven.compiler.target>
</properties>
<reporting>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-report-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-report-plugin</artifactId>
</plugin>
</plugins>
</reporting>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<executions>
<execution>
<phase>process-classes</phase>
<id>${main.class}</id>
<goals>
<goal>java</goal>
</goals>
<configuration>
<mainClass>${main.class}</mainClass>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-site-plugin</artifactId>
<version>3.9.1</version>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
当 clean install site
为 运行 时,test.Runner 被调用三次 - 每次添加报告插件时,都会再次调用 运行。
尝试将报告配置更改为:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-report-plugin</artifactId>
<version>${maven.surefire.plugin.version}</version>
<reportSets>
<reportSet>
<reports>
<report>report-only</report>
</reports>
</reportSet>
</reportSets>
</plugin>
这告诉 Maven 哪些报告应该是 运行。如果没有 reportSet
配置,
every reporting goal available in the plugin is rendered once
根据 Maven Site plugin docs. This is important because as @khmarbaise notes, the report mojo
Invokes the execution of the lifecycle phase test prior to executing itself.
我有一个 Maven 工件,其中包含在编译时计算的数据
这是通过使用exec-maven-plugin
调用生成class实现的。
这在构建工件时被正确执行,但是当添加报告插件时,执行发生多次,显着减慢速度。
采取以下pom.xml
:
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.me</groupId>
<artifactId>test</artifactId>
<version>0.0.1-SNAPSHOT</version>
<properties>
<main.class>test.Runner</main.class>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>${maven.compiler.source}</maven.compiler.target>
</properties>
<reporting>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-report-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-report-plugin</artifactId>
</plugin>
</plugins>
</reporting>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<executions>
<execution>
<phase>process-classes</phase>
<id>${main.class}</id>
<goals>
<goal>java</goal>
</goals>
<configuration>
<mainClass>${main.class}</mainClass>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-site-plugin</artifactId>
<version>3.9.1</version>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
当 clean install site
为 运行 时,test.Runner 被调用三次 - 每次添加报告插件时,都会再次调用 运行。
尝试将报告配置更改为:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-report-plugin</artifactId>
<version>${maven.surefire.plugin.version}</version>
<reportSets>
<reportSet>
<reports>
<report>report-only</report>
</reports>
</reportSet>
</reportSets>
</plugin>
这告诉 Maven 哪些报告应该是 运行。如果没有 reportSet
配置,
every reporting goal available in the plugin is rendered once
根据 Maven Site plugin docs. This is important because as @khmarbaise notes, the report mojo
Invokes the execution of the lifecycle phase test prior to executing itself.