tags:

views:

188

answers:

4

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?

A: 

Have you tried the offline mode?

mvn -o
Valentin Jacquemin
I still want maven to download all the other artifacts from the remote repo. I mean... normal behaviour except for *some* specified artifacts.
mgv
A: 

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.

Rich Seller
I have a similiar issue. My problem is that I have a couple of Maven artifacts that my company has created and which only exist in my local repository. When I perform a full build, Maven will attempt to re-download the artifacts from the central repository. It will always fail and it is delaying my build process. How can I tell Maven to never attempt to download the private artifacts from the central repository.Is that the problem that mgv is trying to solve?
Ben Hammond
+3  A: 

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.

Ken Liu
That was exactly what I was looking for. Thanks!
mgv
keep in mind that this is deprecated. I would suggest you install a copy in your local repos with a different name. Pre-pending "local." to the group and artifact name would make it easy to id in the pom files.
sal
sorry, I wasn't aware that this was deprecated. As usual, the maven docs are no good :(
Ken Liu
A: 

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>
sal