0

I am currently working on several projects each one of them has different artifactory settings. So, when switching between them I have to go to maven folder and change settings file to correspond to correct corporate repository. I'm pretty sure that it is ineffective and most likely someone already have a simple solution for this problem. May be there is some IDEA settings that I need to switch, or maven itself has some way to store them? So, my question is - does anyone know the simple way to use several settings.xml file in the same maven home folder?

Quick google and stackoverflow search doesn't provide any results so far.

I expect that when I open another project in Idea it will work with its own artifactory instead of using the one from previous project (since these are from different companies, obviously it is not correct to use the same one)

The answer above doesn't quite work for me, since I'm running project via IDEA and it's getting artifacts downloaded using single settings.xml

Igor Tiulkanov
  • 552
  • 5
  • 18
  • 1
    Possible duplicate of [maven command line how to point to a specific settings.xml for a single command?](https://stackoverflow.com/questions/25277866/maven-command-line-how-to-point-to-a-specific-settings-xml-for-a-single-command) – Amongalen Aug 02 '19 at 08:37
  • Have you tried just to put this settings to pom files? You can use maven profiles that are applied on several levels: https://maven.apache.org/guides/introduction/introduction-to-profiles.html – Serge Harnyk Aug 02 '19 at 08:38
  • @Igor - i think you can add the settings as command line arguments for mvn commands in IDE as mentioned in comments of this answer. https://stackoverflow.com/a/25279325/3981539 – Kavitha Karunakaran Aug 02 '19 at 08:53
  • I'm running project via IDEA and it's getting artifacts downloaded using single settings.xml, so the link to the first answer above doesn't quite work for me. Adding something to pom files might have worked if that project was only mine, but since there are several developers, spoiling pom files with extra stuff that only I will use is not something I can do. – Igor Tiulkanov Aug 02 '19 at 08:55
  • Why are there different settings for artifactory if you are working within the same corporate environment? – khmarbaise Aug 02 '19 at 09:28
  • At the moment I work for 2 different corps so to speak, so both has their own repo, credentials, etc. – Igor Tiulkanov Aug 02 '19 at 09:45
  • 1
    Best setup I can recommend to make a git repository in `$HOME/.m2/` and make two different branches for the areas ...just `git checkout COMPANY1` for one and `git checkout COMPANY2` for the other...easy and simple..and you can follow changes you have made in your settings.xml file.. – khmarbaise Aug 02 '19 at 14:36
  • Have you considered using profiles? – Mark Rotteveel Aug 02 '19 at 17:55

1 Answers1

0

The usual way you work is to either:

  • put all repositories you need for all of your projects into your settings.xml so that it works for all projects.
  • use a Nexus/Artifactory that proxies all the repositories you need and put that as mirror into your settings.xml.

If a repository should really be only accessible for one project, you can put into the pom.xml of that project.

I don't understand how other developers should object to putting the repositories into the pom.xml because they need the very same repositories to run the project (if not, please comment and explain).

J Fabian Meier
  • 33,516
  • 10
  • 64
  • 142
  • Not all developers works with several projects and for them might be more convenient to use single settings file inside maven home than figure out new records inside pom files. At least right now this is the way this project structured, If it were convenient to put settings into pom they would have already been there. – Igor Tiulkanov Aug 02 '19 at 09:33
  • We configured all the 20+ repositories we need in our Nexus and then the `settings.xml` (for all developers) just points to that Nexus. – J Fabian Meier Aug 02 '19 at 09:38
  • Especially, I wonder: You probably build these projects on some kind of build server like Jenkins, Bamboo, ... how do you manage different `settings.xml` there? – J Fabian Meier Aug 02 '19 at 09:39
  • Jenkins is located on a remote server which CI's once it receives a push. I'm currently talking about my local dev machine, which is somehow should store both files simultaneously. I can combine links to repos, but each artifactory requires its own credentials, is it possible to combine both in one settings file? – Igor Tiulkanov Aug 02 '19 at 09:42
  • I'm checking out what is Nexus, it looks like it might be a solution, but I thought about some simple and quick solution instead of figuring out whole new technology) – Igor Tiulkanov Aug 02 '19 at 09:44
  • Does your Jenkins have one settings file for all projects? Then you might just copy that one. – J Fabian Meier Aug 02 '19 at 10:07