How can I download a specific Maven artifact in one command line?

前端 未结 11 900
太阳男子
太阳男子 2020-11-28 01:05

I can install an artifact by install:install-file, but how can I download an artifact?

For example:

mvn download:download-file -Dgroup         


        
11条回答
  •  眼角桃花
    2020-11-28 01:23

    Regarding how to get the artifact binary, Pascal Thivent's answer is it, but to also get the artifact sources jar, we can use:

    mvn dependency:get -Dartifact=groupId:artifactId:version:jar:sources
    

    e.g.

    mvn dependency:get -Dartifact=junit:junit:4.12:jar:sources
    

    This works because the artifact parameter actually consists of groupId:artifactId:version[:packaging][:classifier]. Just the packaging and classifier are optional.

    With jar as packaging and sources as classifier, the maven dependency plugin understands we're asking for the sources jar, not the artifact jar.

    Unfortunately for now sources jar files cannot be downloaded transitively, which does make sense, but ideally I do believe it can also respect the option downloadSources just like the maven eclipse plugin does.

提交回复
热议问题