I am reading the apache maven instruction about how to deploy eclipse project and how to configure pom.xml and .m2/settings.xml for this purpose...
pom.xml
[...]
<distributionManagement>
<repository>
<id>internal.repo</id>
<name>MyCo Internal Repository</name>
<url>Host to Company Repository</url>
</repository>
</distributionManagement>
[...]
and the .m2/settings.xml
[...]
<server>
<id>internal.repo</id>
<username>maven</username>
<password>foobar</password>
</server>
[...]
the thing is the settings.xml is just one file which is about to contain the repo id to login etc...
so my question is... is there a way to switch in eclipse between maven projects (dedicated for deployment) and not to edit the settings.xml (the ticket) for each project in separate?
Thanks
I'm not quite sure what are you asking. And I don't really know what Eclipse has to do with it.
If I understand correctly, your concern is that different project will need to use different repositories. If so, just configure all the repositories in the servers section of your settings.xml. Then each POM can reference the server it needs by its ID.
If that is not what you are asking, please update the question to explain exactly what you are trying to do and what is the problem you are facing.
I came across the notorius situation of jar-references, which are not available through any public repositories. And I am trying this solution: by Brett Porter 28/Mar/11 9:00 AM
So I checked out http://svn.apache.org/repos/asf/maven/sandbox/trunk/examples/extensions/bundled-repository-extension, built it with IDEA and put resulting bundled-repository-extension-1.0-SNAPSHOT.jar directly into C:\Program Files\Apache Software Foundation\apache-maven-3.0.4\lib\ext
Now I am trying to use it like shown here. But IntelliJ IDEA is always highlighting in red that it can't find this build extesnion:
<build>
<extensions>
<extension>
<groupId>org.apache.maven.examples</groupId>
<artifactId>bundled-repository-extension</artifactId>
<version>1.0-SNAPSHOT</version>
</extension>
</extensions>
</build>
How can I help it find the build extension?
This extension is not found on maven central either. Possible resolutions:
locate remote repository hosting necessary snapshot and enable it insettings.xml
install this extension into your local repository manually
set up your own repository server ( sonatype nexus is good choice ) and upload this extenstion there
One it is available for your maven commandline build IDEA will find it.
Is there a way to change the version number without editing the POM?
<groupId>org.example</groupId>
<artifactId>example</artifactId>
<version>1.0.0</version>
We have a CI system where we want to release nightly builds, but without using the -SNAPSHOT solution of Maven, so if 1.0.0 is the current version, we just want to have CI-NIGHTLY-BIULD-20120426.
I suggested this would be possible with something like mvn deploy -Dversion=CI-NIGHTLY-BIULD-20120426, but obviously not. The bad solution would be to let the CI server edit the pom.xml every time, but I think this is very unhandy.
Thank you!
I suggest to use classifier.
<groupId>foo</groupId>
<artifactId>bar</artifactId>
<version>1.0</version>
<properties>
<!-- default classifier is empty -->
<my.project.classifier></my.project.classifier>
</properties>
<build>
...
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.3.1</version>
<configuration>
<classifier>${my.project.classifier}</classifier>
</configuration>
<executions>...</executions>
</plugin>
</plugins>
</build>
and
mvn package -Dmy.project.classifier=NIGHTLY-2012-04-26_02-30
Maven documentation says about classifier:
classifier: You may occasionally find a fifth element on the
coordinate, and that is the classifier. We will visit the classifier
later, but for now it suffices to know that those kinds of projects
are displayed as groupId:artifactId:packaging:classifier:version.
and
The classifier allows to distinguish artifacts that were built from
the same POM but differ in their content. It is some optional and
arbitrary string that - if present - is appended to the artifact name
just after the version number. As a motivation for this element,
consider for example a project that offers an artifact targeting JRE
1.5 but at the same time also an artifact that still supports JRE 1.4. The first artifact could be equipped with the classifier jdk15 and the
second one with jdk14 such that clients can choose which one to use.
Another common use case for classifiers is the need to attach
secondary artifacts to the project's main artifact. If you browse the
Maven central repository, you will notice that the classifiers sources
and javadoc are used to deploy the project source code and API docs
along with the packaged class files.
I think you could also use versions maven plugin. I find it quite useful for things like this.
You could do it in 2 steps:
set necessary version: mvn versions:set -DnewVersion=CI-NIGHTLY-BIULD-20120426
deploy: mvn deploy
in case you need to revert back the changes, use mvn versions:revert (as Mark suggests)
I highly recommend reading Maven Releases on Steroids (part 2, part 3) by Axel Fontaine. It is great, and I'm quite happy using it.
It not only details how you con do what you ask, but also contains good advice how you can tie your build versions with your CI server.
In a nutshell, here are the main points:
Maven Release is slow, needs to be done faster
You parametarize your project version like
<version>${VERSION_NUMBER}</version>
...
<properties>
...
<VERSION_NUMBER>1.0-SNAPSHOT</VERSION_NUMBER>
...
</properties>
Local builds get that version: 1.0-SNAPSHOT
Release builds are done only from your CI server
In your Jenkins/Hudson project configuration you use
clean deploy scm:tag -DVERSION_NUMBER=${BUILD_NUMBER}
That way you get a new release with each Jenkins build, not only nightly.
You can change the configuration to use
clean deploy scm:tag -DVERSION_NUMBER=1.0.0-CI-NIGHTLY-BIULD-${BUILD_ID}
and you would get versions like 1.0.0-CI-NIGHTLY-BIULD-2012-04-26_12-20-24
You could parameterize the version number as
<groupId>foo</groupId>
<artifactId>bar</artifactId>
<version>${my.project.version}</version>
<properties>
<my.project.version>1.0</my.project.version>
</properties>
and drive the version number from command line using
mvn package -Dmy.project.version=NIGHTLY
Although this is possible, Maven 3 discourages it.
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