How to get access to Maven's dependency hierarchy within a plugin

前端 未结 7 1656
生来不讨喜
生来不讨喜 2020-11-29 05:25

In my plugin I need to process the dependency hierarchy and get information (groupId, artifactId, version etc) about each dependency and if it was excluded. What is the best

7条回答
  •  渐次进展
    2020-11-29 05:52

    Why not just get back all the dependencies (both direct and transitive ones) and check for exclusion?

    @Parameter(property = "project", required = true, readonly = true)
    private MavenProject project;
    
    public void execute() throws MojoExecutionException
    {
      for (Artifact a : project.getArtifacts()) {
        if( a.getScope().equals(Artifact.SCOPE_TEST) ) { ... }
        if( a.getScope().equals(Artifact.SCOPE_PROVIDED) ) { ... }
        if( a.getScope().equals(Artifact.SCOPE_RUNTIME) ) { ... }
      }
    }
    

提交回复
热议问题