Dushyant Patil
Dushyant Patil

Reputation: 27

MAVEN : Run Multiple Maven Project using Maven Test

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

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>

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>

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.

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>

It is showing error message -

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 -> [Help 1

Please Help !!!

Upvotes: 2

Views: 1373

Answers (1)

fabballe
fabballe

Reputation: 771

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

To do that launch the command

mvn clean install

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

EDIT:

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

In your root pom you will have

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

And in your submodule

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

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

Upvotes: 1

Related Questions