首页 > 解决方案 > Maven surefire-report 不在存储库中生成报告

问题描述

当我运行mvn surefire-report:report它时,它应该生成一个 HTML 到 repo/target/site/surefire-report.html,虽然它在本地测试时这样做,但它不会将它添加到我们的 GitHub 存储库中。我们的仓库目前没有 /target 目录。
这是我们的 pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.com.csapat</groupId>
    <artifactId>Izsakazsivany</artifactId>
    <version>1.0-SNAPSHOT</version>
    <properties>
        <maven.compiler.source>15</maven.compiler.source>
        <maven.compiler.target>15</maven.compiler.target>
    </properties>
    <dependencies>
        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter</artifactId>
            <version>5.7.0</version>
            <scope>test</scope>
        </dependency>
    </dependencies>
    <reporting>
         <plugins>
             <plugin>
                 <groupId>org.apache.maven.plugins</groupId>
                 <artifactId>maven-surefire-report-plugin</artifactId>
                 <version>3.0.0-M5</version>
             </plugin>
         </plugins>
    </reporting>
    <build>
        <testSourceDirectory>src/main/test/java/com/csapat</testSourceDirectory>
        <finalName>izsakazsivany</finalName>
        <plugins>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.22.0</version>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.8.1</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

这是 maven.yml

name: Java CI with Maven

on:
  push:
    branches: [ main ]
  pull_request:
    branches: [ main ]

jobs:
  build:

    runs-on: ubuntu-latest

    steps:
    - uses: actions/checkout@v2
    - name: Set up JDK 1.8
      uses: actions/setup-java@v1
      with:
        java-version: 1.8
    - name: Build with Maven
      run: mvn clean install
    - name: Test
      run: mvn test
    - name: Report
      run: mvn surefire-report:report

实现这一目标缺少什么?在存储库中运行时,我是否需要指定生成位置?如果是这样,那应该在 .xml 还是 .yml 中?很抱歉,如果这个问题的答案很明显,但我发现浏览 apache 的文档站点非常困难。

标签: javamavenmaven-surefire-plugin

解决方案


要更改生成的输出报告以及其他项目报告的位置,应将 maven-site-plugin 和 maven-surefire-report-plugin 的 outputDirectory 属性设置为所需的替代位置。

  <project>
  [...]
  <reporting>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-report-plugin</artifactId>
        <version>3.0.0-M5</version>
        <configuration>
          <outputDirectory>${basedir}/target/newsite</outputDirectory>
        </configuration>
      </plugin>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-site-plugin</artifactId>
        <version>2.1</version>
        <configuration>
          <outputDirectory>${basedir}/target/newsite</outputDirectory>
        </configuration>
      </plugin>
    </plugins>
  </reporting>
  [...]
</project>

要使用独立目标更改生成的输出报告的位置,应将 outputDirectory 属性设置为新路径:

mvn surefire-report:report -DoutputDirectory=newpath

推荐阅读