Maven3 : How to get all the project dependencies i

2019-08-18 22:00发布

In Maven 3.x , how I can get all the dependencies of a project including the transitive in a custom maven extension (By not using Aether)

Currently I have this :

 @Component(role = AbstractMavenLifecycleParticipant.class, hint = "Test")
 public class sampleExtension extends AbstractMavenLifecycleParticipant implements LogEnabled {

   private Logger logger;

   @Override
   public void afterSessionStart(MavenSession session)
        throws MavenExecutionException {
  this.logger.info("Starting afterSessionStart()");
}

@Override
public void afterProjectsRead(MavenSession session)
        throws MavenExecutionException {
      MavenProject pr = session.getCurrentProject();

    List dependencies = pr.getDependencies();

    this.logger.info("Project name and Size of dependencies: " + pr.getArtifactId() + " : " + dependencies.size()); 
}

@Override
public void enableLogging(Logger logger) {
    this.logger = logger;
}

}

I am building this extension jar and placing it in $Maven_home/lib/ext . I picked up a random maven project (lets call it 'abc') and ran the command : mvn clean install , which shows the number of dependencies as 13 from the logs. Where as if I run mvn dependency:copy-dependencies on 'abc' , I see more than 200 dependencies copied to target folder.

Ultimately, what I want to do is, get all the dependencies of a project in the extension class and copy it to a folder.

Is there anything I am doing wrong? Please note that I am new to all this. Any help is greatly appreciated.

0条回答
登录 后发表回答