本文介绍了MAVEN:使用 Maven 测试运行多个 Maven 项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有 3 个 Maven 项目.项目 1、项目 2 和项目3.Project3 依赖于 Project1 &Project2 和 Project2 依赖于 Project1.

I have 3 maven projects. Project1, Project2 & Project3.Project3 depends on Project1 & Project2 and Project2 depends on Project1.

为此,我在 Project2 pom.xml 文件中添加了这个

For this I have added this in Project2 pom.xml file

<modelVersion>4.0.0</modelVersion>

  <groupId>Project2</groupId>
  <artifactId>Project2</artifactId>
  <version>0.0.1-SNAPSHOT</version>

  <dependencies>
     <dependency>
            <groupId>Project1</groupId>
            <artifactId>Project1</artifactId>
            <version>0.0.1-SNAPSHOT</version>
    </dependency>
  </dependencies>

我用于 Project3 的 pom.xml 是 -

My pom.xml for Project3 is -

<modelVersion>4.0.0</modelVersion>
  <groupId>Project3</groupId>
  <artifactId>Project3</artifactId>
  <version>0.0.1-SNAPSHOT</version>

  <dependencies>
        <dependency>
            <groupId>Project1</groupId>
            <artifactId>Project1</artifactId>
            <version>0.0.1-SNAPSHOT</version>
         </dependency>

         <dependency>
            <groupId>Project2</groupId>
            <artifactId>Project2</artifactId>
            <version>0.0.1-SNAPSHOT</version>
        </dependency>
  </dependencies>

在项目 3 中,我添加了 testng.xml 文件来运行测试.现在,如果我运行这个 testng.xml 文件,那么我所有的测试用例都会成功运行.如果我尝试使用 maven test 运行测试用例,那么它失败了.

In the project 3 I have added testng.xml file to run the test. Now If I run this testng.xml file then all my test cases are running successfully. By If I tried to run test cases using maven test then its failing.

我在依赖项下面的 pom 文件中包含 testng.xml 文件以使用 maven 运行 testng 测试 -

I have included testng.xml file in the pom file below dependencies to run testng test using maven -

<build>
        <!-- Source directory configuration -->
        <sourceDirectory>src</sourceDirectory>
        <plugins>
            <!-- Following plugin executes the testng tests -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.14.1</version>
                <configuration>
                    <!-- Suite testng xml file to consider for test execution -->
                    <suiteXmlFiles>
                        <suiteXmlFile>Tng1.xml</suiteXmlFile>
                    </suiteXmlFiles>
                </configuration>
            </plugin>
            <!-- Compiler plugin configures the java version to be used for compiling the code -->
            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>1.6</source>
                    <target>1.6</target>
                </configuration>
            </plugin>
        </plugins>
    </build>

显示错误信息 -

Project1:Project1:jar:0.0.1-SNAPSHOT 的 POM 丢失,没有可用的依赖信息.Project2:Project2:jar:0.0.1-SNAPSHOT 的 POM 丢失,没有可用的依赖信息

未能在项目 Project3 上执行目标:无法解析项目 Project3:Project3:jar:0.0.1-SNAPSHOT:以下工件无法解析:Project1:Project1:jar:0.0.1-快照,Project2:Project2:jar:0.0.1-SNAPSHOT:找不到工件 Project1:Project1:jar:0.0.1-SNAPSHOT ->[帮助1

请帮忙!!!

推荐答案

您必须先在 Maven 存储库中安装 Project1 和 Project2.

You have to install Project1 and Project2 in your maven repository first.

为此启动命令

mvn clean install

在 Project1 和 Project2 目录中(从 Project1 开始,因为 Project2 依赖于 Project1)

in Project1 and Project2 directory (start with Project1 because Project2 has a dependecy to Project1)

对于 Jenking,我通常创建一个带有模块声明的 Root pom.Maven 将按依赖项对您的模块进行排序.

For Jenking, I usually create a Root pom with module declaration. Maven will order you module by dependencies.

在您的根 pom 中,您将拥有

In your root pom you will have

<modules>
    <module>project1</module>
    <module>project2</module>
    <module>project3</module>
  </modules>

在你的子模块中

  <parent>
  <groupId>com.myGroupId</groupId>
  <artifactId>project-root</artifactId>
  <version>1.0-SNAPSHOT</version>
  </parent>

你可以查看 http://books.sonatype.com/mvnex-book/reference/multimodule.html 完整示例

Yon can check http://books.sonatype.com/mvnex-book/reference/multimodule.html for full example

这篇关于MAVEN:使用 Maven 测试运行多个 Maven 项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-06 08:15