首页 > 解决方案 > 无法使用 jmeter maven 插件运行 jmeter

问题描述

我正在尝试使用 maven POM.xml 运行我的 jmx 文件,该文件是 src/test/jmeter,但出现错误

我在 pom.xml 中提供了 5.1.1 版本,仍然说这个插件需要 5.1.1 版本的 jmeter。

这个插件会自动下载 jmeter 吗?还是我必须手动下载并保存在 src/test/jmeter 文件夹中?

下面使用的版本:

<dependency>
    <groupId>com.lazerycode.jmeter</groupId>
    <artifactId>jmeter-maven-plugin</artifactId>
    <version>2.9.0</version>
</dependency>

尝试更改 jmeter maven 插件的版本,仍然出现同样的错误

这是我在 maven 代码下运行时出现的错误: mvn clean install -DskipTests -Dskip.report.generation=true -Djmeter.version=5.1.1

[ERROR] Failed to execute goal com.lazerycode.jmeter:jmeter-maven-plugin:2.9.0:jmeter (jmeter-tests) on project WebserviceAutomation: The plugin com.lazerycode.jmeter:jmeter-maven-plugin:2.9.0 requires Maven version 3.5.2

标签: javamavenjmeter

解决方案


根据JMeter Maven 插件文档的当前版本

最新版本是2.9.0,它需要Maven >= 3.5.2并且默认为 Apache JMeter 5.1.1

所以请确保获取Maven 3.5.2最新版本

最小的工作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 http://maven.apache.org/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.example</groupId>
    <artifactId>jmeter-maven</artifactId>
    <packaging>jar</packaging>
    <version>1.0-SNAPSHOT</version>
    <name>maven-jmeter-demo</name>
    <url>http://maven.apache.org</url>
    <build>
        <plugins>
            <plugin>
                <groupId>com.lazerycode.jmeter</groupId>
                <artifactId>jmeter-maven-plugin</artifactId>
                <version>2.9.0</version>
                <executions>
                    <!-- Generate JMeter configuration -->
                    <execution>
                        <id>configuration</id>
                        <goals>
                            <goal>configure</goal>
                        </goals>
                    </execution>
                    <!-- Run JMeter tests -->
                    <execution>
                        <id>jmeter-tests</id>
                        <goals>
                            <goal>jmeter</goal>
                        </goals>
                    </execution>
                    <!-- Fail build on errors in test -->
                    <execution>
                        <id>jmeter-check-results</id>
                        <goals>
                            <goal>results</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>

只需创建src/test/jmeter文件夹并将您的 JMX 脚本放在那里,一旦完成,您应该能够使用mvn verify命令启动测试

更多信息:不使用 JMeter GUI 启动 JMeter 测试的五种方法


推荐阅读