运行2主要通过exec-maven-plugin与2个profils

时间:2016-12-06 15:01:40

标签: maven profile

我想通过exec-maven-plugin运行2个主要的2个配置文件。在我的制作中,我只使用“prod”配置文件,在我的连续集成中,我想使用“preProd”配置文件和“prod”配置文件。

in prod

  

mvn -Pprod

在连续整合中:

  

mvn -PpreProd,prod

<profiles>
    <profile>
        <id>preProd</id>
        <build>
            <plugins>
                <plugin>
                    <groupId>org.codehaus.mojo</groupId>
                    <artifactId>exec-maven-plugin</artifactId>
                    <version>1.5.0</version>
                        <executions>
                            <execution>
                                <id>CountContinusIntegr-execution</id>
                                <phase>compile</phase>
                                <goals>
                                    <goal>java</goal>
                                </goals>
                            </execution>
                        </executions>
                        <configuration>
                            <mainClass>com.mycompany.CountContinusIntegr</mainClass>
                        </configuration>
                </plugin>
            </plugins>
        </build>
    </profile>
    <profile>
        <id>prod</id>
        <build>
            <plugins>
                <plugin>
                    <groupId>org.codehaus.mojo</groupId>
                    <artifactId>exec-maven-plugin</artifactId>
                    <version>1.5.0</version>
                        <executions>
                            <execution>
                                <id>RunMyProd-execution</id>
                                <phase>compile</phase>
                                <goals>
                                    <goal>java</goal>
                                </goals>
                            </execution>
                        </executions>
                        <configuration>
                            <mainClass>com.mycompany.RunMyProd</mainClass>
                        </configuration>
                </plugin>
            </plugins>
        </build>
    </profile>
</profiles>

当我运行maven命令时,我有这个日志(com.mycompany.RunMyProd.main()运行2次):

[INFO] --- exec-maven-plugin:1.5.0:java(CountContinusIntegr-execution)@ myproject --- [2016-12-06 15:44:44]:读取文件scenario.properties 0 [ com.mycompany.RunMyProd .main()] INFO .... [INFO] --- exec-maven-plugin:1.5.0:java(RunMyProd-execution)@ myproject --- [2016-12-06 15:44:45]:读取文件scenario.properties 0 [ com.mycompany.RunMyProd .main()] INFO ....

1 个答案:

答案 0 :(得分:1)

我找到了解决方案: I put <configuration> in <execution>

<profiles>
    <profile>
        <id>preProd</id>
        <build>
            <plugins>
                <plugin>
                    <groupId>org.codehaus.mojo</groupId>
                    <artifactId>exec-maven-plugin</artifactId>
                    <version>1.5.0</version>
                        <executions>
                            <execution>
                                <id>CountContinusIntegr-execution</id>
                                <phase>compile</phase>
                                <goals>
                                    <goal>java</goal>
                                </goals>
                                <configuration>
                                    <mainClass>com.mycompany.CountContinusIntegr</mainClass>
                                </configuration>
                            </execution>
                        </executions>
                </plugin>
            </plugins>
        </build>
    </profile>
    <profile>
        <id>prod</id>
        <build>
            <plugins>
                <plugin>
                    <groupId>org.codehaus.mojo</groupId>
                    <artifactId>exec-maven-plugin</artifactId>
                    <version>1.5.0</version>
                        <executions>
                            <execution>
                                <id>RunMyProd-execution</id>
                                <phase>compile</phase>
                                <goals>
                                    <goal>java</goal>
                                </goals>
                                <configuration>
                                    <mainClass>com.mycompany.RunMyProd</mainClass>
                                </configuration>
                            </execution>
                        </executions>
                </plugin>
            </plugins>
        </build>
    </profile>
</profiles>