简体   繁体   中英

Download maven dependencies programmatically

I have been trying to download all maven dependencies programmatically via aether. 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.

If I try to download the dependecies for sonarqube plugin with ResolveTransitiveDependencies.java, I get the following correctly downloaded.

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. Is there a way to do that from Aether ?

You can try Jeka library ( https://jeka.dev ) to accomplish this.

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();
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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