How can I stop maven from downloading transitive dependencies?

1

I have a Maven call that downloads artifacts for the purpose of running integration tests:

mvn -Dmdep.useRepositoryLayout=true -Dmdep.copyPom=true -Dmdep.useBaseVersion=true dependency:copy-dependencies -DoutputDirectory=deps -DexcludeTransitive=true -e

The pom consists purely of dependencies, nothing else. There are other scripts that pick up the artifacts from the deps dir and runs tests on them.

Now, my problem is this: Even though Maven only copies the artifacts I want into deps, it still downloads all transitive dependencies to the Maven cache, which is a waste of time and bandwidth (the artifacts are compiled on another continent).

Is there some way I can stop maven from downloading all the transitive dependencies into the cache?

Maven 3.0.4

Solutions using other tools like gradle or ant+ivy are also welcome, as long as they can create the maven repo layout in deps.

clacke

Posted 2013-07-18T09:42:57.957

Reputation: 218

Answers

1

Maven has limited facilities to control dependency scope and the documentation is not the best. Here are a few for reference:

Paul Sweatte

Posted 2013-07-18T09:42:57.957

Reputation: 613

I do want to look for and download the latest versions of the direct dependencies though. It seems that offline mode would prevent any downloads at all from happening. – clacke – 2013-07-29T19:31:03.767

There's an option to update snapshots while remaining offline in that case.

– Paul Sweatte – 2013-07-29T23:15:35.240

No, --update-snapshots is a different issue, that's how often (always, rather than once per day) it rechecks whether snapshots existing in the .m2 cache have been updated upstream. But offline is still offline. – clacke – 2013-07-30T07:40:09.743

Actually being offline I get error messages about deep dependencies not existing in my local cache, even though I do not want them. So offline is not the way to go anyway. – clacke – 2013-07-30T07:41:07.137

Thanks. It looks like dependency exclusion is what you need.

– Paul Sweatte – 2013-07-31T00:17:42.187

It does look like dependency exclusion is the terribly explicit, brittle and cumbersome way to solve this problem in Maven. :-) – clacke – 2013-07-31T09:07:24.193

I've updated the answer. Good question. – Paul Sweatte – 2013-08-02T19:21:59.200