【问题标题】:Maven surefire-report not generating report in repositoryMaven surefire-report 不在存储库中生成报告
【发布时间】:2021-04-02 17:19:21
【问题描述】:

当我运行 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 的文档站点非常困难。

【问题讨论】:

    标签: java maven maven-surefire-plugin


    【解决方案1】:

    要更改生成的输出报告以及其他项目报告的位置,应将 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
    

    【讨论】:

    • 感谢您的回复。我试过这个,但无济于事,我认为有些东西阻止了新文件自动添加到存储库中,我不完全确定。从那以后,我通过使用工件来存储测试结果来解决这个问题,据我所知,它现在就足够了。感谢您的帮助
    猜你喜欢
    • 2017-02-05
    • 1970-01-01
    • 1970-01-01
    • 2023-03-21
    • 1970-01-01
    • 1970-01-01
    • 2019-01-14
    • 1970-01-01
    • 2014-07-02
    相关资源
    最近更新 更多