Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

Version 1 Next »

Mojo Developer Cookbook

 This page contains code snippets demonstrating commonly used tasks when writing Maven plug-ins. There are no guarantees that these are the 'right' way to do things, but they worked for the author(s).

Commonly used plexus components 

These components are commonly used, also in the following snippets.

You may want to add @required and @readonly, but I dropped them to keep it short.

Creating and resolving an artifact

 To create an artifact, use an ArtifactFactory.

An artifact doesn't help you much until it's resolved (using an ArtifactResolver). This resolving process is not transitive!

 Now you get the artifact file (in the local repository):

Resolving transitively

You need a MavenProject. If you don't have (the right) one, you can create it with just a groupId:artifactId:version:

Now you can use the ArtifactResolver to resolve transitively.

The filter is optional, and limits the resolving. Possible filters are:

  • ScopeArtifactFilter
  • InclusionArtifactFilter
  • ExclusionArtifactFilter
  • TypeArtifactFilter
  • AndArtifactFilter (to combine them)
  • or create your own, by implementing ArtifactFilter
  • No labels