Search code examples
javamavenelasticsearch-jest

How to add a project and its dependecies using Maven?


I have a Project (A) that uses I class Library(B) that my team and I developed.

The Class Library (B) imports the searchbox-io.Jest project to access my ElasticSearch Engine and does some processing. The Project (A) implements the Restful service to the user interface.

This is the POM of B, the Class Library:

<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>br.org.b</groupId>
    <artifactId>b-project</artifactId>
    <version>0.1.11</version>
    <packaging>jar</packaging> 
    <build>
        <sourceDirectory>src</sourceDirectory>
        <plugins>
            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.3</version>              
            </plugin>
        </plugins>
        <extensions>
            <extension>
                <groupId>org.kuali.maven.wagons</groupId>
                <artifactId>maven-s3-wagon</artifactId>
                <version>1.2.1</version>
            </extension>
        </extensions>
    </build>
    <dependencies>      
        <dependency>
            <groupId>io.searchbox</groupId>
            <artifactId>jest</artifactId>
            <version>2.0.0</version>
        </dependency>       
    </dependencies> 
</project>

This is the POM of project A:

<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>MachineAPI</groupId>
    <artifactId>MachineAPI</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>war</packaging>
    <build>
        <sourceDirectory>src</sourceDirectory>
        <plugins>
            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.3</version>
            </plugin>
            <plugin>
                <artifactId>maven-war-plugin</artifactId>
                <version>2.6</version>
            </plugin>
        </plugins>
    </build>
    <dependencies>
        <dependency>
            <groupId>br.org.b</groupId>
            <artifactId>b-project</artifactId>
            <version>0.1.11</version>           
        </dependency>
    </dependencies>
</project>

The Problem:

However when I try to execute Project A it doesn´t find the reference to the searchbox-io.Jest.

My problem is that I have to make the project A import the same references that the Class Library uses, so I can use the methods of ElasticSearch. How can i resolve that?


Solution

  • If both projects depend on the same package it should be explicitly listed on both projects dependencies. Do not count on transitive dependencies.

    If both projects share the several dependencies, instead of listing all on the on each POM you can create a "parent" POM with all common dependencies and make it the parent POM of both projects.