gpt4 book ai didi

maven-2 - 如何递归地解决 Maven 2 插件中的依赖项

转载 作者:行者123 更新时间:2023-12-04 22:16:08 25 4
gpt4 key购买 nike

我正在编写一个 Maven 2 插件,它必须遍历所有项目依赖项并递归遍历这些依赖项的所有依赖项。到目前为止,我只设法使用以下代码解决了直接依赖关系:

for (Dependency dependency : this.project.getModel().getDependencies())
{
Artifact artifact = this.artifactFactory.createArtifact(
dependency.getGroupId(),
dependency.getArtifactId(),
dependency.getVersion(),
dependency.getScope(),
dependency.getType());
this.artifactResolver.resolve(
artifact,
this.remoteRepositories,
this.localRepository);

....
}

我怎样才能递归地做同样的事情,以便我也找到依赖项的依赖项等等?

最佳答案

A) 不要使用
project.getModel().getDependencies() ,
使用 project.getArtifacts()
反而。这样你就可以自动获得传递依赖。要启用它:将您的魔力标记为

  • @requiresDependencyResolution compile
  • @requiresDependencyCollection compile

  • (请参阅 Mojo API Specification 以供引用)。

    B) 你真的想使用遗留的依赖 API 吗?为什么不是 use the new Maven 3 Aether API

    关于maven-2 - 如何递归地解决 Maven 2 插件中的依赖项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5116281/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com