개요

The dependency plugin provides the capability to manipulate artifacts. It can copy and/or unpack artifacts from local or remote repositories to a specified location.

 

사용

dependency:analyze

프로젝트내에서 정의되고 사용되는 dependency 들의 유형을 분석(사용되며 선언됨, 사용되고 선언되지 않음, 사용하지 않고 선언됨)

 

dependency:analyze-duplicate

프로젝트내에 중복된 dependency 들을 분석하여 출력

dependency:copy-dependencies

Goal that copies the project dependencies from the repository to a defined location.

http://maven.apache.org/plugins/maven-dependency-plugin/usage.html

 

project>
  [...]
  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-dependency-plugin</artifactId>
        <version>2.8</version>
        <executions>
          <execution>
            <id>copy-dependencies</id>
            <phase>package</phase>
            <goals>
              <goal>copy-dependencies</goal>
            </goals>
            <configuration>
              <!-- configure the plugin here -->
            </configuration>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>
  [...]
</project>
XML

 

The dependency:build-classpath mojo

현재 pom 파일에 기술되어 있는 dependencies 를 참고해서 전체 의존성을 다음과 같이 CLASSPATH 형식으로 출력해 준다. 

/home/foo/.m2/repository/org/java/utils/util/util-1.0.jar:/home/foo/.m2/ ....
CODE
다음 명령어로 cp.txt 에 CLASSPATH 를 지정할 수 있다.
mvn dependency:build-classpath -Dmdep.outputFile=cp.txt
BASH

cp.txt 를 입력해서 해서 바로 java program 을 실행할 수 있다.

java -cp `cat cp.txt` MyMainClass
BASH

현재 pom 에 기술된 artifactId 는 CLASSPATH 에서 빠지므로 편집기에서 수동으로 등록하거나 다음처럼 echo 문으로 cp.txt 맨 뒤에 추가해야 한다.

echo "target/my-artifact.jar" >> cp.txt

 

Ref