如何从现有的简单项目中提取maven多模块项目?

时间:2018-01-05 13:00:56

标签: maven intellij-idea maven-surefire-plugin multi-module

由于项目的增长,我想了解如何将当前的maven项目提取/重构为maven-multimodule项目。 它的Selenium,Java,Maven,Cucumber-JVM自动化项目。

对于并行运行,我们在POM.xml中使用cucumber-jvm-parallel-plugin(后者又依赖于maven-surefire-plugin)。

mvn clean verify -Dcucumber.options="--tags @ios_e2e,@android_e2e" -DtargetEnv="cloudStackEnv"

enter image description here

但是对于串行本地运行,我依赖于pom-singleRunner.xml,它还有一个maven-surefire-plugin来调用Cucumber runner。

mvn -f pom-singleRunner.xml clean verify

上述两个pom文件中都不可避免地复制了依赖项。

有没有更简单的方法来巩固这个(maven多模块结构)? 或者以这样的方式重构它 - 可以在根pom中提取常见的依赖关系等。

**请注意 - 虽然有两个poms,但它们都指向相同的模块,但方式略有不同。

的pom.xml

    <?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>XYZ</groupId>
    <artifactId>NativeAppsAutomation-project</artifactId>
    <version>1.0-SNAPSHOT</version>


    <properties>
        <surefire.fork.count>5</surefire.fork.count>
        <jackson.version>2.7.0</jackson.version>
        <selenium.java.version>3.7.1</selenium.java.version>
        <!--<selenium.java.version>3.7.1</selenium.java.version>-->
        <cucumber.extentsreport.version>3.0.1</cucumber.extentsreport.version>
        <!--<appium.java-client.version>5.0.0-BETA4</appium.java-client.version>-->
        <appium.java-client.version>5.0.4</appium.java-client.version>
        <log4j.version>LATEST</log4j.version>
        <cucumber-java.version>LATEST</cucumber-java.version>
        <json-path.version>2.2.0</json-path.version>
        <junit.version>LATEST</junit.version>
        <cucumber-junit.version>LATEST</cucumber-junit.version>
        <json-simple.version>1.1</json-simple.version>
        <spring-context.version>4.3.6.RELEASE</spring-context.version>
        <cucumber-spring.version>1.2.5</cucumber-spring.version>
        <hamcrest-library.version>1.3</hamcrest-library.version>
        <testng.version>6.8</testng.version>
        <cucumber.jvm.parallel.version>4.1.0</cucumber.jvm.parallel.version>
        <device.name>browserstack.ios</device.name>
        <target.env>browserStackEnv</target.env>
    </properties>

    <profiles>
        <profile>
            <id>TestSuite1</id>
            <activation>
              <activeByDefault>true</activeByDefault>
            </activation>
            <properties>
                <app.config>//src//test//java//envConfig//localGridConfig.properties</app.config>
                <test.tag>@albelli_android</test.tag>
                <dummy.tag>@dummy</dummy.tag>
                <device.name>browserstack.ios</device.name>
                <!--<target.env>browserStackEnv</target.env>-->
            </properties>
        </profile>


        </profile>

    </profiles>
    <build>
        <!--<sourceDirectory>src</sourceDirectory>-->
        <plugins>
            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.1</version>
                <configuration>
                    <source>1.7</source>
                    <target>1.7</target>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-failsafe-plugin</artifactId>
                <version>2.20</version>
                <configuration>
                    <parallel>methods</parallel>
                    <threadCount>5</threadCount>
                </configuration>
            </plugin>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.19</version>
                <configuration>
                    <forkCount>5</forkCount>
                    <reuseForks>true</reuseForks>
                    <includes>
                        <include>**/Parallel*IT.class</include>
                    </includes>
                    <systemPropertyVariables>
                        <deviceName>${device.name}</deviceName>
                        <targetEnv>${target.env}</targetEnv>
                    </systemPropertyVariables>
                </configuration>
            </plugin>




           <plugin>
                    <groupId>com.github.temyers</groupId>
                    <artifactId>cucumber-jvm-parallel-plugin</artifactId>
                <version>4.2.0</version>
                <executions>
                    <execution>
                        <id>generateRunners</id>
                        <phase>generate-test-sources</phase>
                        <!--<phase>validate</phase>-->
                        <goals>
                            <goal>generateRunners</goal>
                        </goals>
                        <configuration>
                            <!-- Mandatory -->
                            <!-- List of package names to scan for glue code. -->
                            <glue>
                                <package>stepDefs</package>
                            </glue>
                            <!-- These are optional, with the default values -->
                            <!-- Where to output the generated tests -->
                            <outputDirectory>${project.build.directory}/cucumber-parallel/html</outputDirectory>
                            <!--<outputDirectory>${project.build.directory}/generated-test-sources/cucumber</outputDirectory>-->
                            <!-- The directory, which must be in the root of the runtime classpath, containing your feature files.  -->
                            <featuresDirectory>src/main/resources/features/</featuresDirectory>
                            <!-- Directory where the cucumber report files shall be written  -->
                            <!--<cucumberOutputDir>target/cucumber-parallel</cucumberOutputDir>-->
                            <cucumberOutputDir>target/cucumber-parallel</cucumberOutputDir>
                            <!-- List of cucumber plugins. When none are provided the json formatter is used. For more
                                 advanced usage see section about configuring cucumber plugins -->
                            <format>json,html,rerun</format>

                            <plugins>
                                <plugin>
                                    <name>json</name>
                                    <extension>json</extension>
                                    <!--Optional output directory. Overrides cucumberOutputDirectory. Usefull when different
                                        plugins create files with the same extension-->
                                    <outputDirectory>${project.build.directory}/cucumber-parallel/json</outputDirectory>
                                </plugin>
                                <!--<plugin>-->
                                <!--<name>com.example.CustomHtmlFormatter</name>-->
                                <!--<extension>html</extension>-->
                                <!--</plugin>-->
                                    <plugin>
                                        <name>com.cucumber.listener.ExtentCucumberFormatter</name>
                                        <extension>html</extension>
                                    </plugin>
                            </plugins>
                            <customVmTemplate>
                                src/main/resources/cucumber-extents-report-runner.java.vm
                            </customVmTemplate>
                            <!-- CucumberOptions.strict property -->
                            <strict>true</strict>
                            <!-- CucumberOptions.monochrome property -->
                            <monochrome>true</monochrome>
                            <!-- The tags to run, maps to CucumberOptions.tags property. Default is no tags. -->
                            <tags>
                                <tag>
                                    <!--${dummy.tag}-->

                                </tag>
                            </tags>
                            <!-- Generate TestNG runners instead of JUnit ones. -->
                            <useTestNG>false</useTestNG>
                            <!-- The naming scheme to use for the generated test classes.  One of 'simple' or 'feature-title' -->
                            <namingScheme>simple</namingScheme>
                            <!-- The class naming pattern to use.  Only required/used if naming scheme is 'pattern'.-->
                            <!--<namingPattern>**/Parallel*IT.class</namingPattern>-->
                            <namingPattern>Parallel{c}IT</namingPattern>

                            <!-- One of [SCENARIO, FEATURE]. SCENARIO generates one runner per scenario.  FEATURE generates a runner per feature. -->
                            <!--<parallelScheme>SCENARIO</parallelScheme>-->
                            <parallelScheme>FEATURE</parallelScheme> <!--Using Feature for accomodating Scenario Outline -->

                            <!-- Specify a custom template for the generated sources (this is a path relative to the project base directory) -->
                            <!--<customVmTemplate>src/test/resources/cucumber-custom-runner.vm</customVmTemplate>-->
                            <!-- Specify a custom package name for generated sources. Default is no package.-->
                            <packageName>
                            </packageName>

                        </configuration>
                    </execution>
                </executions>
            </plugin>

          <!-- Cucumber report merger

          -->
            <plugin>
                <groupId>report.donut</groupId>
                <artifactId>donut-maven-plugin</artifactId>
                <version>0.0.6</version>
                <executions>
                    <execution>
                        <id>execution</id>
                        <phase>post-integration-test</phase>
                        <goals>
                            <goal>generate</goal>
                        </goals>
                        <configuration>
                            <sourceDirectory>${project.build.directory}/cucumber-parallel</sourceDirectory>
                            <outputDirectory>${project.build.directory}/TrackMergeReport</outputDirectory>
                            <timestamp>${maven.build.timestamp}</timestamp>
                            <template>default</template>
                            <projectName>NativeAppsAutomation</projectName>
                            <!-- optional -->
                            <customAttributes>
                                <customAttribute>
                                    <name>App Name</name>
                                    <!--<value>${app.name}</value>-->
                                    <value>smartphone.editor.beta</value>
                                </customAttribute>
                                <customAttribute>
                                    <name>Device Name</name>
                                    <!--<value>${app.name}</value>-->
                                    <value>${device.name}</value>

                                </customAttribute>

                                <customAttribute>
                                    <name>Target Env</name>
                                    <value>${target.env}</value>
                                </customAttribute>
                            </customAttributes>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>

    </build>

    <dependencies>

        <dependency>
            <groupId>com.github.fge</groupId>
            <artifactId>json-schema-validator</artifactId>
            <version>2.0.0</version>
        </dependency>


        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-databind</artifactId>
            <version>${jackson.version}</version>
        </dependency>
        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-core</artifactId>
            <version>${jackson.version}</version>
        </dependency>

        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-java</artifactId>
            <version>${selenium.java.version}</version>
        </dependency>

        <dependency>
            <groupId>io.appium</groupId>
            <artifactId>java-client</artifactId>
            <version>${appium.java-client.version}</version>
            <!--<version>5.0.0-BETA5</version>-->
        </dependency>

        <!-- https://mvnrepository.com/artifact/log4j/log4j -->
        <dependency>
            <groupId>log4j</groupId>
            <artifactId>log4j</artifactId>
            <version>${log4j.version}</version>
        </dependency>

        <dependency>
            <groupId>info.cukes</groupId>
            <artifactId>cucumber-java</artifactId>
            <version>${cucumber-java.version}</version>
        </dependency>

        <!-- https://mvnrepository.com/artifact/com.jayway.jsonpath/json-path -->
        <dependency>
            <groupId>com.jayway.jsonpath</groupId>
            <artifactId>json-path</artifactId>
            <version>${json-path.version}</version>
        </dependency>


        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>${junit.version}</version>
        </dependency>

        <dependency>
            <groupId>info.cukes</groupId>
            <artifactId>cucumber-junit</artifactId>
            <version>${cucumber-junit.version}</version>
        </dependency>



        <dependency>
            <groupId>com.googlecode.json-simple</groupId>
            <artifactId>json-simple</artifactId>
            <version>${json-simple.version}</version>
        </dependency>


        <dependency>
            <groupId>org.hamcrest</groupId>
            <artifactId>hamcrest-library</artifactId>
            <version>${hamcrest-library.version}</version>
            <scope>test</scope>
        </dependency>



        <dependency>
            <groupId>info.cukes</groupId>
            <artifactId>cucumber-jvm-deps</artifactId>
            <version>1.0.5</version>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>info.cukes</groupId>
            <artifactId>cucumber-picocontainer</artifactId>
            <version>1.2.5</version>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>com.vimalselvam</groupId>
            <artifactId>cucumber-extentsreport</artifactId>
            <version>${cucumber.extentsreport.version}</version>
        </dependency>


        <dependency>
            <groupId>report.donut</groupId>
            <artifactId>donut</artifactId>
            <version>1.1</version>
        </dependency>

    </dependencies>
