This question already has answers here:
Can I use a GitHub project directly in Maven?
(3 answers)
Closed 2 years ago.
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?
Now you can import a Java library from a GitHub repo using JitPack.
In your pom.xml:
Add repository:
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
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.
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.
Github now supports packages https://help.github.com/en/github/managing-packages-with-github-packages/configuring-apache-maven-for-use-with-github-packages
You can follow the steps above to deploy Jar files to github properly.
Another very nice thing about Jitpack is, it has a lookup button on the main page. And if you type the URL of your GitHub repository, it displays different commits of the source code, and you can select which commit/tag you want. The Jitpack creates pom dependencies for you.
It became dead simple.
Related
This question already has answers here:
How to add local jar files to a Maven project?
(35 answers)
Closed 5 years ago.
I feel like I must be lacking some very very basic Maven knowledge here. I have a (couple of) maven project(s) and a shared library. This library should be a separate maven project with its own life cycle. I'm trying to import the library into my project using:
<dependencyManagement>
<dependencies>
<dependency>
<groupId>nl.whatever.com</groupid>
<artifactId>my_shared_library</artifactId>
<version>1.0-SNAPSHOT</groupid>
</dependency>
...
</dependencies>
</dependencyManagement>
But maven keeps looking in my repro instead of trying to find my local build. And worst of all, it keeps looking for a jar. I get:
Could not resolve dependencies for project my.project:ejb:1.0-SNAPSHOT: Could not find artifact nl.whatever.com:my_shared_library:jar:1.0-SNAPSHOT
What's my rookie mistake? Yes, I did do a clean install of my library project.
edit:
My .m2 directory has a settings file redirecting my local repro to
/ws/repro, which contains:
/ws/repro/nl/whatever/com/my_shared_library/1.0-SNAPSHOT/
my_shared_project-1.0-SNAPSHOT.jar.lastUpdate
my_shared_project-1.0-SNAPSHOT.pom
and some property files.
edit2:
I don't think it's a duplicate. I looked at the question linked before posting my question. There is no non-maven project or external jar involved here.
Your local repository is usually in .m2/repository below the user repository. If You do clean install on your library project, it should be installed into this repository (in nl/whatever/com/my_shared_library/...). Then you can use it from all other Maven projects on the same computer.
It is furthermore important that the <packaging> is correct, i.e. the packaging needs to match the artifact you want to build. If the packaging is pom then you only create a pom (like a parent pom or a bom). Leaving out the packaging tag implictely means that you use packaging jar.
You shall try updating your pom.xml with a tag named as repositories.
Maven repositories are the places that hold build artifacts and dependencies of varying types.
A sample maven remote repository tag with its values is:
<repositories>
<repository>
<id>central</id>
<name>Maven Repository</name>
<url>http://repo1.maven.org/maven2</url>
</repository>
</repositories>
To configure multiple repositories you can follow the guide and make use of profile in settings.xml as well.
On a side note, unless following a hierarchy or making use of specific versions of a library. You should use <dependencies> instead of <dependencyManagement>, take a look at the differences between dependencymanagement and dependencies in maven.
I have a set of plugins in eclipse with a product. My goal is to automate the deliveries: passing automatically test, creating automatically features and update sites...I found tutorials like this one http://www.vogella.com/tutorials/EclipseTycho/article.html#exercisetycho_configuration_parent and it works great on my personal laptop where I have internet but not on my work computer because I don't have access to internet. The part that is the problem is the configuration of the properties for the build:
<properties>
<tycho.version>0.25.0</tycho.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<mars-repo.url>http://download.eclipse.org/releases/mars</mars-repo.url>
</properties>
<repositories>
<repository>
<id>mars</id>
<url>${mars-repo.url}</url>
<layout>p2</layout>
</repository>
</repositories>
I want to point my url to my p2 repositories in eclipse repository and not on the internet. Is there a way to do it?
Thanks a lot for the help
Build the features locally using mvn clean install in the features directory. This should generate /target/repository.
Then, in your product pom.xml, you can update the repository to point to this local repo:
<repositories>
<repository>
<id>mars</id>
<url>file:/C:/path-to-target/target/repository</url>
<layout>p2</layout>
</repository>
</repositories>
A mvn clean package in the products directory should give you an assembly using the local features.
There are also a couple slight variations of this answer in the answers section over here: Build local eclipse plugins using tycho pointing to local p2 repository
Since the Github plugin for hosting maven repositories within Github is not working anymore, I am trying to find some other quick way to host a maven artifact.
One way I am thinking is to use my Dropbox 'Public' folder (since I still have it active now) and host the artifact from there.
What could be the approach to use Dropbox as maven repository?
Is there a plugin to use Dropbox as maven repository?
For people who share a common Dropbox folder, you can set it up as a Maven repository using this configuration in your project/pom.xml or maven/conf/settings.xml:
<repositories>
<repository>
<id>localDropbox</id>
<url>file://[path to Dropbox folder]</url>
</repository>
</repositories>
And to use mvn deploy to send artifacts there:
<distributionManagement>
<repository>
<id>localDropbox</id>
<url>file://[path to Dropbox folder]</url>
</repository>
</distributionManagement>
If the folder is publicly available, people who want access to that could have a http URL instead of filesystem URL in their <repository> declaration.
I am interested in using a project on GitHub as a dependency in my project. The GitHub project has a pom file. Can I modify my pom file to use this project? If so, how? If not, what is my best course of action?
Try jitpack, you just need to add the dependency, jitpack will build others for you.
From home page:
jitpack
Easy to use package repository for Gradle and Maven projects
JitPack builds GitHub projects on demand and provides ready-to-use packages
HOW
Add repository first
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
Add dependency
<dependency>
<groupId>com.github.User</groupId>
<artifactId>Repo name</artifactId>
<version>Release tag</version>
</dependency>
TIPS:
You can see its build log too https://jitpack.io/com/github/NanoHttpd/nanohttpd/Release-2.1.0/build.log
Not in the way I think you mean, AFAIK.
You can use github as a Maven repository--this is not the same thing as directly referencing a project, and that it has a pom file means only that it's a Maven project.
If the project is not available in the central, or other, repository, your best bet may be to clone it, build it, and install it locally. You should confirm that it's truly not available elsewhere.
#wener's answer is very helpful, but leaves some mystery.
This real example might save some time:
<project ... >
<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
<dependencies>
<dependency>
<!-- groupId is https://github.com/fabric8io/kubernetes-client -->
<groupId>com.github.fabric8io.kubernetes-client</groupId>
<!-- module is a directory within the repo, containing pom.xml -->
<artifactId>kubernetes-model-generator-client</artifactId>
</dependency>
</dependencies>
. . .
Make sure you are signed into GitHub.
You can also find a tag index page by cutting at the tag within the URL, like https://jitpack.io/com/github/fabric8io/kubernetes-client/. In my example, I figured out if "v" from "v6.4.1" had to be removed or not, since there is a release with the v and a tag without it.
More details: jitpack.io page
I'm intrigued to test new frameworks in the Java world, and decided to create a new project that takes advantage of Maven and db4o. I'm starting to get a hang of Maven, but I have a hard time adding db4o as a dependency to the project. First problem is that db4o doesn't exist in the official Maven repositories. Next up comes the problem that db4o seem to have recently restructured their whole site's URI:s, so I'm getting 'site not found' messages all the time when I try to navigate their site.
I found somewhere a potential Maven repository that should be at https://source.db4o.com/maven but I get all the time "Error reading archetype catalog https://source.db4o.com/maven Unable to locate resource in repository" when I try to access it.
So, any suggestions on how I'll get db4o up through Maven? I've managing Maven through Eclipse with the M2Eclipse plugin.
Works for me with the following snippet:
<project>
<repositories>
<repository>
<id>source.db4o</id>
<url>http://source.db4o.com/maven</url>
</repository>
</repositories>
...
<dependencies>
<dependency>
<groupId>com.db4o</groupId>
<artifactId>db4o-full-java5</artifactId>
<version>8.1-SNAPSHOT</version> <!-- latest version -->
</dependency>
...
</dependencies>
</project>
You won't see a dependency in m2eclipse unless the Maven repository has been indexed with the Nexus indexer...very few 3rd party repositories are.