简体   繁体   English

如何运行maven-antrun-plugin目标?

[英]how to run maven-antrun-plugin targets?

I don't want to mess up with maven failsafe plugin. 我不想弄乱Maven故障安全插件。 Also I wanted something to copy properties files for me not interested in entire lifecycle. 另外,我还需要一些对整个生命周期不感兴趣的属性文件。 So, now I am using two plugins maven-failsafe-plugin to run regular clean, verify tasks and maven-antrun-plugin only and only to copy properties file before maven-failsafe-plugin starts. 因此,现在我使用两个插件maven-failsafe-plugin运行常规clean, verify任务和maven-antrun-plugin并且仅在启动maven-failsafe-plugin之前复制属性文件。
Below POM works fine if you remove profiles, ie if I don't have profiles under maven-antrun-plugin then it copies properties files using below command mvn clean test verify -Dwebdriver.driver=chrome -Dcucumber.options="--tags @sanity" -e 如果删除配置文件,则在POM下方工作正常,即,如果我在maven-antrun-plugin下没有profiles文件,则使用以下命令mvn clean test verify -Dwebdriver.driver=chrome -Dcucumber.options="--tags @sanity" -e

But if I create profiles then it doesn't copy 但是,如果我创建配置文件,则不会复制

mvn clean test -Pqa verify -Dwebdriver.driver=chrome -Dcucumber.options="--tags @sanity" -e

How can I make profiles work here? 如何在这里使用个人资料? Am I executing wrong command? 我执行错误的命令吗?

<?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.demo.automation</groupId>
    <artifactId>serenity-automation-tests</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>jar</packaging>

    <name>Serenity Cucumber and WebDriver</name>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <serenity.version>2.0.18</serenity.version>
        <serenity.cucumber.version>1.6.6</serenity.cucumber.version>
        <webdriver.driver>firefox</webdriver.driver>
    </properties>
    <repositories>
        <repository>
            <snapshots>
                <enabled>false</enabled>
            </snapshots>
            <id>central</id>
            <name>bintray</name>
            <url>http://jcenter.bintray.com</url>
        </repository>
    </repositories>
    <pluginRepositories>
        <pluginRepository>
            <snapshots>
                <enabled>false</enabled>
            </snapshots>
            <id>central</id>
            <name>bintray-plugins</name>
            <url>http://jcenter.bintray.com</url>
        </pluginRepository>
    </pluginRepositories>

    <dependencies>
        <dependency>
            <groupId>net.serenity-bdd</groupId>
            <artifactId>serenity-core</artifactId>
            <version>${serenity.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>net.serenity-bdd</groupId>
            <artifactId>serenity-cucumber</artifactId>
            <version>${serenity.cucumber.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-simple</artifactId>
            <version>1.7.7</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.12</version>
            <scope>test</scope>
        </dependency>
    </dependencies>
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.22.1</version>
                <configuration>
                    <skip>true</skip>
                </configuration>
            </plugin>
            <plugin>
                <artifactId>maven-antrun-plugin</artifactId>
                <version>1.8</version>
                <executions>
                    <execution>
                        <phase>test</phase>
                        <goals>
                            <goal>run</goal>
                        </goals>
                        <configuration>
                            <profiles>
                                <profile>
                                    <id>qa</id>
                                    <target>
                                        <delete>
                                            <fileset dir="${project.build.outputDirectory}"
                                                includes="*.properties" />
                                        </delete>
                                        <echo>Using env.test.properties</echo>
                                        <copy file="src/main/resources/qa.properties"
                                            tofile="${project.build.outputDirectory}/env.properties" />
                                    </target>
                                </profile>
                                <profile>
                                    <id>stage</id>
                                    <target>
                                        <delete>
                                            <fileset dir="${project.build.outputDirectory}"
                                                includes="*.properties" />
                                        </delete>
                                        <echo>Using env.test.properties</echo>
                                        <copy file="src/main/resources/stage.properties"
                                            tofile="${project.build.outputDirectory}/env.properties" />
                                    </target>
                                </profile>
                                <profile>
                                    <id>prod</id>
                                    <target>
                                        <delete>
                                            <fileset dir="${project.build.outputDirectory}"
                                                includes="*.properties" />
                                        </delete>
                                        <echo>Using env.test.properties</echo>
                                        <copy file="src/main/resources/prod.properties"
                                            tofile="${project.build.outputDirectory}/env.properties" />
                                    </target>
                                </profile>
                            </profiles>
                        </configuration>
                        <!-- <goals> <goal>run</goal> </goals> -->
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <artifactId>maven-failsafe-plugin</artifactId>
                <version>2.19.1</version>
                <configuration>
                    <includes>
                        <include>**/*.java</include>
                    </includes>
                    <argLine>-Xmx512m</argLine>
                    <systemPropertyVariables>
                        <webdriver.driver>${webdriver.driver}</webdriver.driver>
                    </systemPropertyVariables>
                </configuration>
                <executions>
                    <execution>
                        <goals>
                            <goal>integration-test</goal>
                            <goal>verify</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.2</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
            </plugin>
            <plugin>
                <groupId>net.serenity-bdd.maven.plugins</groupId>
                <artifactId>serenity-maven-plugin</artifactId>
                <version>${serenity.version}</version>
                <executions>
                    <execution>
                        <id>serenity-reports</id>
                        <phase>post-integration-test</phase>
                        <goals>
                            <goal>aggregate</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>

You're defining your profiles in the wrong place. 您在错误的位置定义了个人资料。 The correct place is directly under project: 正确的位置直接在项目下:

<project>
    ...
    <profiles>

and then the plugin-configuration for that profile: 然后是该配置文件的插件配置:

<project>
    ...
    <profiles>
    ...
      <build>
          <plugins>
             ....

That means you'll have to define the plugins mutliple times (per profile). 这意味着您必须定义插件的多重时间(每个配置文件)。 The profile-information in configuration has to be removed. 配置中的配置文件信息必须删除。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用Maven-antrun-plugin运行IntelliJ调试器 - Running IntelliJ debugger with maven-antrun-plugin 指定代理以使用Maven-antrun-plugin与Maven签名罐子 - Specifiying proxy to sign jars with maven with maven-antrun-plugin maven3 - maven-antrun-plugin - “无法创建任务或输入if” - maven3 - maven-antrun-plugin - “failed to create task or type if” Maven-antrun-plugin出现“生命周期配置未涵盖插件执行”错误 - “Plugin execution not covered by lifecycle configuration” error with maven-antrun-plugin 使用 antcontrib<if> 通过 maven-antrun-plugin 的任务 - Using antcontrib <if> task via maven-antrun-plugin 从maven-antrun-plugin调用ant脚本时出现IllegalAccessError - IllegalAccessError when calling ant script from maven-antrun-plugin 优雅地停止maven-antrun-plugin启动的java进程 - Gracefully stopping a java process started by maven-antrun-plugin 在 pom.xml 中找不到 maven-antrun-plugin - In pom.xml maven-antrun-plugin not found 用于用maven-antrun-plugin替换exec-maven-plugin的脚本 - script used for replacing exec-maven-plugin with maven-antrun-plugin 使用maven-antrun-plugin的Maven Ant BuildException ...无法找到javac编译器 - Maven Ant BuildException with maven-antrun-plugin … unable to find javac compiler
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM