I'm writing a Maven 3 plugin that needs to know the transitive dependencies of a given org.apache.maven.model.Dependency
. How can I do that?
相关问题
- Include pom.xml in Jar with gradle
- What order does maven find its dependencies?
- proguard causing EnumMap NPE on dynamically declar
- How to resolve Maven exec plugin: classpath too lo
- Maven: How to read the Parent POM version
相关文章
- IDEA2020 安装maven 插件后,springboot程序 SpringBootApplic
- pom文件中的插件定义
- pom.xml中的project为何报红
- Hibernate Tutorial - Where to put Mapping File?
- Cannot use org.jvnet.jax-ws-commons.jaxws-maven-pl
- New Maven install: mvn -version java.lang.ClassNot
- What's the difference between archetype.xml an
- NoNodeAvailableException[None of the configured no
So the following code should give you an impression how to do it.
The above code will give you the resolved artifacts as well as dependencies. You need to make a difference between the dependencies (in this case the project dependencies without transitive and the artifacts which are the solved artifacts incl. transitive.).
Most important is
requiresDependencyResolution = ResolutionScope.COMPILE
otherwise you will getnull
forgetArtifacts()
.The suggestion by Tunaki will work for any kind of artifact which is not part of your project...The question is what you really need?
In Maven 3, you access all dependencies in a tree-based form by relying on the
maven-dependency-tree
shared component:This component introduces the
DependencyGraphBuilder
that can build the dependency tree for a given Maven project. You can also filter artifacts with aArtifactFilter
, that has a couple of built-in implementations to filter by groupId, artifactId (IncludesArtifactFilter
andExcludesArtifactFilter
), scope (ScopeArtifactFilter
), etc. If the fiter isnull
, all dependencies are kept.In your case, since you target a specific artifact, you could add a
IncludesArtifactFilter
with the patterngroupId:artifactId
of your artifact. A sample code would be:This gives access to the root node of the dependency tree, which is the current project. From that node, you can access all chidren by calling the
getChildren()
method. So if you want to list all dependencies, you can traverse that graph recursively. This component does provide a facility for doing that with theCollectingDependencyNodeVisitor
. It will collect all dependencies into aList
to easily loop through it.For the Maven plugin, the following dependency is therefore necessary: