【问题标题】:MAVEN : Run Multiple Maven Project using Maven TestMAVEN:使用 Maven 测试运行多个 Maven 项目
【发布时间】:2015-11-18 19:56:40
【问题描述】:

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

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

<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 是 -

<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 运行测试用例,那么它会失败。

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

<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>

显示错误信息 -

The POM for Project1:Project1:jar:0.0.1-SNAPSHOT is missing, no dependency information available. The POM for Project2:Project2:jar:0.0.1-SNAPSHOT is missing, no dependency information available

Failed to execute goal on project Project3: Could not resolve dependencies for project Project3:Project3:jar:0.0.1-SNAPSHOT: The following artifacts could not be resolved: Project1:Project1:jar:0.0.1-SNAPSHOT, Project2:Project2:jar:0.0.1-SNAPSHOT: Could not find artifact Project1:Project1:jar:0.0.1-SNAPSHOT -&gt; [Help 1

请帮忙!!!

【问题讨论】:

    标签: maven


    【解决方案1】:

    您必须先在您的 maven 存储库中安装 Project1 和 Project2。

    为此启动命令

    mvn clean install
    

    在 Project1 和 Project2 目录中(以 Project1 开头,因为 Project2 对 Project1 有依赖关系)

    编辑:

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

    在你的根 pom 中你将拥有

    <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 以获取完整示例

    【讨论】:

    • 现在我还要做一件事。我必须使用 Jenkins 运行这个项目。如何做到这一点?我正在提供 Project3 pom.xml 的路径。但显示与使用 maven 测试运行时先前提供的相同错误消息。请帮忙!!!
    • 我会试试这个,但是有没有办法可以用当前的 pom 运行它?
    • 如果你想使用你当前的 pom,你必须在 project3 之前在 Jenkins 中构建 project1 和 project2。另一种方法是在nexus(或其他maven存储库)中部署project1.jar和project2.jar
    • 感谢您的回复!!!我会尝试第一个选项,因为我不知道如何将 jar 部署到 nexus。
    猜你喜欢
    • 2019-05-05
    • 1970-01-01
    • 2013-03-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-01-18
    • 2020-11-26
    相关资源
    最近更新 更多