I've used maven for a while in common way with settings out of the box, so I understand what it is but I'm newbie in maven settings.
I need to organize such workflow:
I have idea how to do it:
My question is: How to use simple directory on filesystem as proxy repository for certain projects? Tell me please how to realize this idea or give me another idea to realize such workflow.
I can just commit local repository, but there are some limitations:
I test local directory to deploy projects, simple by writing "file://testRespoDir" in repo url, but I can't understand how to make this directory proxy all remote artefacts for project(project must not use local repo and use only common directory.
You can use the Maven Dependency Plugin to download dependencies. Run mvn dependency:copy-dependencies , to download all your dependencies and save them in the target/dependency folder. You can change the target location by setting the property outputDirectory .
The go-offline goal of the Maven Dependency plugin downloads all the required dependencies and plugins for the project, based on the pom file. The –o option tells Maven to work offline and not check the Internet for anything.
When you run a Maven build, then Maven automatically downloads all the dependency jars into the local repository. It helps to avoid references to dependencies stored on remote machine every time a project is build.
Maven's local repository is a directory on the local machine that stores all the project artifacts. When we execute a Maven build, Maven automatically downloads all the dependency jars into the local repository. Usually, this directory is named . m2.
I found simple and perfect solution: POM include 2 repositories:
<repositories>
<repository>
<id>commonDep</id>
<name>common dependency</name>
<url>file://../common/repository</url>
</repository>
<!-- it used when collect dependencies before commit. If developer already download dependency, get it from local repo, save traffik and time -->
<repository>
<id>localPlugins</id>
<name>local plugins</name>
<url>file://${user.home}/.m2/repository</url>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>commonDep</id>
<name>common dependency</name>
<url>file://../common/repository</url>
</pluginRepository>
<!-- it used when collect dependencies before commit. If developer already download dependency, get it from local repo, save traffik and time -->
<pluginRepository>
<id>localPlugins</id>
<name>local plugins</name>
<url>file://${user.home}/.m2/repository</url>
</pluginRepository>
</pluginRepositories>
when developer opens project, he use local, common and central repositories in such order. It saves his traffic. When he finished work, he call script:
mvn dependency:go-offline -Dmaven.repo.local=../common/repository
all current dependencies of project copyed from his default local repository to common repository. Then developer commit common.
When we run build on teamcity, we checkout project and common and run it. There is no internet connection, but all dependencies exist in common repository.
Yeah you can do this personally i wouldn't recommend it especially if you're using SNAPSHOT's however you should be able to.
So what you want to do is create a network drive (i dont know whether your on windows or linux but it dont matter).
Then mount that network drive on all systems which require it.
Then in maven config file specify the local maven repo location:
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0
http://maven.apache.org/xsd/settings-1.0.0.xsd" >
<localRepository>c:/mvn-repo/</localRepository>
...
</settings>
Replace c:/mvn-repo/ with path to your the directory on the network drive you wish to use.
You can place this config in various places but i would suggest placing it in the root config file which lives @ ${MAVEN_HOME}/conf/settings.xml.
You will need to specify this on each computer which is using maven.
Then that should do it and all your maven run times will share the same local repo.
So how to get round different projects using different directories? Thats a tricky one you could use different directories on network drive and change the localRepository variable @ run time by specifying it as a runtime property.
mvn -Dmaven.repo.local=$HOME/.my/other/repository clean install
That way you would have it all parceled up nicely one network drive with a directory for each project then simply specify that variable @ run time to set which local repo to use.
The flow you propose won't scale. I would rather set up a local corporate mirror of the central repository and have both developers and automation servers (teamcity etc.) use it. Trivial to set up, easy to maintain, easy to track dependencies on the third party software and put restrictions in place.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With