I create a GitHub Repository(Private) and wanted to Use it as a Maven Dependency for Some Other Projects (Private). Accordingly I have tried out following approaches in the internet and still I could able to import the maven dependencies on the Other projects.
I have tried out these following approaches
https://gist.github.com/fernandezpablo85/03cf8b0cd2e7d8527063
through building a branch, which contains jar and linking the branch raw.githubusercontent.com as the repo url.
Hosting a Maven repository on github
http://www.lordofthejars.com/2011/09/questa-di-marinella-e-la-storia-vera.html
http://maven.apache.org/guides/mini/guide-3rd-party-jars-local.html
(same as Step 1)
https://github.com/jitpack/maven-simple
I tried linking with JITPACK and Tried but still it doesn't work.
This is based on Reference 5,
In my pom.xml file the project which I am going to use repository, I have added dependency as follows, ant it was able to update maven indices and able to download related pom.xml file for CMD.
<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
<dependency>
<groupId>com.github.Amutheezan</groupId>
<artifactId>CMD</artifactId>
<version>v1.0ALPHA2</version>
</dependency>
NOTE : - I place of version, I have tried recently released version, latest commit's value and 1.0-SNAPSHOT.
Still I couldn't able to import in either way.
import com.abc.CMD.*
or
import com.abc.*
Can help me out where I am making mistake ?
It's because your repository is private, and you have not followed the steps to authorize jitpack to access a private repository.
https://jitpack.io/private
Private Repositories To use JitPack with private repositories:
Step 1. Authorize JitPack and get your personal access token:
Step 2. Add the token to $HOME/.m2/settings.xml as the username
<settings>
<servers>
<server>
<id>jitpack.io</id>
<username>AUTHENTICATION_TOKEN</username>
<password>.</password>
</server>
</servers>
</settings>
The id of the server must be the same you use in your pom.xml
Step 3. (Optional) You may need to approve JitPack Application on GitHub
Build artifacts (jar, aar) are also private and you can only download
them if you have access to the Git repo itself. See the documentation
for more details
If you'd like to host JitPack inside your organization please see
JitPack Enterprise
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
Does maven require a connection to the internet at some point to be able to use it? Meaning specifically getting the internal maven plugins for compiling, cleaning, packaging, etc?
You can run Maven in "offline" mode using the -o or -offline option (e.g. mvn -o install). Of course any artifacts not available in your local repository will fail. Maven is not predicated on distributed repositories, but they certainly make things more seamless. It's for this reason that many shops use internal mirrors that are incrementally synced with the central repos.
In addition, the mvn dependency:go-offline can be used to ensure you have all of your dependencies installed locally before you begin to work offline.
If you have a PC with internet access in your LAN, you should install a local Maven repository.
I recommend Artifactory Open Source. This is what we use in our organization, it is really easy to setup.
Artifactory acts as a proxy between your build tool (Maven, Ant, Ivy, Gradle etc.) and the outside world.
It caches remote artifacts so that you don’t have to download them over and over again.
It blocks unwanted (and sometimes security-sensitive) external requests for internal artifacts and controls how and where artifacts are deployed, and by whom.
After setting up Artifactory you just need to change Maven's settings.xml in the development machines:
<?xml version="1.0" encoding="UTF-8"?>
<settings xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd" xmlns="http://maven.apache.org/SETTINGS/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<mirrors>
<mirror>
<mirrorOf>*</mirrorOf>
<name>repo</name>
<url>http://maven.yourorganization.com:8081/artifactory/repo</url>
<id>repo</id>
</mirror>
</mirrors>
<profiles>
<profile>
<repositories>
<repository>
<snapshots>
<enabled>false</enabled>
</snapshots>
<id>central</id>
<name>libs-release</name>
<url>http://maven.yourorganization.com:8081/artifactory/libs-release</url>
</repository>
<repository>
<snapshots />
<id>snapshots</id>
<name>libs-snapshot</name>
<url>http://maven.yourorganization.com:8081/artifactory/libs-snapshot</url>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<snapshots>
<enabled>false</enabled>
</snapshots>
<id>central</id>
<name>plugins-release</name>
<url>http://maven.yourorganization.com:8081/artifactory/plugins-release</url>
</pluginRepository>
<pluginRepository>
<snapshots />
<id>snapshots</id>
<name>plugins-snapshot</name>
<url>http://maven.yourorganization.com:8081/artifactory/plugins-snapshot</url>
</pluginRepository>
</pluginRepositories>
<id>artifactory</id>
</profile>
</profiles>
<activeProfiles>
<activeProfile>artifactory</activeProfile>
</activeProfiles>
</settings>
We used this solution because we had problems with internet access in our development machines and some artifacts downloaded corrupted files or didn't download at all. We haven't had problems since.
You have two options for this:
1.) make changes in the settings.xml add this in first tag
<localRepository>C:/Users/admin/.m2/repository</localRepository>
2.) use the -o tag for offline command.
mvn -o clean install -DskipTests=true
mvn -o jetty:run
Maven needs the dependencies in your local repository. The easiest way to get them is with internet access (or harder using other solutions provided here).
So assumed that you can get temporarily internet access you can prepare to go offline using the maven-dependency-plugin with its dependency:go-offline goal. This will download all your project dependencies to your local repository (of course changes in the dependencies / plugins will require new internet / central repository access).
Sadly dependency:go-offline hasn't worked for me as it didn't cached
everything, ie. POMs files and other implicitly mention dependencies.
The workaround has been to specify a local repository location, either within settings.xml file with <localRepository>...</localRepository> or by running mvn with -Dmaven.repo.local=... parameter.
After initial project build, all necessary artifacts should be cached, and then you can reference repository location the same ways, while running Maven build in offline mode (mvn -o ...).
Before going offline you have to make sure that everything is in your local repo, which is required while working offline. Running "mvn dependency:go-offline" for the project(s)/pom(s), you intend to work on, will reduce the efforts to achieve this.
But it´s usually not the whole story, because dependency:go-offline will only download the "bare build" plugins (go-offline / resolve-plugins does not resolve all plugin dependencies). So you have to find a way to download deploy / test / site plugins (and maybe others) and their dependencies into your repo.
Furthermore dependency:go-offline does not download the pom´s artifact itself, so you have to dependency:copy it if required.
Sometimes - as MaDa wrote - you do not know, what you will need, while being offline, which makes it pretty impossible to have a "sufficient" repo.
Anyway having a properly filled repo you only have to add "<offline>true</offline>" to Maven´s settings.xml to go offline.
Do not change the Maven profile (id) you used to fill your repo, while being offline. Maven recognizes the downloaded artifacts in its metadata with an "identity", which is bound to the profile id.
If you're using IntelliJ, you can simply go to Preferences -> Build, Execution, Deployment -> Build Tools -> Maven and check/uncheck Work offline.
Does this work for you?
http://jojovedder.blogspot.com/2009/04/running-maven-offline-using-local.html
Don't forget to add it to your plugin repository and point the url to wherever your repository is.
<repositories>
<repository>
<id>local</id>
<url>file://D:\mavenrepo</url>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>local</id>
<url>file://D:\mavenrepo</url>
</pluginRepository>
</pluginRepositories>
If not, you may need to run a local server, e.g. apache, on your machines.
(source: jfrog.com)
or
Just use Maven repository servers like Sonatype Nexus http://www.sonatype.org/nexus/ or JFrog Artifactory https://www.jfrog.com/artifactory/.
After one developer builds a project, build by next developers or Jenkins CI will not require Internet access.
Maven repository server also can have proxies configured to access Maven Central (or more needed public repositories), and they can have cynch'ed list of artifacts in remote repositories.
My experience shows that the -o option doesn't work properly and that the go-offline goal is far from sufficient to allow a full offline build:
The solution I could validate includes the use of the --legacy-local-repository maven option rather than the -o (offline) one and
the use of the local repository in place of the distribution repository
In addition, I had to copy every maven-metadata-maven2_central.xml files of the local-repo into the maven-metadata.xml form expected by maven.
See the solution I found here.
A new plugin has appeared to fix shortcomings of mvn dependency:go-offline:
https://github.com/qaware/go-offline-maven-plugin
Add it in your pom, then run mvn -T1C de.qaware.maven:go-offline-maven-plugin:resolve-dependencies. Once you've setup all dynamic dependencies, maven won't try to download anything again (until you update versions).
Answering your question directly: it does not require an internet connection, but access to a repository, on LAN or local disk (use hints from other people who posted here).
If your project is not in a mature phase, that means when POMs are changed quite often, offline mode will be very impractical, as you'll have to update your repository quite often, too. Unless you can get a copy of a repository that has everything you need, but how would you know? Usually you start a repository from scratch and it gets cloned gradually during development (on a computer connected to another repository). A copy of the repo1.maven.org public repository weighs hundreds of gigabytes, so I wouldn't recommend brute force, either.
Here's a clear, straightforward way to cache Maven dependencies for offline development (based on #luka5z and others' comments):
While you have internet access, cache dependencies locally:
mvn -Dmaven.repo.local=dependencies install
Disconnect from the internet, verify that offline mode compilation succeeds:
mvn clean
mvn -o -Dmaven.repo.local=dependencies package
Continue developing offline as long as needed.
In preparation before working offline just run
mvn dependency:go-offline
<offline> false </offline>
<localRepository>${user.home}/.m2/repository</localRepository>
to
<offline> true <offline>
<localRepository>${user.home}/.m2/repository</localRepository>
Change the offline tag from false to true .
will download from repo online
Using a google code svn as a basic maven repository is easy.
However, using mvn site:deploy efficiently on google code seems hard.
So far, I found only these solutions:
Deploy to a local file:/// and use a PERL script to delete the old and copy the new.
Source: http://www.mail-archive.com/users#maven.apache.org/msg107719.html
Use wagen-svn to deploy. This is very slow (hours!) and does not delete old files
Plus all mime-types are wrong
I am looking for a solution that allows new developers in my projects to check out the current source and just use it, without requiring to install PERL or learn weird steps to perform or wait hours.
Here is the simplest configuration that works for me in my Google code projects that have a maven repository on Google code svn:
<build>
...
<extensions>
<extension>
<groupId>org.jvnet.wagon-svn</groupId>
<artifactId>wagon-svn</artifactId>
<version>1.9</version>
</extension>
</extensions>
</build>
<distributionManagement>
<repository>
<uniqueVersion>false</uniqueVersion>
<id>googlecode</id>
<url>svn:https://myproject.googlecode.com/svn/trunk/repo/</url>
</repository>
</distributionManagement>
Note the url:
Replace 'myproject' with your real project name and also make sure that your create a folder named 'repo' (or whatever you want) in that location using your svn client.
You can make sure by browsing the sources via your google code site.
After your pom is configured as above, just run 'mvn deploy'.
Make sure you have your google code password at hand ...
Good luck ...
How to deploy maven artifact to Google code svn?
I. Create m2 folder with releases and snaphots subfolders
II. Add dependency to maven-svn-wagon
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.5</version>
<dependencies>
<dependency>
<groupId>com.google.code.maven-svn-wagon</groupId>
<artifactId>maven-svn-wagon</artifactId>
<version>1.4</version>
</dependency>
</dependencies>
</plugin>
III. Add the path to the release and the snapshot repository
<distributionManagement>
<repository>
<id>project-name.googlecode.com</id>
<url>svn:https://project-name.googlecode.com/svn/m2/releases</url>
</repository>
<snapshotRepository>
<id>project-name.googlecode.com</id>
<url>svn:https://project-name.googlecode.com/svn/m2/snapshots</url>
</snapshotRepository>
</distributionManagement>
IV. Don't forget to add to settings.xml your auth. code
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0
http://maven.apache.org/xsd/settings-1.0.0.xsd">
<servers>
<server>
<id>project-name.googlecode.com</id>
<username>yourlogin</username>
<password>yoursvpassword</password>
</server>
</servers>
</settings>
V. Do what you usually do for generating a site (you may consider having a look at maven-svn-wagon pom file with settings for maven-site-plugin)
VI. mvn clean deploy
Example of such pom
Also, might be helpful: maven-repository-for-google-code-project, maven svn wagon, MavenRepositoryInsideGoogleCode
Would a solution like rsync be easier? You essentially want to mirror a locally-generated tree of HTML etc., to a remote server.
Otherwise, you could get Maven to generate and publish the site as part of a continuous integration build using, say, Hudson. Not suitable if you need the site to be globally available - unless you want to open your Hudson server.
I've found good instruction to do what do you want with good responses:
http://babyloncandle.blogspot.com/2009/04/deploying-maven-artifacts-to-googlecode.html
But I suggest to use normal simple http hosting, because it is much more faster than Google Code SVN. Your project is not the one, which needs site, while locates in Google Code.
I'd suggest you to use https://maven2-repository.dev.java.net/ to deploy your open source artifacts. Quite simple to configure and use.
The main "issue" is that you'll need to create an account but you can use it only to deploy the artifacts and still have your source code hosted on Google Code
I want to limit maven to use only private/not public maven repository, do these two settings have the same effect ?
1.Setting mirror in settings.xml
<mirrors>
<mirror>
<id>my-internal-site</id>
<mirrorOf>*</mirrorOf>
<name>our maven repository</name>
<url>http://myserver/repository</url>
</mirror>
</mirrors>
2.Setting repository in pom.xml
<repositories>
<repository>
<id>my-internal-site</id>
<name>our maven repository</name>
<url>http://myserver/repo</url>
</repository>
</repositories>
Again the requirement is that maven never goes out to public repositories even if some dependencies are not there on the internal repository. thank you
No they don't have the same effect.
The second setting add a new repository as a "complement" to central but doesn't prevent Maven to check central by itself.
The first one forces Maven to use a single repository by having it mirror all repository requests (by setting mirrorOf to *). This is the way to use a single repository.
What you're looking for is thus the first setting and need to be defined in the settings.xml.
Now, adding your corporate repository in the ~/.m2/settings.xml file of each machine can be a bit painful and what I like to do in a corporate environment is to distribute and install a "customized" version of Maven containing the mirror predefined in conf/settings.xml. This way, people just have to install the "corporate" version and they are ready to go.
No, they mean different things:
In the first example, you said that the given repository is a mirror of all repositories, including the official one.
In the second example, you simply add a new repository. In case a dependency is not found in the local repository, Maven will then look in this repository after having searched in the official repository.
Thus, to force the usage of an internal repository, you must configure the mirror in your settings.xml file.
This is explained in the official documentation of Maven.