一行bash命令,用于将pom的Maven工件下载到指定的lib

时间:2017-06-09 17:20:30

标签: maven awk sed ant

据我所知:

mvn dependency:tree | grep ":compile" | sed 's/+//' | sed 's/-//' | sed 's/\\//' | sed 's/\|//g' | sed 's/ //g' | sed 's/:jar:/:/'| sed 's/:compile//' | sed 's/:/,/g' | sed 's/\[INFO\]//'

是的,这是初步的。我在想那里的'cut'用法,也许为http://central.maven.org/maven2/com/thoughtworks/xstream/xstream/1.4/xstream-1.4.jar构建curl / wget的一行但是我的Bash fu不存在。

显然,随着所有管道的进行,随后的curl / wget位是很容易的。这只是一个遥不可及的URL构造。

这就是我所拥有的结果(所以你不必理解Maven):

com.thoughtworks.xstream,xstream,1.4

1 个答案:

答案 0 :(得分:0)

所以我不能像onkeriner那样做,但是一个小的Python脚本符合要求:

# pip3 install sh
from sh import mvn, grep, rm, mkdir, sed, wget
import csv

rm("-rf", "libs")
mkdir("libs")

tree = sed(sed(mvn("dependency:tree", _tty_out=False), "s/\\[INFO\\]//"), "/\\[WARNING\\]/d")
lines = sed(sed(sed(sed(sed(sed(sed(sed(tree, "s/+//"), "s/-//"), "s/\\\//"), "s/\|//g"), "s/ //g"), "s/:jar:/:/"), "s/:/,/g"), "s/\[INFO\]//")

for gav in csv.reader(lines):
    if (len(gav) is not 4):
        continue

    mkdir("-p", "libs/" + gav[3])
    try:
        wget("http://central.maven.org/maven2/" + gav[0].replace(".", "/") + "/" + gav[1] + "/" + gav[2] + "/" + gav[1] + "-" + gav[2] + ".jar", "-O", "libs/" + gav[3] + "/" + gav[1] + "-" + gav[2] + ".jar")
    except:
        pass

用于https://github.com/paul-hammant/spring-jetty-integrationtest-ant-example/blob/master/mavdl.py(演示项目)的愤怒

编辑:Maven Resolver还有一个Ant功能,我被告知:https://maven.apache.org/resolver-archives/resolver-ant-tasks-LATEST/