• 0.10.1

Retrieving Maven Plugin Classpath in Runtime

In Maven plugin it is very often necessary to get a full classpath (determined by the project dependencies), in relation to a certain scope. For example, you want to get a full list of all JAR files available for the project in test scope.

Classpath class helps to do this in one line:

public class MyMojo extends AbstractMojo {
  /**
   * @parameter default-value="${project}"
   * @readonly
   */
  private MavenProject project;
  /**
   * @parameter default-value="${repositorySystemSession}"
   * @readonly
   */
  private RepositorySystemSession session;
  @Override
  public void execute() {
    Collection<File> jars = new Classpath(
      this.getProject(),
      this.session.getLocalRepository().getBasedir(),
      "test"
    );
  }
}

Classpath uses Aether to collect required information and resolve all transitive dependencies. It also takes into account dependency exclusions.