I have a Maven plugin that takes a groupId, artifactId, and version in its confiugration.
I want to be able to download that artifact from the remote repositories and copy the file into the project. I can’t figure out how to download the artifact though.
I understand that I can resolve dependencies using the dependency plugin, but I need it to happen inside my plugin. How can I do this?
Your plugin needs to create an Artifact using the ArtifactFactory and the groupId, artifactId and version of the artifact to be bootstrapped, then pass that artifact to an ArtifactResolver to handle the discovery/download.
The resolver needs access to the local repository and remote repositories. The good news is that all those are plexus components that you can declare as dependencies in your Mojo and have Plexus wire them in for you.
In another answer I showed how to do this. In your case you need a cut-down version with slightly different parameters to read the groupId, artifactId and version. In the plugin below, the various components are declared as plexus components, and the properties to declare the groupId, artifactId, version, and packaging type.
This is an example of a pom configured to use the plugin (and download the aspectjrt 1.6.4 pom):