IT박스

하나의 명령 줄에서 특정 Maven 아티팩트를 어떻게 다운로드 할 수 있습니까?

itboxs 2020. 6. 14. 11:13
반응형

하나의 명령 줄에서 특정 Maven 아티팩트를 어떻게 다운로드 할 수 있습니까?


로 아티팩트를 설치할 수 install:install-file있지만 아티팩트를 어떻게 다운로드 할 수 있습니까?

예를 들면 다음과 같습니다.

mvn download:download-file -DgroupId=.. -DartifactId=.. -Dversion=LATEST

2.1 버전부터 좋은 목표 를 가진 maven dependency plugin사용할 수 있습니다 dependency:get. pom이 필요하지 않으며 모든 것이 명령 행에서 발생합니다.

dependency:get목표 를 찾으려면 버전 2.1을 사용하도록 maven에 명시 적으로 알려야합니다. 즉, 버전을 포함하여 완전한 플러그인 이름을 사용해야합니다.

mvn org.apache.maven.plugins:maven-dependency-plugin:2.1:get \
    -DrepoUrl=url \
    -Dartifact=groupId:artifactId:version

업데이트 : 이전 버전의 Maven (2.1 이전)에서는 dependency:getmaven 사본이 지정된 버전의 플러그인을 사용하도록하여 정규화 된 이름과 버전을 사용하지 않고 정상적으로 실행할 수 있습니다.

다음과 같이 수행 할 수 있습니다.

1. 파일 <settings>요소 내에 다음 줄을 추가 ~/.m2/settings.xml하십시오.

<usePluginRegistry>true</usePluginRegistry>

2. ~/.m2/plugin-registry.xml다음 내용으로 파일 추가하십시오 .

<?xml version="1.0" encoding="UTF-8"?>
<pluginRegistry xsi:schemaLocation="http://maven.apache.org/PLUGIN_REGISTRY/1.0.0 http://maven.apache.org/xsd/plugin-registry-1.0.0.xsd"
xmlns="http://maven.apache.org/PLUGIN_REGISTRY/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <plugins>
    <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-dependency-plugin</artifactId>
      <useVersion>2.1</useVersion>
      <rejectedVersions/>
    </plugin>
  </plugins>
</pluginRegistry>

그러나 이것은 maven 2.1 / 2.2에서 더 이상 작동하지 않는 것 같습니다. 실제로 플러그인 레지스트리 소개 에 따르면 , 기능은 plugin-registry.xml(이동성을 위해) 재 설계되었으며 플러그인 레지스트리는 현재 Maven 2 내에서 반 휴면 상태 입니다. 그래서 우리는 지금 긴 이름을 사용해야한다고 생각합니다 (pom없이 플러그인을 사용할 때 뒤에 아이디어입니다 dependency:get).


Maven Dependency Plugin 최신 버전 (2.8)을 사용 하면 Maven Central Repository에서 아티팩트를 다운로드하는 것이 다음과 같이 간단합니다.

mvn org.apache.maven.plugins:maven-dependency-plugin:2.8:get -Dartifact=groupId:artifactId:version[:packaging[:classifier]]

여기서 Maven 좌표groupId:artifactId:version 등은

예를 들어 Maven 2.0.9, Maven 2.2.1 및 Maven 3.0.4로 테스트했습니다.

mvn org.apache.maven.plugins:maven-dependency-plugin:2.8:get -Dartifact=org.hibernate:hibernate-entitymanager:3.4.0.GA:jar:sources

(자신의 제공 파스칼 Thivent 덕분에 멋진 대답을 처음부터.이 코멘트에 맞지 않을 것하고 편집을 위해 너무 광범위한 것 때문에 내가 다른 대답을 추가하고 있습니다.)


다음은 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 \

이슈 바이너리를 얻는 방법과 관련하여 Pascal Thivent의 대답 은 그것이지만, 이슈 소스 항아리를 얻으려면 다음을 사용할 수 있습니다.

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

예 :

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

artifact매개 변수가 실제로로 구성되어 있기 때문에 작동합니다 groupId:artifactId:version[:packaging][:classifier]. 그냥 포장분류는 선택 사항입니다.

jar같이 포장sources같이 분류 , 받는다는 종속성 플러그인은 우리가 소스 항아리가 아닌 유물 항아리를 요청하고 이해한다.

불행히도 현재 소스 jar 파일은 전 이적으로 다운로드 할 수 없으므로 의미가 있지만 이상적으로 downloadSources는 maven eclipse plugin과 마찬가지로 옵션을 존중 할 수 있다고 생각합니다 .


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"

One could use dependency:copy (http://maven.apache.org/plugins/maven-dependency-plugin/copy-mojo.html) which takes a list of artifacts defined in the plugin configuration section and copies them to a specified location, renaming them or stripping the version if desired. This goal can resolve the artifacts from remote repositories if they don't exist in either the local repository or the reactor.

Not all the properties of the plugin could be used in maven CLI. The properties which have "User Property:" property defined could be specified. In the below example I am downloading junit to my temp folder and stripping the vesion from the jar file.

mvn org.apache.maven.plugins:maven-dependency-plugin:2.8:copy -Dartifact=junit:junit:4.11 -DoutputDirectory=/tmp -Dmdep.stripVersion=true

where artifact=junit:junit:4.11 is the maven coordinates. And you specify artifcat as groupId:artifactId:version[:packaging[:classifier]]

(Thanks to Pascal Thivent for providing his https://stackoverflow.com/a/18632876/2509415 in the first place. I am adding another answer)


The command:

mvn install:install-file 

Typically installs the artifact in your local repository, so you shouldn't need to download it. However, if you want to share your artifact with others, you will need to deploy the artifact to a central repository see the deploy plugin for more details.

Additionally adding a dependency to your POM will automatically fetch any third-party artifacts you need when you build your project. I.e. This will download the artifact from the central repository.


Here's an example to get ASM-7 using Maven 3.6:

mvn dependency:get -DremoteRepositories=maven.apache.org -Dartifact=org.ow2.asm:7.0:sources:jar

Or you can download the jar from here: https://search.maven.org/search?q=g:org.ow2.asm%20AND%20a:asm and then

mvn install:install-file -DgroupId=org.ow2.asm -DartifactId=asm -Dversion=7.0 -Dclassifier=sources -Dpackaging=jar -Dfile=/path/to/asm-7.0.jar

LATEST is deprecated, try with range [,)

./mvnw org.apache.maven.plugins:maven-dependency-plugin:3.1.1:get \  
-DremoteRepositories=repoId::default::https://nexus/repository/maven-releases/ \
"-Dartifact=com.acme:foo:[,)"

참고URL : https://stackoverflow.com/questions/1895492/how-can-i-download-a-specific-maven-artifact-in-one-command-line

반응형