8

What's the best way to download remote maven artifact from within a maven plugin while also supporting maven 2.2.x1), 3.0.x, 3.1.x and newer?

Aether seems a good candidate but it changed package namespace between 3.0.5 and 3.1 breaking compatibility.

There's pieces of information around,

So what's the correct, or at least working, way to go on about this?

1) Where Maven 2.2.x is a nice to have as pointed out by @khmarbaise is EoL

Community
  • 1
  • 1
Johan Sjöberg
  • 47,929
  • 21
  • 130
  • 148
  • What kind of dependencies dou you need to download? Do you really need to support Maven 2.? Do you mean 2.0.X or 2.2.X ? – khmarbaise Aug 20 '14 at 07:00
  • @khmarbaise, `2.2.x` and any artifact from e.g., central. – Johan Sjöberg Aug 20 '14 at 09:32
  • Take a look into maven-compat module which might help for this. You know that [Maven 2.2.1 is already EoL](http://maven.apache.org/maven-2.x-eol.html) ? – khmarbaise Aug 20 '14 at 09:38
  • @khmarbaise, perhaps I can reword to the question to state that `2.2.x` is *nice to have* since still a lot of people are using it. – Johan Sjöberg Aug 20 '14 at 09:39
  • Maven 2.2.1 has reached it's EOL over five years ago. (Check http://maven.apache.org/maven-2.x-eol.html). It only makes sense to support 3.x.y. I haven't dealt with this in a while, but I think the Karaf option you quoted looks good. Alternatively, if you really must support 2.2.x, you could write your own utility class which switches between what you see in the Karaf helper and the way you would normally download them in 2.2.x. – carlspring Aug 20 '14 at 09:41
  • @carlspring EoL for Maven 2.2.1 has been decided this year in February (see [dev list](http://maven.40175.n5.nabble.com/VOTE-Maven-2-x-is-end-of-life-td5784522i20.html#a5785086)). Not five years ago. – khmarbaise Aug 20 '14 at 09:58
  • Oh, you're actually right, I seem to have confused it with it's last release date. Either way, use of 2.2.1 should now be discouraged. – carlspring Aug 20 '14 at 10:11

1 Answers1

1

If you're in a plugin and want to have another plugin invoked, the best solution - by far - is to use Mojo Executor. This way, you won't rewrite the maven-dependency-plugin ... Considering the maven version issues, well, I guess you should indeed give up on maven 2.* support.

Riduidel
  • 22,052
  • 14
  • 85
  • 185
  • Interesting, my use case requires an `Artifact` instance, is that possible using the Mojo Executor? – Johan Sjöberg Aug 21 '14 at 19:31
  • Can you elaborate by "my use case requires an Artifact" ? You'll have to give maven dependencies plugin the maven coordinates of the artifact you want to download. Do you want the user of your plugin to provide these in their POMs ? If so, you can get some inspiration by looking at the source of dependencies mojos : their use of a Collection (look the [AbstractFromConfigurationMojo](https://maven.apache.org/plugins/maven-dependency-plugin/xref/org/apache/maven/plugin/dependency/fromConfiguration/AbstractFromConfigurationMojo.html)) – Riduidel Aug 22 '14 at 13:24
  • Preferably I would like to download an artifact and then get a handle to it, for instance to be able to copy it to somewhere on the local file system. – Johan Sjöberg Aug 22 '14 at 13:36
  • 1
    You know this is exactly what [maven-dependency-plugin:copy mojo](https://maven.apache.org/plugins/maven-dependency-plugin/copy-mojo.html) allows you to do ? You don't even need custom code. – Riduidel Aug 22 '14 at 13:41