Maven3 : How to get all the project dependencies in a Custom Maven Extension

守給你的承諾、 提交于 2019-12-11 23:42:45

问题


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.

来源:https://stackoverflow.com/questions/51888672/maven3-how-to-get-all-the-project-dependencies-in-a-custom-maven-extension

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!