</project>

POM-SingleRunner.XML

    <?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>XYZ</groupId>
    <artifactId>NativeAppsAutomation-project</artifactId>
    <version>1.0-SNAPSHOT</version>[![enter image description here][2]][2]
    <properties>
        <surefire.fork.count>5</surefire.fork.count>
        <jackson.version>2.7.0</jackson.version>
        <selenium.java.version>3.7.1</selenium.java.version>
        <!--<selenium.java.version>3.7.1</selenium.java.version>-->
        <cucumber.extentsreport.version>3.0.1</cucumber.extentsreport.version>
        <!--<appium.java-client.version>5.0.0-BETA4</appium.java-client.version>-->
        <appium.java-client.version>5.0.4</appium.java-client.version>
        <log4j.version>LATEST</log4j.version>
        <cucumber-java.version>LATEST</cucumber-java.version>
        <json-path.version>2.2.0</json-path.version>
        <junit.version>LATEST</junit.version>
        <cucumber-junit.version>LATEST</cucumber-junit.version>
        <json-simple.version>1.1</json-simple.version>
        <spring-context.version>4.3.6.RELEASE</spring-context.version>
        <cucumber-spring.version>1.2.5</cucumber-spring.version>
        <hamcrest-library.version>1.3</hamcrest-library.version>
        <testng.version>6.8</testng.version>
        <cucumber.jvm.parallel.version>4.1.0</cucumber.jvm.parallel.version>
        <device.name>browserstack.ios</device.name>
        <target.env>browserStackEnv</target.env>
    </properties>

    <profiles>
        <profile>
            <id>TestSuite1</id>
            <activation>
                <activeByDefault>false</activeByDefault>
            </activation>
            <properties>
                <test.tag>@dummy2</test.tag>
                <dummy.tag>@dummy</dummy.tag>
                <device.name>browserstack.ios</device.name>
            </properties>
        </profile>


   </profiles>
    <build>
        <!--<sourceDirectory>src</sourceDirectory>-->
        <plugins>
            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.7.0</version>
                <configuration>
                    <source>1.7</source>
                    <target>1.7</target>
                </configuration>
            </plugin>


            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.19</version>
                <configuration>
                    <systemPropertyVariables>
                        <appConfig>${app.config}</appConfig>
                        <targetEnv>${target.env}</targetEnv>
                    </systemPropertyVariables>
                    <forkCount>5</forkCount>
                    <reuseForks>true</reuseForks>
                </configuration>
                <executions>
                    <execution>
                        <id>acceptance-test</id>
                        <goals>
                            <goal>test</goal>
                        </goals>
                        <configuration>
                            <forkCount>${surefire.fork.count}</forkCount>
                            <reuseForks>false</reuseForks>
                            <includes>
                                <include>**/IOSRunner*.class</include>
                            </includes>
                            <testFailureIgnore>true</testFailureIgnore>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-failsafe-plugin</artifactId>
                <version>2.20</version>
                <configuration>
                    <parallel>classes</parallel>
                    <threadCount>5</threadCount>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.19</version>
                <configuration>
                    <forkCount>5</forkCount>
                    <reuseForks>true</reuseForks>
                    <includes>
                        <include>**/Parallel*IT.class</include>
                    </includes>
                    <systemPropertyVariables>
                        <deviceName>${device.name}</deviceName>
                    </systemPropertyVariables>
                </configuration>
            </plugin>
        </plugins>

    </build>

    <dependencies>

        <dependency>
            <groupId>com.github.fge</groupId>
            <artifactId>json-schema-validator</artifactId>
            <version>2.0.0</version>
        </dependency>

        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-core</artifactId>
            <version>${jackson.version}</version>
        </dependency>

        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-java</artifactId>
            <version>${selenium.java.version}</version>
        </dependency>


        <dependency>
            <groupId>com.vimalselvam</groupId>
            <artifactId>cucumber-extentsreport</artifactId>
            <version>${cucumber.extentsreport.version}</version>
        </dependency>

        <dependency>
            <groupId>io.appium</groupId>
            <artifactId>java-client</artifactId>
            <version>${appium.java-client.version}</version>
            <!--<version>5.0.0-BETA5</version>-->
        </dependency>

        <!-- https://mvnrepository.com/artifact/log4j/log4j -->
        <dependency>
            <groupId>log4j</groupId>
            <artifactId>log4j</artifactId>
            <version>${log4j.version}</version>
        </dependency>

        <dependency>
            <groupId>info.cukes</groupId>
            <artifactId>cucumber-java</artifactId>
            <version>${cucumber-java.version}</version>
        </dependency>

        <dependency>
            <groupId>com.jayway.jsonpath</groupId>
            <artifactId>json-path</artifactId>
            <version>${json-path.version}</version>
        </dependency>



        <dependency>
            <groupId>info.cukes</groupId>
            <artifactId>cucumber-junit</artifactId>
            <version>${cucumber-junit.version}</version>
        </dependency>

        <dependency>
            <groupId>info.cukes</groupId>
            <artifactId>cucumber-core</artifactId>
            <version>${cucumber-junit.version}</version>
        </dependency>


        <dependency>
            <groupId>com.googlecode.json-simple</groupId>
            <artifactId>json-simple</artifactId>
            <version>${json-simple.version}</version>
        </dependency>

        <dependency>
            <groupId>org.hamcrest</groupId>
            <artifactId>hamcrest-library</artifactId>
            <version>${hamcrest-library.version}</version>
            <scope>test</scope>
        </dependency>


        <dependency>
            <groupId>info.cukes</groupId>
            <artifactId>cucumber-jvm-deps</artifactId>
            <version>1.0.5</version>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>info.cukes</groupId>
            <artifactId>cucumber-testng</artifactId>
            <version>1.2.4</version>
            <scope>compile</scope>
            <exclusions>
                <exclusion>
                    <groupId>junit</groupId>
                    <artifactId>junit</artifactId>
                </exclusion>
            </exclusions>
        </dependency>

        <dependency>
            <groupId>info.cukes</groupId>
            <artifactId>cucumber-picocontainer</artifactId>
            <version>1.2.5</version>
            <scope>test</scope>
        </dependency>


        <dependency>
            <groupId>com.relevantcodes</groupId>
            <artifactId>extentreports</artifactId>
            <version>2.41.2</version>
            <scope>test</scope>
        </dependency>



        <dependency>
            <groupId>com.vimalselvam</groupId>
            <artifactId>cucumber-extentsreport</artifactId>
            <version>2.0.4</version>
        </dependency>

        <dependency>
            <groupId>com.aventstack</groupId>
            <artifactId>extentreports</artifactId>
            <version>3.0.2</version>
        </dependency>


        <dependency>
            <groupId>io.magentys</groupId>
            <artifactId>donut</artifactId>
            <version>0.0.1</version>
        </dependency>

    </dependencies>
</project>

另外,还有一个原因,如果是串行运行器,我正在探索有一个重试运行器,可以在串行运行结束后调用。但maven-surefire插件并不能保证特定的执行顺序,所以也许我可以再添加一个POM来运行黄瓜转轮进行重试。 enter image description here

enter image description here

0 个答案:

没有答案
相关问题