-1

I've got a collection of projects that all have a large third party dependency in common, it seems like a waste of space to copy this jar to all the projects during the build, is it possible to have maven just create a hard or soft link to a single cached copy?

This is not a duplicate of Maven multi-module: aggregate common dependencies in a single one? which relates to how to manage common dependencies from a pom perspective. This is about how to avoid copying the same dependent files to the target of multiple projects and just creating links to a single instance to save space.

Simpler version of the question is: is there an equivalent to the maven-dependency-plugin's copy-dependencies goal that creates links vs. copying the files.

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-dependency-plugin</artifactId>
    <version>2.4</version>
    <executions>
        <execution>
            <id>copy-dependencies</id>
            <phase>package</phase>
            <goals>
                <goal>copy-dependencies</goal>
            </goals>
        </execution>
    </executions>
</plugin>
Community
  • 1
  • 1
JR GD
  • 1
  • 3
  • Did you have a look at: https://maven.apache.org/guides/mini/guide-multiple-modules.html – Adonis Mar 10 '17 at 13:07
  • 2
    Possible duplicate of [Maven multi-module: aggregate common dependencies in a single one?](http://stackoverflow.com/questions/6086774/maven-multi-module-aggregate-common-dependencies-in-a-single-one) – Beck Yang Mar 10 '17 at 13:22
  • OK, so you're doing it yourself. The next obvious question is "why?" but you don't tell us that. I'm not sure if you think that you'd be giving away corporate secrets by describing your entire build process, or if you think that "everybody does this" and assume that we all know what you're trying to accomplish. If the latter, the answer is no; people do not normally copy their dependencies into the build directory. – kdgregory Mar 11 '17 at 14:02
  • On the other hand, if there _is_ a reason why you're doing this, then you'll need to tell us the reason. Otherwise any answers you get will be irrelevant. I recommend deleting this question and creating a new one that (1) shows your POM, and (2) explains what you're doing with the dependencies that you copy. You may get an alternative approach, or you may not (and really, unless we're talking gigabytes of dependencies, it's probably not that bad). – kdgregory Mar 11 '17 at 14:04
  • The reason is that there's a dependency that's a few hundred MBs in size and it's required by each module. Copying it for each module means that during packaging, I need about 15Gb of space, when in reality I should only need about 1. – JR GD Mar 11 '17 at 18:44

1 Answers1

0

Yes, Maven already does. It puts all your dependencies in your .m2/repository/... folder. In Windows it's c: \ Users \ [your_name] \ .m2 \ repository. So there is no need for linking it with simlinks or st like that. Just have your maven project search for the dependencies in your maven repository and your dependencies will be reused by all projects which need these dependencies. If you use the same maven all the time, the Maven settings are the same and for every project your repository folder is the same, so you're done already.

Al different jars are saved here, so every single version you depend on. If more pojects depend on the same dependency, with the same version, it's that one jar being used for all your projects.

You can remove all dependencies and reïmport your dependencies, if you used an old version before, and you use a newer version now, you just deleted the old version, and the new one is back where it's needed.

Jeroen van Dijk-Jun
  • 1,028
  • 10
  • 22
  • You're talking about a different thing. During building it copies those dependencies to the various project target folder, I want it to just link them so I don't have 20 copies of the same file. That's what this question is about. – JR GD Mar 10 '17 at 23:57
  • @JRGD - no, actually it does _not_ copy the dependencies, unless you're producing a WAR or shaded JAR, and then there's no way around copying because you're intentionally combining dependencies into a deployable module. If you're seeing dependencies copied during a normal `jar` build, then there's something wrong with your POM. Please edit your question to include your POM _and a listing of the `target` directory that shows the behavior you claim to see_. – kdgregory Mar 11 '17 at 00:07
  • During the packaging, the maven-dependency-plugin executes copy-dependencies, I'm looking for something like link-dependencies instead. – JR GD Mar 11 '17 at 00:12