Utkarsh Saraf
Utkarsh Saraf

Reputation: 495

Importing dependency from mvn repo in addition to jars in git repo

I have jars present for my file in git repo I have created which is having pom.xml as

<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>
    <parent>
        <groupId>com.acc.ar</groupId>
        <artifactId>ar-anal-plat</artifactId>
        <version>1.6.0-RC-SNAPSHOT</version>
    </parent>
    <artifactId>gr-anal-app</artifactId>

    <dependencies>
        <dependency>
            <groupId>com.acc.ar</groupId>
            <artifactId>ar-anal-core</artifactId>
        </dependency>
        <dependency>
            <groupId>com.acc.ar</groupId>
            <artifactId>ar-anal-core-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>
</project>

I want to import an additional jar of graphframes from mvn repo having dependency as follows:
https://mvnrepository.com/artifact/graphframes/graphframes/0.5.0-spark2.1-s_2.11

What changes I have to make in pom file?

Upvotes: 1

Views: 469

Answers (2)

Punit
Punit

Reputation: 344

There are 3 types of repositories in maven :

1) local repository : a location on your local system which is used to store the downloaded jar from central or remote repository at the first time and from 2nd time onward dependencies are search out in local repo first if not present then go to central repo: It's location need to be mention in maven's setting.xml file.

2) Central repository : It is a centralized loaction of all the project related dependencies and it's location need to be provide in setting.xml file. I hope, you have already mentioned "git repo" in setting.xml file.

3) Remote repository : Still if any dependency is not present in local or central repo then for a custom location can be provided inside pom.xml file. So, first it will look into local repo, if not present then central repo and then remote repo.

<repositories>
  <repository>
     <id>companyname.lib1</id>
     <url>http://download.companyname.org/maven2/lib1</url>
  </repository>
  <repository>
     <id>companyname.lib2</id>
     <url>http://download.companyname.org/maven2/lib2</url>
  </repository>

Use this in your case and I guess you problem should be resolved.

Search Sequence :

Step 1 − Search dependency in local repository, if not found, move to step 2 else perform the further processing.

Step 2 − Search dependency in central repository, if not found and remote repository/repositories is/are mentioned then move to step 4. Else it is downloaded to local repository for future reference.

Step 3 − If a remote repository has not been mentioned, Maven simply stops the processing and throws error (Unable to find dependency).

Step 4 − Search dependency in remote repository or repositories, if found then it is downloaded to local repository for future reference. Otherwise, Maven stops processing and throws error (Unable to find dependency).

Upvotes: 1

hippieSabotage89
hippieSabotage89

Reputation: 43

within the dependencies block you need to insert the following:

   <!-- https://mvnrepository.com/artifact/graphframes/graphframes -->
   <dependency>
       <groupId>graphframes</groupId>
       <artifactId>graphframes</artifactId>
       <version>0.5.0-spark2.1-s_2.11</version>
   </dependency>

and then most probably refresh the project in the IDE / import changes.

Upvotes: 0

Related Questions