使用maven中的参数执行多个目标

问题描述 投票:2回答:1

我正在尝试在maven中执行多个目标

我有我的Pom.xml

<plugins>
    <plugin>
        <groupId>com.lazerycode.jmeter</groupId>
        <artifactId>jmeter-maven-plugin</artifactId>
        <version>1.4.1</version>
        <executions>
            <execution>
                <id>jmeter-tests</id>
                <phase>verify</phase>
                <goals>
                    <goal>jmeter</goal>
                </goals>
                <configuration>
                    <testFilesIncluded>
                        <jMeterTestFile>${mytest}</jMeterTestFile>                       
                    </testFilesIncluded>
                    <propertiesUser>                
                        <hostName>${myhost}</hostName> 
                        <port>${myport}</port> 
                        <protocol>${myprotocol}</protocol>              
                    </propertiesUser>
                </configuration>                        
            </execution>
        </executions>
    </plugin>

    <plugin>
        <groupId>de.codecentric</groupId>
        <artifactId>jmeter-graph-maven-plugin</artifactId>
        <version>0.1.0</version>
        <executions>
            <execution>
                <id>create-graphs</id>
                <goals>
                    <goal>create-graph</goal>
                </goals>
                <phase>verify</phase>         
            </execution>
        </executions>       
    </plugin>

    <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>exec-maven-plugin</artifactId>
        <version>1.4.0</version>
        <executions>
            <execution>
                <id>runcommand</id>
                <goals>
                    <goal>exec</goal>
                </goals>
            </execution>
        </executions>   
        <configuration>
            <executable>mvn</executable>
            <arguments>
                <argument>**com.lazerycode.jmeter:jmeter-maven-plugin:1.4.1:jmeter@jmeter-tests -Dmyhost=hix.qa.com -Dmyport=80 -Dmyprotocol=http -Dmythreads=5 -Dmyloopcount=20 -Dmyrampup=1 -Dmytest=ScreenerAPI.jmx**</argument>
                <argument>de.codecentric:jmeter-graph-maven-plugin:0.1.0:create-graph@create-graphs</argument>        
            </arguments>
        </configuration>
    </plugin>     
</plugins>

我在org.codehaus插件中提到了两个参数。

使用argument1 disabled运行以下命令可以正常工作。

mvn org.codehaus.mojo:exec-maven-plugin:1.4.0:exec@runcommand 

但是当我用两个命令运行命令时,启用了参数会给我一个错误

未能执行目标com.lazerycode.jmeter:jmeter-maven-plugin:1.4.1:jmeter @ jmeter-tests -Dmyhost = hix.qa.com -Dmyport = 80 -Dmyprotocol = http -Dmythreads = 5 -Dmyloopcount = 20 - Dmyrampup = 1 -Dmytest = ScreenerAPI.jmx

使用cmd行中的参数单独运行目标1和目标2可以正常工作。

mvn de.codecentric:jmeter-graph-maven-plugin:0.1.0:create-graph@create-graphs 
mvn com.lazerycode.jmeter:jmeter-maven-plugin:1.4.1:jmeter@jmeter-tests "-Dmyhost=hix.qa.com" "-Dmyport=80" "-Dmyprotocol=http" "-Dmythreads=5" "-Dmyloopcount=20" "-Dmyrampup=1" "-Dmytest=ScreenerAPI.jmx"

如何在运行多个目标时从命令行将参数传递给一个目标?

maven parameters jmeter jmeter-maven-plugin
1个回答
3
投票

您想要执行多个命令,因此您希望拥有多个插件的executions

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>exec-maven-plugin</artifactId>
    <version>1.4.0</version>
    <executions>
        <!-- First execution executing jmeter-maven-plugin -->
        <execution>
            <id>runcommand1</id>
            <goals>
                <goal>exec</goal>
            </goals>
            <phase> <!-- you need to write a phase here --> </phase>
            <configuration>
                <arguments>
                    <argument>com.lazerycode.jmeter:jmeter-maven-plugin:1.4.1:jmeter@jmeter-tests -Dmyhost=hix.qa.com -Dmyport=80 -Dmyprotocol=http -Dmythreads=5 -Dmyloopcount=20 -Dmyrampup=1 -Dmytest=ScreenerAPI.jmx</argument>
                </arguments>
            </configuration>
        </execution>
        <!-- Second execution executing jmeter-graph-maven-plugin -->
        <execution>
            <id>runcommand2</id>
            <goals>
                <goal>exec</goal>
            </goals>
            <phase> <!-- you need to write a phase here --> </phase>
            <configuration>
                <arguments>
                    <argument>de.codecentric:jmeter-graph-maven-plugin:0.1.0:create-graph@create-graphs</argument>
                </arguments>
            </configuration>
        </execution>
    </executions>
    <configuration>
        <executable>mvn</executable>
    </configuration>
</plugin>

这个配置做了很多事情:

  • 它为您要调用的2个命令配置2个执行。它们都配置了正确的<argument>属性。
  • 它将全局配置元素中这两者的通用配置分解出来。在这种情况下,这只是可执行文件。

但是有一个重要的因素:如果你想在一个构建中执行这两个执行,那么这些执行需要绑定到一个阶段。例如,如果将它们绑定到verify,则调用mvn verify将调用两次执行。

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