Maven optional repository
I am converting a project to use Ant/maven-ant-tasks. I have a local repository in $HOME/.m2, an enterprise repository on a local machine on the LAN, and I have listed several global repositories (http://repo2.maven.org/, etc.).
If I am out of the office, is there a way to have Maven skip the enterprise repository in it searching for dependency resolu开发者_JAVA技巧tions?
Thanks.
You can do this by swiching profiles :
<profiles>
<profile>
<id>atWork</id>
<repositories>
<repository>
...
</repository>
</repositories>
</profile>
<profile>
<id>atHome</id>
<repositories>
<repository>
...
</repository>
</repositories>
</profile>
</profiles>
If you're "at home" you can activate your home profile and deactivate the "at work" profile.
You can use this either in your pom.xml (not recommended) or in your ~/.m2/settings.xml (recommended)
Resources :
- Maven - profiles
- Maven - settings.xml
Sadly, there is no particular facility for this in Maven (something like network based settings). If you only need to manage repositories, you can do it with profiles as suggested by @Colin answer. If you need to manage mirror definitions (that you can't declare inside profiles) you are screwed and you'll need to use different settings.xml
, or to edit it, or to script the change. You might want to track MNG-3525. See also the related question below.
Related question
- Make Maven Proxy/Server settings configurable based on location?
精彩评论