我可以通过install:install-file安装一个工件, 但我怎么下载藏物呢?
例如:
mvn download:download-file -DgroupId=.. -DartifactId=.. -Dversion=LATEST
我可以通过install:install-file安装一个工件, 但我怎么下载藏物呢?
例如:
mvn download:download-file -DgroupId=.. -DartifactId=.. -Dversion=LATEST
当前回答
要在指定位置复制工件,请使用copy而不是get。
mvn org.apache.maven.plugins:maven-dependency-plugin:3.1.2:copy \
-DrepoUrl=someRepositoryUrl \
-Dartifact="com.acme:foo:RELEASE:jar" -Dmdep.stripVersion -DoutputDirectory=/tmp/
其他回答
下面是使用Maven 3.6获取ASM-7的示例:
mvn dependency:get -DremoteRepositories=maven.apache.org -Dartifact=org.ow2.asm:7.0:sources:jar
或者你可以从这里下载罐子:https://search.maven.org/search?q=g:org.ow2.asm%20AND%20a:asm然后
mvn install:install-file -DgroupId=org.ow2.asm -DartifactId=asm -Dversion=7.0 -Dclassifier=sources -Dpackaging=jar -Dfile=/path/to/asm-7.0.jar
下面是我最终使用Maven 3.1.1下载名为“component.jar”的工件的最新版本的方法(其他建议没有,我认为主要是由于Maven版本的更改)
这实际上下载了文件并将其复制到本地工作目录
从bash:
mvn dependency:get \
-DrepoUrl=http://.../ \
-Dartifact=com.foo.something:component:LATEST:jar \
-Dtransitive=false \
-Ddest=component.jar \
不幸的是,maven-dependency-plugin:get不支持版本范围,例如[2.17.1,)或[,)
如果你需要下载一个特定的maven工件,但是使用版本范围,就像我做的那样,看这里:
下载带有版本范围的Maven工件
官方文件中的用法:
https://maven.apache.org/plugins/maven-dependency-plugin/usage.html#dependency:get
对于我的案例,请看下面的答案:
mvn dependency:get -Dartifact=$2:$3:$4:$5 -DremoteRepositories=$1 -Dtransitive=false
mvn dependency:copy -Dartifact=$2:$3:$4:$5 -DremoteRepositories=$1 -Dtransitive=false -DoutputDirectory=$6
#mvn dependency:get -Dartifact=com.huya.mtp:hynswup:1.0.88-SNAPSHOT:jar -DremoteRepositories=http://nexus.google.com:8081/repository/maven-snapshots/ -Dtransitive=false
#mvn dependency:copy -Dartifact=com.huya.mtp:hynswup:1.0.88-SNAPSHOT:jar -DremoteRepositories=http://nexus.google.com:8081/repository/maven-snapshots/ -Dtransitive=false -DoutputDirectory=.
使用命令mvn dependency:get下载特定的工件并使用 使用命令mvn dependency:copy将下载的工件复制到目标目录-DoutputDirectory。
在没有mvn的情况下下载最新maven工件的一行代码:
curl -O -J -L "https://repository.sonatype.org/service/local/artifact/maven/content?r=central-proxy&g=io.staticcdn.sdk&a=staticcdn-sdk-standalone-optimizer&e=zip&v=LATEST"