如何调试Maven插件?

问题描述 投票:0回答:3

我使用 POM 中配置的 allure-maven 插件。然而,当它失败时

ru.yandex.qatools.allure.data.ReportGenerationException: Could not find any allure results

我想在运行时调试插件,看看它是否正确设置了所有变量。

我尝试按照

在 Maven 中调试?
的答案使用 mvnDebug。当 Maven 使用 Surefire 插件执行测试时,我能够将调试器连接到 JVM。但是,当 Maven 尝试使用 allure 插件生成 Allure 报告时,我无法连接调试器。 Allure 插件在 POM 的“报告”部分中定义,并由“站点”Maven 目标使用。

这是我用

mvn clean test site
命令调用的 POM(几乎完成,我省略了依赖部分)。

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xmlns="http://maven.apache.org/POM/4.0.0"
             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>

    ...  

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.20</version>
                <configuration>
                    <testFailureIgnore>true</testFailureIgnore>
                    <argLine>-Xmx2048m -XX:-UseSplitVerifier -XX:MaxPermSize=256m
                        -javaagent:${settings.localRepository}/org/aspectj/aspectjweaver/${aspectj.version}/aspectjweaver-${aspectj.version}.jar
                    </argLine>
                    <properties>
                        <property>
                            <name>parallel</name>
                            <value>classes</value>
                        </property>
                        <property>
                            <name>threadcount</name>
                            <value>4</value>
                        </property>
                    </properties>
                </configuration>
                <dependencies>
                    <dependency>
                        <groupId>org.aspectj</groupId>
                        <artifactId>aspectjweaver</artifactId>
                        <version>${aspectj.version}</version>
                    </dependency>
                </dependencies>
            </plugin>
        </plugins>
    </build>


    <reporting>
        <excludeDefaults>true</excludeDefaults>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-report-plugin</artifactId>
                <version>2.19.1</version>
            </plugin>
            <plugin>
                <groupId>io.qameta.allure</groupId>
                <artifactId>allure-maven</artifactId>
                <version>2.8</version>
                <configuration>
                </configuration>
            </plugin>
        </plugins>
    </reporting>

    <pluginRepositories>
        <pluginRepository>
            <id>mvn-nexus-all</id>
            <url>https://lunabuild.akamai.com/nexus/content/groups/public/</url>
            <snapshots>
                <enabled>false</enabled>
            </snapshots>
        </pluginRepository>
    </pluginRepositories>
</project>

这是失败插件的完整堆栈跟踪:

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-site-plugin:3.3:site (default-site) on project sso-config-tests: Error during page generation: Error rendering Maven report: Could not generate the report: InvocationTargetException: Could not find any allure results -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.apache.maven.plugins:maven-site-plugin:3.3:site (default-site) on project sso-config-tests: Error during page generation
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:216)
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
        at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:116)
        at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:80)
        at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:51)
        at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:128)
        at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:307)
        at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:193)
        at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:106)
        at org.apache.maven.cli.MavenCli.execute(MavenCli.java:862)
        at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:286)
        at org.apache.maven.cli.MavenCli.main(MavenCli.java:197)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:497)
        at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289)
        at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)
        at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415)
        at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)
Caused by: org.apache.maven.plugin.MojoExecutionException: Error during page generation
        at org.apache.maven.plugins.site.SiteMojo.execute(SiteMojo.java:143)
        at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:134)
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:208)
        ... 20 more
Caused by: org.apache.maven.doxia.siterenderer.RendererException: Error rendering Maven report: Could not generate the report
        at org.apache.maven.plugins.site.ReportDocumentRenderer.renderDocument(ReportDocumentRenderer.java:233)
        at org.apache.maven.doxia.siterenderer.DefaultSiteRenderer.renderModule(DefaultSiteRenderer.java:319)
        at org.apache.maven.doxia.siterenderer.DefaultSiteRenderer.render(DefaultSiteRenderer.java:135)
        at org.apache.maven.plugins.site.SiteMojo.renderLocale(SiteMojo.java:175)
        at org.apache.maven.plugins.site.SiteMojo.execute(SiteMojo.java:138)
        ... 22 more
Caused by: org.apache.maven.reporting.MavenReportException: Could not generate the report
        at ru.yandex.qatools.allure.report.AllureGenerateMojo.executeReport(AllureGenerateMojo.java:127)
        at org.apache.maven.reporting.AbstractMavenReport.generate(AbstractMavenReport.java:255)
        at org.apache.maven.plugins.site.ReportDocumentRenderer.renderDocument(ReportDocumentRenderer.java:219)
        ... 26 more
Caused by: java.lang.reflect.InvocationTargetException
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:497)
        at ru.yandex.qatools.allure.report.AllureGenerateMojo.executeReport(AllureGenerateMojo.java:123)
        ... 28 more
Caused by: ru.yandex.qatools.allure.data.ReportGenerationException: Could not find any allure results
        at ru.yandex.qatools.allure.data.AllureReportGenerator.generate(AllureReportGenerator.java:58)
        at ru.yandex.qatools.allure.data.AllureReportGenerator.generate(AllureReportGenerator.java:53)
        at ru.yandex.qatools.allure.AllureMain.main(AllureMain.java:48)
        ... 33 more
maven maven-plugin allure
3个回答
22
投票

如果您使用

mvnDebug clean install
而不是
mvn clean install
开始构建,Maven 将等待远程调试器连接到端口
8000
。这应该适用于所有不在自己的 JVM 中运行的插件。

这需要 Maven 大于

2.0.8
,我假设你正在运行。

参见 在 Maven 中调试?


1
投票

如果您想从 Intellij IDEA 调试它。 我假设你运行捆绑的 mvn,JDK9+

  1. 转到 IDEA 中的 Maven Runner 设置。
  2. 在 VM 选项中指定此行:
    -agentlib:jdwp=transport=dt_socket,address=5005,server=y,suspend=y

Maven 在您连接之前不会继续 远程调试器。

  1. 创建远程调试器配置(指定端口 5005)。
  2. 运行远程调试器(不要忘记在代码中添加断点)。

-1
投票

您可能想首先修复配置问题,而不是

allure-maven
插件调试。您已将插件放入错误的 pom 部分。请参阅官方插件的docs

Allure 2 不再使用报告部分。您应该将插件放入 build 部分。

报告生成命令也已更新。您应该使用以下内容,而不是

site
目标召唤:

mvn allure:report
mvn allure:serve

检查 this 示例以了解有效配置。

© www.soinside.com 2019 - 2024. All rights reserved.