0

I would like maven to store the dependent jars in the project specific lib folder instead of in the default MyUser/.m2/repository/. Not everybody has internet access when he gets the project, and copying the global local repository seems like a less-than-ideal solution.

How do I persuade maven to store and use these dependencies in a local, relative, project specific folder?

Seems my question is a rephrased version of this Stackoverflow question

I did something like this:

    <build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-dependency-plugin</artifactId>
            <version>${mvn-dependency-plugin.version}</version>
            <executions>
                <execution>
                    <id>copy-dependencies</id>
                    <phase>package</phase>
                    <goals>
                        <goal>copy-dependencies</goal>
                    </goals>
                    <configuration>
                        <outputDirectory>${project.basedir}/${local-lib-dir}</outputDirectory>
                        <overWriteReleases>false</overWriteReleases>
                        <overWriteSnapshots>false</overWriteSnapshots>
                        <overWriteIfNewer>true</overWriteIfNewer>
                        <stripVersion>true</stripVersion>
                    </configuration>
                </execution>
            </executions>
        </plugin>
    </plugins>
    <build>

The only downside is, that eclipses maven still refer to the jars in the local repository.

Community
  • 1
  • 1
Stefan K.
  • 7,701
  • 6
  • 52
  • 64

2 Answers2

1

I'm sorry to say that, but if you really like to have a lib folder which contains the dependencies you are working with you are back in Ant times and start also checking in the lib folder into your version control which is really bad.

If you argument that an internet access does not exist you should start using a repository manager like Artifactory, Nexus or Archiva which is installed within the local network and only the repository manager needs the internet connection. Everyone else just uses a version control tool to checkout the sources and can start working with the project.

khmarbaise
  • 92,914
  • 28
  • 189
  • 235
  • a) it to migrate away from ant. b) The build is for training exercises on the clients site without internet at all. – Stefan K. Oct 16 '13 at 19:36
  • If you need to go that way Ok. Just create the build let it run and download all deps into `.m2/repository` or better using a RepoManager in between and afterwards you can either copy the local repo to the appropriate client computer. But better would be to use repo Manager and just transport the repository manager including it's content into the network of the client and this will give you opportunity to run the build as usual on users computer. But maven without internet is not really working. – khmarbaise Oct 16 '13 at 19:56
0

You can manage your external dependencies like this:

<dependency>
    <groupId>mydependencygroup</groupId>
    <artifactId>my.artifact</artifactId>
    <scope>system</scope>
    <version>1.0</version>
    <systemPath>${basedir}\src\lib\myartifact.jar</systemPath>
</dependency>

The lib folder is inside your src folder.

Hope it hepls.

Gerard Ribas
  • 717
  • 1
  • 9
  • 17