Reputation: 3019
I been facing some issues with settings.xml
. Actually the problems is at work place I need to point to different repository on our VPN, while in case of trying out new examples I want to ignore the settings.xml
with repository server configured on VPN. Is there a way I can do it? Currently what I am doing is I just simply change the name of settings.xml
to settings.xml1
and it works. But I am tired of doing such changes.
One thing my fellow colleague doing is keeping the settings.xml in project itself. Which I don't like as it is maven repository configuration and it should not be kept in project itself. For the same thing I got similar reference from quick start guide as well. From official documentation on settings:
The settings element in the settings.xml file contains elements used to define values which configure Maven execution in various ways, like the pom.xml, but should not be bundled to any specific project, or distributed to an audience.
If you have any solution to this feel free to answer.
Upvotes: 2
Views: 1969
Reputation: 27812
If repositories are defined in your settings.xml
file, they are hence defined in a profile, which I guess is active by default, applying the standard approach suggested on the official documentation. Let's say this profile is called vpn-rep
(via its id
element).
You could then add a second profile which declares any repository you want and not be active by default. So, no impact. You can call it my-rep
.
Then, since they are profiles, you can easily switch from one to another from command line as following:
mvn clean install -P!vpn-rep,my-rep
The -P!vpn-rep,my-rep
part will actually switch off the vpn-rep
profile (and as such maven will not use the repositories declared on it, that is, no VPN repository will be used) and will switch on the my-rep
one.
If you are actually not configuring any additional or special repository and you just don't want to use the VPN one, you can skip the creation of the second profile and switch off only the first one (-P!vpn-rep
), Maven will then use the default repository.
An example of how such a settings.xml
file may look like:
<settings>
<profiles>
<profile>
<id>vpn-rep</id>
<repositories>
<repository>
<id>central</id>
<url>http://your-vpn-company-repository/libs-releases</url>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
...
</pluginRepository>
</pluginRepositories>
</profile>
<profile>
<id>my-rep</id>
<repositories>
<!-- any specific repository configuration here -->
</repositories>
<pluginRepositories>
...
</pluginRepositories>
</profile>
</profiles>
<activeProfiles>
<activeProfile>vpn-rep</activeProfile>
</activeProfiles>
</settings>
Upvotes: 2
Reputation: 7940
I presume that you have a private (internal artifacts) and public repository. If this is the case, simply add both to your settings file, it will look in each repository in the order given
See https://maven.apache.org/guides/mini/guide-multiple-repositories.html
Upvotes: 0