my problem with maven is that if the maven repository is not responding, one cannot build. It seems to fetch every "mvn package" time some poms, which won't change, because they are of the same version.
How can I say to maven that please don't look them up from server, and instead download them permanetly to offline repository?
Thanks!
You can run maven with the -o flag:
-o,--offline Work offline
This will cause Maven to never look for dependencies in remote repositories. On the other hand, your build will fail if the dependencies are not found in the local repository.
You can configure the repository to only check for updates occasionally, or never by setting the updatePolicy element on the repository declaration. From the settings documentation:
The frequency for downloading updates - can be "always", "daily" (default), "interval:XXX" (in minutes) or "never" (only if it doesn't exist locally).
Adding the following to your POM or the settings will configure the central repository to only download if the artifact doesn't exist locally:
<repositories>
<repository>
<id>central</id>
<releases>
<updatePolicy>never</updatePolicy>
</releases>
</repository>
</repositories>
If the repository in question is an internal remote repository, you need to ensure the maven-metadata.xml is configured correctly in the remote repository or Maven will attempt to download it each time. The simplest way to do this is to use a repository manager that will manage the metadata automatically
Related
Why is maven downloading dependencies from repository even if the jar exists on my local repository(one reason could be that jar doesn't have a pom), is there a way to get bypass that except with the -o option?
Why is maven downloading [SNAPSHOT] dependencies from repository even if the jar exists on my local repository
Because that's the expected behavior with SNASPSHOT dependencies. Unlike fixed versions, Maven will periodically try to download the most recent version of a given SNAPSHOT. That's extremely useful when you're depending on a project that is under active development. From the Maven Reference:
3.3.1.2. SNAPSHOT Versions
Maven versions can contain a string
literal to signify that a project is
currently under active development. If
a version contains the string
“SNAPSHOT,” then Maven will expand
this token to a date and time value
converted to UTC (Coordinated
Universal Time) when you install or
release this component. For example,
if your project has a version of
“1.0-SNAPSHOT” and you deploy this
project’s artifacts to a Maven
repository, Maven would expand this
version to “1.0-20080207-230803-1” if
you were to deploy a release at 11:08
PM on February 7th, 2008 UTC. In other
words, when you deploy a snapshot, you
are not making a release of a software
component; you are releasing a
snapshot of a component at a specific
time.
Why would you use this? SNAPSHOT
versions are used for projects under
active development. If your project
depends on a software component that
is under active development, you can
depend on a SNAPSHOT release, and
Maven will periodically attempt to
download the latest snapshot from a
repository when you run a build.
Similarly, if the next release of your
system is going to have a version
"1.4", your project would have a
version "1.4-SNAPSHOT" until it was
formally released.
As a default setting, Maven will not
check for SNAPSHOT releases on remote
repositories. To depend on SNAPSHOT
releases, users must explicitly enable
the ability to download snapshots
using a repository or pluginRepository
element in the POM.
When releasing a project, you should
resolve all dependencies on SNAPSHOT
versions to dependencies on released
versions. If a project depends on a
SNAPSHOT, it is not stable as the
dependencies may change over time.
Artifacts published to non-snapshot
Maven repositories such as
http://repo1.maven.org/maven2 cannot
depend on SNAPSHOT versions, as
Maven's Super POM has snapshot's
disabled from the Central repository.
SNAPSHOT versions are for development
only.
If you really want to change this behavior, you can change the updatePolicy of your snapshot enabled repository:
<repositories>
<repository>
<id>my-repo</id>
<name>My Corporate Repository</name>
<url>http://repo.mycompany.com/maven2</url>
<layout>default</layout>
...
<snapshots>
<enabled>true</enabled>
<updatePolicy>never</updatePolicy>
<checksumPolicy>fail</checksumPolicy>
</snapshots>
</repository>
Switching to never will force you to use a manual update (using mvn -U). But beware, this is usually not what people want and expect with SNAPSHOTs.
For the record, Maven 3 has a -nsu, --no-snapshot-updates command line option allowing to Suppress SNAPSHOT updates.
See also
3.2. The POM
Repositories in the POM reference
You could generate a pom in your local repository by installing the file manually:
mvn install:install-file
-Dfile=[FILE]
-DgroupId=[GROUP]
-DartifactId=[ARTIFACT]
-Dversion=[VERSION]
-Dpackaging=jar
-DgeneratePom=true
-DcreateChecksum=true
EDIT: You wouldn't want to do this for snapshots.
I want to setup jetty with jetty-blazeds extension. Everything looks fine but when I run maven to get the dependencies, I get:
UNRESOLVED DEPENDENCIES
com.adobe.flex#flex-messaging-core;3.2.0: not found
com.adobe.flex#flex-messaging-common;3.2.0: not found
I've tried many repositories but no success. I am wondering has anyone managed to successfully locate these dependencies through maven ? If yes, could you please share the repository !
Thank you,
-A
If you look at the pom of jetty-blazeds, for example jetty-blazeds-7.0.0.1beta3.pom, you'll see this:
<repositories>
<repository>
<id>project-repo</id>
<name>project repo</name>
<url>file:${basedir}/maven_repo</url>
<releases><enabled>true</enabled></releases>
<snapshots><enabled>true</enabled></snapshots>
</repository>
</repositories>
Jetty is using a file based repository. And if you look at this file based repository in their svn repository, you will see that it contains the mentioned artifacts (which are thus very likely not available in any known public repository).
So my suggestion would be to use the same strategy i.e. to install the artifacts locally, either in your local repository or in a file based repository in your VCS (you could also declare https://svn.codehaus.org/jetty/jetty/branches/jetty-7/jetty-blazeds/maven_repo/ as repository but this is extremely ugly).
If you have a corporate repository, the alternative is obvious: deploy the adobe artifacts in it.
It is recommended to set up a central Maven repository for your project/department and configure it in the project pom. Then you can download such dependencies by hand and deploy them manually to the project repo. Although this is a bit more extra work, it eliminates the whole class of problems in the long run.
How can i make a project jar release and maven repository strucuture(md5hash,distribution pom,etc) to put this in my own repository? Maven have a plugin to do it? Note, i need to generate this structure in my local machine, i don't have CI and others to do it!
Hopes!!!
Check the deploy plugin, I think this is what you're looking for. Quoting the documentation:
As a repository contains more than the artifacts (POMs, the metadata, MD5 and SHA1 hash files...), deploying means not only copying the artifacts, but making sure all this information is correctly updated. It's the reponsibility of the deploy plugin.
You'll need to declare a <distributionManagement> element to use it, something like this:
<distributionManagement>
<repository>
<id>internal.repo</id>
<name>MyCo Internal Repository</name>
<url>Host to Company Repository</url>
</repository>
</distributionManagement>
Where the url can be a "local" file://.
And if the question is about installing a (third party) jar in your local repository (the question is not totally clear), have look at the Maven Install Plugin, install:install and install:install-file both admit a createChecksum optional parameters.
I have Maven on Ubuntu server.
It seems to try lots and lots of places to download from but the download times out, but the timeout takes ages, so my whole build takes more than a hour.
Downloading: http://scala-tools.org/repo-releases/org/apache/maven/maven-repository-metadata/2.0.3/maven-repository-metadata-2.0.3.pom
[INFO] Unable to find resource 'org.apache.maven:maven-repository-metadata:pom:2.0.3' in repository scala-tools.org (http://scala-tools.org/repo-releases)
Downloading: http://download.java.net/maven/2/org/apache/maven/maven-repository-metadata/2.0.3/maven-repository-metadata-2.0.3.pom
[WARNING] Unable to get resource 'org.apache.maven:maven-repository-metadata:pom:2.0.3' from repository java.net (http://download.java.net/maven/2): Error transferring file: Connection timed out
Downloading: http://download.java.net/maven/1/org.apache.maven/poms/maven-repository-metadata-2.0.3.pom
[WARNING] Unable to get resource 'org.apache.maven:maven-repository-metadata:pom:2.0.3' from repository m1.java.net (http://download.java.net/maven/1): Error transferring file: Connection timed out
Downloading: http://download.java.net/maven/2/org/apache/maven/maven-repository-metadata/2.0.3/maven-repository-metadata-2.0.3.pom
[INFO] Unable to find resource 'org.apache.maven:maven-repository-metadata:pom:2.0.3' in repository maven2-repository.dev.java.net (http://download.java.net/maven/2)
Downloading: http://repository.jboss.org/maven2/org/apache/maven/maven-repository-metadata/2.0.3/maven-repository-metadata-2.0.3.pom
[INFO] Unable to find resource 'org.apache.maven:maven-repository-metadata:pom:2.0.3' in repository repository.jboss.org (http://repository.jboss.org/maven2)
Downloading: http://repo1.maven.org/maven2/org/apache/maven/maven-repository-metadata/2.0.3/maven-repository-metadata-2.0.3.pom
I only have two repos set in my maven build
<repository>
<id>central</id>
<name>Maven Repository Switchboard</name>
<layout>default</layout>
<url>http://repo1.maven.org/maven2</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
<repository>
<id>maven2-repository.dev.java.net</id>
<name>Java.net Repository for Maven</name>
<url>http://download.java.net/maven/2</url>
</repository>
<repository>
<id>repository.jboss.org</id>
<name>JBoss Repository</name>
<url>http://repository.jboss.org/maven2</url>
</repository>
Thanks, philip
It seems that Ubuntu's packaged Maven version comes with a /etc/maven2/settings.xml. Have a look at this file to see if it contains additional repositories. Also check the file ~/.m2/settings.xml of the user you are using.
PS: I don't really like using .deb for this kind of software and recommend installing it "manually" (i.e. just download the archive, unzip it somewhere, set the M2_HOME env variable and add $M2_HOME/bin to the $PATH).
Maybe overkill if you're the only one working on the project but I'd recommend installing a Maven repository manager like Artifactory (http://www.jfrog.org/products.php) or Nexus. I'm not familiar with Nexus but Artifactory installation is dead simple - just unzip and you're good to go (since it comes with an embedded jetty).
Why will this make your Maven builds faster ?
Repository managers employ more sophisticated caching than the Maven core itself
(at least with Artifactory) You can restrict which Maven repositories are queried for which group IDs. This speeds up things considerably if you need to fetch dependencies from multiple different Maven repositories
Make sure you can access these resources (in your case the POMs) outside of Maven, if the machine has no network connectivity for example (or can't resolve hostnames), it will time out, and it will take a long time (as you noted).
If you don't need to re-download the resources every time, just run Maven in the "offline" mode with the -o switch.
Also, just a tip, you may want to create and install POMs, even for third party JARs, and then get them in your local repo. That way Maven will not have to go out to the tubes to get resources each time (it will check em, but they will be resolved locally).
For third party or otherwise non Maven JARs you can install then with the install plugin.
I have a remote repository which updates the jar once in 5 hours without changing the version number.Pom file is not able to update as the version is same.Each time I need to manually delete.Is there any way i can get the latest files using the settings.xml.
Do you control this remote repository? If yes, then use a "-SNAPSHOT" version number.
Or ask the people who do control the repository to do that. It's the correct way to tell Maven that the dependency is in a state of flux.
And if you're unable/unwilling to do that, write yourself a batch/shell script to invoke Maven, which deletes the file beforehand.
I have a remote repository which updates the jar once in 5 hours without changing the version number. Pom file is not able to update as the version is same. Each time I need to manually delete. Is there any way i can get the latest files using the settings.xml.
No, there is no way to achieve this. Once an artifact with a fixed version (as opposed to SNAPSHOT) has been downloaded, it won't be downloaded again, unless you remove it from your local repository. Actually, re-releasing a jar without changing its fixed version number is an EVIL practice and must be avoided. This is just not how maven works and when doing this, it's impossible to predict which version people are really using (without asking them to explicitly remove the jar from their local repository which is a very weak practice) and this will lead to unpredictable results.
The right way to handle frequent releases is either to change the version number (and updating POMs accordingly) or to use a SNAPSHOT version which is the common approach used during development. By definition, SNAPSHOT version will be downloaded if a newer version is made available in the remote repository. This is what you are looking for and this is the maven way to manage this situation. For more details about SNAPSHOT, see the chapter 9.3.1.2. SNAPSHOT Versions of Maven: The Definitive Guide.
You can set element updatePolicy to always for a repository in your settings.xml:
<profiles>
<profile>
<id>default</id>
<repositories>
<repository>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
</snapshots>
<id>snapshots.jboss.org</id>
<name>Snapshot JBoss Repository for Maven</name>
<url>http://snapshots.jboss.org/maven2/</url>
<layout>default</layout>
</repository>
</repositories>
</profile>
</profiles>