Maven tries to download dependency despite it existing in local repository - maven-2

I have an installed dependency in my local repository. The remote repository where the dependency came from is now down for some reason. When I try to compile the project Maven says that it can't resolve dependency. But why???

When you have these error, simply clean the _remote.repositories that indicate maven where the dependency comes from. You will find this file for each artifact inside your M2_REPO.

Maven will compare the local POM's timestamp (stored in a repository's maven-metadata file) to the remote. When maven does this depends on the updatePolicy that can be defined in your settings xml.
Either set this to never (discouraged) or skip this check (only when a remote repository appears to be down) by using the -o option (offline); then maven will not check remote repositories.

Related

Why does maven use my internal repository before my local repository?

when I am doing development I often need to change a dependency, but I'm not ready to deploy my changes. For example, I'm working on project Foo and I realize I need to add a method to the common library. Before deploying this change to our internal repository, I would like to install the changes to common library (mvn install) and recompile Foo to use the common library in the local repository (note that I'm using all SNAPSHOT versions).
However, after I mvn install my common library, when I recompile Foo it doesn't use the new common library--it keeps using the latest SNAPSHOT of common library in the internal repository. If I deploy the changed common library, Foo picks it up immediately.
How can I get maven to look first in the local repository?
UPDATE: when the file is installed into the local repository, it gets a name like foo-1.0.0-SNAPSHOT.jar, but when I deploy it, it gets a timestamp foo-1.0.0-20111104.191316-23.jar. I think this is why the remote artifact gets pulled each time. Any idea why mvn install is not working like mvn deploy? Does it have to do with the fact that I have a snapshot repository set up for deploy?
By default, Maven checks for new versions of SNAPSHOT artifacts once per day. When it does this check, it will download SNAPSHOTS from remote repos that are newer than what you have locally. Either your artifact timestamps are out of sync and you're doing something to override Maven's update policy (like calling it with -U or setting the udpatePolicy to "always"), or else the local repository you're installing the artifact to isn't the same one you're subsequently running Maven against. What you're describing isn't typical Maven behavior. For a better answer, give more details in your question.
One indicator you can look for: after you install your common artifact, when you next compile Foo, does Maven download the common artifact again? If so, then it really is getting it from the remote, and you need to check your update settings. If not, then you have something strange going on locally.
You can try this option. This worked for me.
In your project's main pom.xml change 'snapshots' enabled setting to 'false'.
<repository>
<id>yourRepo</id>
<name>Repository</name>
<url>http://your.repo.com/repo</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>

Maven 2 - 'mvn test' does not find internal project plugin dependency

I have a multi-module maven project (maven 2.2.1).
One of the module is a maven plugin.
This plugin is bound to the compile phase of another module, and added as a direct dependency to trigger correct reactor ordering of module's building.
If I run 'mvn clean install' on the root module, with a fresh local repository, everything goes fine (build, test, install). (I precise that my project's artifacts are not deployed anywhere, only installed locally in my machine's local repo).
BUT if I delete my local repository, and perform 'mvn test', the plugin module is reported as missing ? Whereas, the build order is correct, the plugin module is built succesfully before the module using it ???
Is there any special treatment of maven module with 'maven-plugin' packaging ?
I don't understand why other project inter modules dependencies are resolved correctly and not this specific one !
The problem is that a Maven Plugin must be installed into the local repository first before you can use a plugin as a dependency (or better be part of the life-cycle).

Gradle: Make a 3rd party jar available to local gradle repository

currently, I'm testing Gradle as an alternative to Maven. In my projects, there are some 3rd party jars, which aren't available in any (Maven) repositories. My problem is now, how could I manage it to install these jars into my local .gradle repository. (If it's possible, I don't want to use the local Maven repository, because Gradle should run independently.) At the moment, I get a lot of exceptions because of missing jars. In Maven, it's quite simple by running the install command. However, my Google search for something similar to the Maven install command wasn't successful. Has anybody an idea?
you can include your file system JAR dependencies as:
dependencies {
runtime files('libs/a.jar', 'libs/b.jar')
runtime fileTree(dir: 'libs', include: '*.jar')
}
you may change runtime for compile/testCompile/etc..
A more comprehensive answer was given on a mailing list by Adam Murdoch at http://gradle.1045684.n5.nabble.com/Gradle-Make-a-3rd-party-jar-available-to-local-gradle-repository-td1431953.html
As of April 2010 there was no simple way to add a new jarfile to your ~/.gradle repository. Currently researching whether this has changed.
As of October 2014, this is still the case--because gradle does an md5 checksum of your jarfile, you can't simply download it and put it into a directory under .gradle/caches, and gradle doesn't, as far as I can tell, have any tasks which let you take a local file and push that file to its cache.
Used option (1) out of Adam Murdoch post (already linked above: http://gradle.1045684.n5.nabble.com/Gradle-Make-a-3rd-party-jar-available-to-local-gradle-repository-td1431953.html) with gradle-1.3 and it works just nicely!
Here his comment:
Copy the jars to a local directory and use a flatDir() repository to use them out of there. For example, you might copy them to
$projectDir/lib and in your build file do:
repositories {
flatDir(dirs: 'lib') }
The files in the lib directory must follow the naming scheme:
name-version-classifier.extension, where version and classifier are
optional. So, for example you might call them groovy-1.7.0.jar or even
groovy.jar
Then, you just declare the dependencies as normal:
dependencies {
compile 'groovy:groovy:1.7.0' }
There's a little more detail one flatDir() repository at:
http://gradle.org/0.9-preview-1/docs/userguide/dependency_management.html#sec:flat_dir_resolver
Similar to the above, but using an ivy resolver instead of flatDir(). This is pretty much the same as the above, but allows a
lot more options as far as naming and locations go.
There's some detail at:
http://gradle.org/0.9-preview-1/docs/userguide/dependency_management.html#sub:more_about_ivy_resolvers
Don't bother with declaring the dependencies. Just copy the jars to a local directory somewhere and add a file dependency. For example,
if the jars are in $projectDir/lib:
dependencies {
compile fileTree('lib') // this includes all the files under 'lib' in the compile classpath }
More details at:
http://gradle.org/0.9-preview-1/docs/userguide/dependency_management.html#N12EAD
Use maven install to install the dependencies into your local maven cache, and the use the maven cache as a repository:
repositories {
mavenRepo(urls: new File(System.properties['user.home'], '.m2/repository').toURI().toURL()) }
Maybe I'm missing something from my reading of your question, assuming your gradle repo is of the flatDir type, you should be able to copy the files there in the form myjar-1.0.jar and resolve them as myjar of version 1.0.
Not sure why should it be necessary for Gradle to run maven in order to access a local maven repository. You can just define the maven repos and it should resolve dependencies. You can use gradle upload to push the jars local or remote maven repos if you need to. In that case, it will execute maven.
In short: deploy to repository manager. It can local, on company LAN.
An altogether different way of thinking about this type of problem, specially if it happens often, is to use a repository manager. There are some great open source options out there such as Artifactory, Nexus or Archiva.
Lets assume you have a jar file from some dubious origin that needs to be included in your build until you have the opportunity of refactoring it out. A repository manager would allow you to upload the file to your own repository as, for the sake of this example, dubious-origin-UNKNOWN.jar
Then your build.gradle would look something like this:
repositories {
mavenRepo urls: "http://your.own.repository/url";
}
dependencies {
compile "dubious:origin:UNKNOWN";
}
There are a lot of other advantages to using a repository manager such as caching of remote artifacts, remove artifacts from scm, staging releases, more granular user permissions, and so forth.
On the down side, you would be adding a server which carries some maintenance overhead to keep your builds running.
Depends on the size if your project, I suppose.
I think something like this should work:
dependencies {
files('yourfile.jar')
}
Does it work for you?

Maven downloads corrupted Jars

I am running into a maven problem that's killing all my hairs.
So at the beginning all my maven project works fine. And then when I switched to a new computer today and trying to compile them all.
The first error I see from Eclipse is IO error reading jar files from the local maven repository. Then I googled and someone suggested this is some corrupted files, simply delete them and let maven rebuild the repository.
That solves the problem for a while. And then it keeps popping up again and again.
I got tired and removed the whole local repository and did everything all over again. Then I found out the cause:
The maven remote repository is BAD.
So here is part of the console messages.
[INFO] Unable to find resource 'org.apache.ws.commons.axiom:axiom-dom:jar:1.2.8'
in repository eclipse-repo (http://repo1.maven.org/eclipse)
Downloading: https://maven-repository.dev.java.net/nonav/repository//org.apache.
ws.commons.axiom/jars/axiom-dom-1.2.8.jar
373b downloaded (axiom-dom-1.2.8.jar)
[WARNING] *** CHECKSUM FAILED - Checksum failed on download: local = '2c6102c2c3
70e0b993e897e981618ed448651147'; remote = '
The file contains an http redirect.
301 Moved Permanently
Moved Permanently
The document has moved here.
Apache Server at maven-repository.dev.java.net Port 443
I am stuck. How can I get the real dependency jars? How can I tell maven to avoid this? This is really annoying.
There is king of bug in maven, simply because maven does not skip taking an artifact if one
of the maven repo sends a 301(MOVED PERMANANTLY) and it simply take that message and write it as the pom file. Simply if the maven repo sends 404 it skip that repo and go for another, but here with 301 it just dump the message as the pom file and later on this failes.
I assuming you're using Maven 2.2.1? If yes try, to downgrade to Maven 2.2.0 or use additional setting. In 2.2.1 was change in wagon implementation.
Maven 2.2.1 aims to correct several critical regressions related to the selection of the HttpClient-based Wagon implementation for HTTP/HTTPS transfers in Maven 2.2.0. The new release reverts this selection, reinstating the Sun-based - or lightweight - Wagon implementation as the default for this sort of traffic.
However, Maven 2.2.1 goes a step further to provide a means of selecting which provider - or implementation - the user wishes to use for a particular transfer protocol.
So, try run maven with additional params.
mvn -Dmaven.wagon.provider.http=httpclient clean install
One answer: avoid dev.java.net. It's often broken in one way or the other. If you need things from there, install them in a local repository manager.
I've seen this error with IntelliJ IDEA 13.1.5 and Ubuntu 14.04.
Maven 2.2.? saves the 301 response body as a jar file in the ~/.m2 cache, which causes problems later on during the build.
The fix for me was to install Maven 3. Instructions for Ubuntu 14.04 are here:
http://www.sysads.co.uk/2014/05/install-apache-maven-3-2-1-ubuntu-14-04/

Don't download artifact from remote repository

I'd like to specify some artifacts that SHOULD NOT be downloaded from a remote repository, even if they are present there. Is there any way to achieve this in maven2?
Have you tried the offline mode?
mvn -o
Not sure if this is what you need, but you can declare a dependency with system scope, which tells Maven that a particular JAR is assumed to be in the classpath (e.g. one that is included in the java installation directory).
From the docs:
This scope is similar to provided except that you have to provide the JAR which contains it explicitly. The artifact is always available and is not looked up in a repository.
AFAIK, Maven treats the local repository basically as a cache of a remote repository, so there isn't any way to tell it not to get a particular dependency from a remote repo.
I'm not clear exactly what you're after, so here's answers to a few different interpretations:
If the artifacts are transitive dependencies, you can specify that the dependencies be excluded. See the Transitive Dependency Exclusion section of the Dependency Mechanism documentation.
If you want to make sure no artifacts are downloaded, you can set Maven to offline mode by passing -o as a command line switch, or adding <offline>true</offline> to your settings.xml
With the Nexus Maven repository manager, you can set up a proxy repository to the remote repository, and configure the proxy to block certain artifacts. You would do this by adding a "repository target" matching the artifact's groupId and artifactId, then create read permissions for the that target that the Nexus user doesn't have. Any user connecting to the proxy would then not be able to obtain that artifact. See the Nexus book for details, of configuring targets.
If none of these meet your needs can you elaborate on your question please.
One option would be to install a local copy of the file with the install-file mojo and give your copy a distinct name. Pre-pending "local." to the groupid name would make it easy to id in the pom files. If would also make it easy to switch out.
add it to your local repos like this:
mvn install:install-file -Durl=file://xmlthing.jar -Dinternal -Dfile=xmthing.jar -DgroupId=local.org.xmltool -DartifactId=xmlthing -Dversion=1.6.1 -Dpackaging=jar
You would then replace
<dependency>
<groupId>org.xmltool</groupId>
<artifactId>xmlthing</artifactId>
<version>1.6.1</version>
</dependency>
with
<dependency>
<groupId>local.org.xmltool</groupId>
<artifactId>xmlthing</artifactId>
<version>1.6.1</version>
</dependency>