Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Loading Maven dependencies from GitHub [duplicate]

How do I add a Java library from its GitHub repo (the library uses Maven as a build system) as a dependency to my Maven project? Can I do that without downloading and compiling the library?

like image 698
Arielle Avatar asked Nov 23 '13 11:11

Arielle


People also ask

How do I force Maven to download dependencies from remote repository?

Force maven to fetch dependencies from the remote repository while building the project. We can use -U/--update-snapshots flag when building a maven project to force maven to download dependencies from the remote repository.

How do I get dependencies from GitHub?

On GitHub.com, navigate to the main page of the repository. Under your repository name, click Insights. In the left sidebar, click Dependency graph. Optionally, under "Dependency graph", click Dependents.

How do I add a Git repository to Maven?

To bring a GitHub hosted Maven project into Eclipse, follow these steps: Copy the GitHub URL of the repository to the clipboard. Open Eclipse and choose Import –> Projects from Git (with smart import) Choose the Clone URI option in the Git import wizard and click Next.


2 Answers

Now you can import a Java library from a GitHub repo using JitPack. In your pom.xml:

  1. Add repository:
<repository>     <id>jitpack.io</id>     <url>https://jitpack.io</url> </repository> 
  1. Add dependency
<dependency>     <groupId>com.github.User</groupId>     <artifactId>Repo name</artifactId>     <version>Release tag</version> </dependency> 

It works because JitPack will check out the code and build it. So you'll end up downloading the jar.
If the project doesn't have a GitHub release then its possible to use a commit id as the version.

like image 188
Andrejs Avatar answered Sep 17 '22 01:09

Andrejs


At the moment there is no way you can do this unless the maintainer of the library provided a way to do this.

So on the title page of the library the should be an instruction containing the repository address like:

<repositories>     <repository>         <id>YOUR-PROJECT-NAME-mvn-repo</id>         <url>https://raw.github.com/YOUR-USERNAME/YOUR-PROJECT-NAME/mvn-repo/</url>         <snapshots>             <enabled>true</enabled>             <updatePolicy>always</updatePolicy>         </snapshots>     </repository> </repositories> 

And a dependency name:

<dependency>      <groupId>...</groupId>      <artifactId>...</artifactId>      <version>...</version> </dependency> 

This means that all artifact of your project including your dependency will be searched in this repo.

You could also have a glance at pom.xml to check if there was an effort made to deploy artifacts to a remote repo. Typically the keywords are oss.sonatype.org or raw.github.com like in this case.

FYI, here is a way to provide a repo for your gihub artifact: Hosting a Maven repository on github.

like image 26
Andrey Chaschev Avatar answered Sep 20 '22 01:09

Andrey Chaschev