Where is the best place to specify required repositories for maven projects, pom.xml or settings.xml? What are the pros and cons of each location? What is best practice?
I'd personally define the repositories required by a particular project in the project pom.xml
because it keeps the build portable. The settings.xml
file should be used for user specific or secret things only in my opinion. No really, asking the user to add repository locations, even if this is properly documented, somehow defeats one of maven's feature (transparent dependency handling) and I don't like this idea.
The only "good" use case I can think of for using settings.xml
to deal with repositories is when you have a corporate repository and want Maven to use this repository instead of public ones. For example, to avoid connections to any public repository, you would declare the corporate repository as a mirror of all of them:
<settings>
...
<mirrors>
<mirror>
<id>proxy-of-entire-earth</id>
<mirrorOf>*</mirrorOf>
<name>Maven Repository Manager running on repo.mycompany.com</name>
<url>http://repo.mycompany.com/proxy</url>
</mirror>
</mirrors>
...
</settings>
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…