0

I see several options:

  • directly in pom.xml
  • in company super-pom
  • in settings.xml (global or user)
  • in a profile or directly (in settings.xml or pom.xml)

We want our Jenkins to push artifacts to internal repository, and developers to pull missing artifacts from there.


If I put the repository URL in pom.xml, and later the internal repository is moved to a different address, the released versions will all have a broken link.

Super-pom saves some repetition, but in a clean setup you need to somehow know where the repository is to find the parent POM — to tell you where the repository is.


Having the URL in settings allows one to change it without modifying the artifacts, but there are two problems:

  • build will fail due to unresolved dependencies, if maven settings have no reference to the internal repo
  • developers have to update their settings.xml files manually

I'm also unsure about the merits of putting repository configuration in profiles. I know it let's you easily switch the repositories on and off, but shouldn't the -o option and snapshot resolution settings be enough for most uses?

What about using a different repository (e.g. with instrumented classes) for integration tests?

Jakub Bochenski
  • 3,113
  • 4
  • 33
  • 61

2 Answers2

1

Configure a single repository in the users ${HOME}/.m2/settings.xml and configure other needed repositories in your appropriate repository manager either Nexus, Artifactory or Archiva. In Jenkins there is the Config File Provider plugin which exactly handles such situations in a very convinient way.

khmarbaise
  • 92,914
  • 28
  • 189
  • 235
  • Can you please comment on the lack of portability of this approach? Won't this be a problem - maven docs about settings.xml is full of "don't make your build non-portable" warnings – Jakub Bochenski Feb 27 '15 at 14:03
  • What is non portable about this approach? Works in Windows, Linux, Mac ? – khmarbaise Feb 27 '15 at 14:53
  • I mean non-portable in the sense described here: https://maven.apache.org/guides/introduction/introduction-to-profiles.html#ProfilePitfalls – Jakub Bochenski Feb 27 '15 at 15:12
  • Also see "I'd personally define the repositories required by a particular project in the project pom.xml because it keeps the build portable." https://stackoverflow.com/questions/2225535/where-is-the-best-place-to-specify-maven-repositories-pom-xml-or-settings-xml – Jakub Bochenski Feb 27 '15 at 17:46
0

If you want to have repeatable builds and good control over your organization internally, use a repository manager and use a mirrorOf entry in everyone’s settings.xml to point at that url.

If you are exposing your source and want to make it easy for others to build, then consider adding a repository entry to your POM, but don’t pick a URL lightly, think long-term, and use a URL that will always be under your control.

http://blog.sonatype.com/2009/02/why-putting-repositories-in-your-poms-is-a-bad-idea/

Jakub Bochenski
  • 3,113
  • 4
  • 33
  • 61