3

I'm about to write a tool with which our developers can checkout sources for an artifact given its maven coordinates. The tool should be able to optionally checkout sources recursively for all SNAPSHOT dependencies as well.

My first question would be: Do I need to write this tool at all? One would imagine that this isn't a very unique user scenario, but I have yet failed to find something suitable to achieve this. I have looked at scm:checkout and scm:bootstrap, both require knowledge about the connection url where as I only have a artifactID. Is there any other way, but to write a custom tool, to do this?

If not, my home brew tool would do something in the lines of:

  1. Parse .m2/settings.xml to determine which repo to use Download the pom for the artefact.
  2. Create a temporary bootstrap-pom with the scm-tag from the downloaded pom.
  3. Use scm:bootstrap and the bootstrap-pom to checkout sources.
  4. [Optionally] Search the sources for poms with SNAPSHOT dependencies and repeat the process.

My second question would be: Does this sound like a good way to go about it to you? Any caveats spring to mind?

Spotty
  • 73
  • 4

2 Answers2

1

For each project you want to checkout this way, you could add a profile containing plugin configuration for the scm plugin's bootstrap goal. The plugin config would be in the same POM as the scm URL, so that handles #2 & 3; you wouldn't need a separate bootstrap-pom.

For getting the initial POM, you could use dependency:get from the command line:

mvn dependency:get -Dartifact=some.group:my.artifact:version:pom -Ddestination=someDirectory

In the directory with the downloaded POM, you perform the bootstrap:

mvn -Pbootstrap-profile-id scm:bootstrap

which would check out the top level project.

I don't know how you'd make this recursive. You might be able to use dependency:copy-dependencies asking for transitive dependencies and copying POMs, and then running the bootstrap process on each of those. Not sure how that would work.

user944849
  • 14,524
  • 2
  • 61
  • 83
0

The solution of user944849 doesn't work for me, but here is an example that works

mvn dependency:get -Dartifact=ar.com.hjg:pngj:2.1.0:pom  -Ddest=pom.xml
mvn scm:bootstrap -Dgoals=validate
mv target/checkout ~/projects/pngj
Erik Martino
  • 4,023
  • 1
  • 19
  • 12
  • If the pom is not generated by the release plugin, the scm url may point to HEAD instead of the tag of the release. Which may or may not be what you want. – Erik Martino May 28 '14 at 06:51