简体   繁体   English

以编程方式下载maven依赖项

[英]Download maven dependencies programmatically

I have been trying to download all maven dependencies programmatically via aether. 我一直试图通过以太编程方式下载所有maven依赖项。 I can get all the transitive dependencies (courtesy of the code from 我可以获得所有传递依赖(来自代码的恭维)

https://github.com/apache/maven-resolver/blob/master/maven-resolver-demos/maven-resolver-demo-snippets/src/main/java/org/apache/maven/resolver/examples/ResolveTransitiveDependencies.java

however because it doesn't download any of the plugins needed by the dependency. 但是因为它没有下载依赖项所需的任何插件。

Since I am quite new to Maven, I might be missing something completely obvious here, but any help would be greatly appreciated. 由于我对Maven很新,我可能会遗漏一些在这里完全明显的东西,但任何帮助都会非常感激。

If I try to download the dependecies for sonarqube plugin with ResolveTransitiveDependencies.java, I get the following correctly downloaded. 如果我尝试使用ResolveTransitiveDependencies.java下载sonarqube插件的dependecies,我会正确下载以下内容。

org\sonarsource\scanner\maven\sonar-maven-plugin\3.6.0.1398\sonar-maven-plugin-3.6.0.1398.jar
org\sonatype\plexus\plexus-sec-dispatcher\1.4\plexus-sec-dispatcher-1.4.jar
org\sonatype\plexus\plexus-cipher\1.4\plexus-cipher-1.4.jar
org\codehaus\plexus\plexus-utils\3.0.22\plexus-utils-3.0.22.jar
org\sonarsource\scanner\api\sonar-scanner-api\2.12.0.1661\sonar-scanner-api-2.12.0.1661.jar
commons-lang\commons-lang\2.6\commons-lang-2.6.jar

However it doesn't download any of the plugins that are part of the individual transitive dependency POM,s. 但是,它不会下载属于单个传递依赖项POM的任何插件。 Is there a way to do that from Aether ? 有没有办法从Aether那里做到这一点?

You can try Jeka library ( https://jeka.dev ) to accomplish this. 您可以尝试使用Jeka库( https://jeka.dev )来完成此任务。

import dev.jeka.core.api.depmanagement.*;

import java.nio.file.Path;
import java.util.List;

import static dev.jeka.core.api.depmanagement.JkJavaDepScopes.*;

public class SampleDepDownload {

    public static void main(String[] args) {
        JkDependencySet deps = JkDependencySet.of()
                .and("com.googlecode.playn:playn-core:1.4")
                .and("com.threerings:tripleplay:1.4")
                .withDefaultScopes(COMPILE_AND_RUNTIME);
        JkDependencyResolver resolver = JkDependencyResolver.of(JkRepo.ofMavenCentral());
        List<Path> libs = resolver.resolve(deps, RUNTIME).getFiles().getEntries();
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM