2015-01-30 3 views
0

Maven 종속성 Jar의 내용을 내 classes 폴더에 압축을 푸는 동시에 전이 의존성을 포함하려고합니다. 또한 모든 프로젝트의 종속성을 풀고 싶지 않습니다. 내가 이것을 그들의 목록으로 할 수 있다면 오직 한 명만 좋을 것이고, 더 좋을 것이다. 비슷한 해결책을 찾았지만 정확한 문제는 언급하지 않았습니다.전이 의존성을 유지하면서, Maven 종속성을 클래스에 풀어 놓으십시오.

예 주 프로젝트 응원단 :

. 
. 
. 
<dependencies> 
    <dependency> 
    <groupId>com.test.dep</groupId> 
    <artifact>first-dependency</artifact> 
    </dependency> 
    <dependency> 
    <groupId>com.test.dep</groupId> 
    <artifact>second-dependency</artifact> 
    </dependency> 
</dependencies> 
. 
. 
. 

예 초 의존성 응원단 :

. 
. 
. 
<dependencies> 
    <dependency> 
    <groupId>com.test.dep</groupId> 
    <artifact>third-dependency</artifact> 
    </dependency> 
    <dependency> 
    <groupId>com.test.dep</groupId> 
    <artifact>fourth-dependency</artifact> 
    </dependency> 
</dependencies> 
. 
. 
. 

내가 원하는 second-dependencytarget 아래에 중첩 내 classes 폴더에 압축을 푼도 (유물 중 하나를하고자합니다 third-dependency, fourth-dependency) 내 lib 폴더에 아직 포함되어 있어야합니다 (압축 해제되지 않음).

나는 (내 의존성의 유물 포함하지 않고) 다음과 같은 시도 :

<plugin> 
    <groupId>org.apache.maven.plugins</groupId> 
    <artifactId>maven-dependency-plugin</artifactId> 
    <executions> 
     <execution> 
      <id>unpack</id> 
      <phase>generate-resources</phase> 
      <goals> 
       <goal>unpack</goal> 
      </goals> 
      <configuration> 
       <artifactItems> 
        <artifactItem> 
         <groupId>com.test.dep</groupId> 
         <artifactId>second-dependency</artifactId> 
         <type>jar</type> 
         <overWrite>true</overWrite> 
         <outputDirectory>${project.build.directory}/classes</outputDirectory> 
         <includes>**/*</includes> 
        </artifactItem> 
       </artifactItems> 
      </configuration> 
     </execution> 
    </executions> 
</plugin> 

을 그리고 이것은 내 classes 폴더에 second-dependency의 내용을 포함했다,하지만 내 주요 프로젝트에 third-dependency 또는 fourth-dependency을 포함하지 않았다 lib 디렉토리.

아이디어가 있으십니까?

답변

0

대신, dependency:unpack-dependencies의 기술 매개 변수를 기반으로, 플러그인 구성 다음 사용해보십시오 : 사용 사례에 대한

<plugin> 
    <groupId>org.apache.maven.plugins</groupId> 
    <artifactId>maven-dependency-plugin</artifactId> 
    <executions> 
    <execution> 
     <id>unpack</id> 
     <phase>generate-resources</phase> 
     <goals> 
     <goal>unpack</goal> 
     </goals> 
     <configuration> 
     <outputDirectory>${project.build.directory}/classes</outputDirectory> 
     <includeArtifactIds>second-dependency</includeArtifactIds> 
     </configuration> 
    </execution> 
    </executions> 
</plugin> 

임 확실하지.

하지만 jar 파일을 빌드하려면 maven-shade-plugin의 사용 사례처럼 들립니다. 이 플러그인은 특정 아티팩트 (종속성) 세트뿐만 아니라 프로젝트 자체의 클래스 및 자원을 하나의 jar로 패키지화 할 수 있습니다.

이슈 자체 ("$ {project.groupId} : $ {project.artifactId}")와 "두 번째 종속성"을 정의하면됩니다.

<plugin> 
    <groupId>org.apache.maven.plugins</groupId> 
    <artifactId>maven-shade-plugin</artifactId> 
    <version>2.1</version> 
    <configuration> 
    <artifactSet> 
     <includes> 
     <include>${project.groupId}:${project.artifactId}</include> 
     <include>com.test.dep:second-dependency</include> 
     </includes> 
    </artifactSet> 
    </configuration> 
    <executions> 
    <execution> 
     <phase>package</phase> 
     <goals> 
     <goal>shade</goal> 
     </goals> 
    </execution> 
    </executions> 
</plugin> 
+1

그런 식으로 일했습니다. 두 번째 종속성의 pom에있는 모든 종속성을 포함하고 클래스 폴더에 두 번째 종속성을 풀고 동시에 lib 폴더의 두 번째 dependency.jar를 포함하지 않습니다. –

관련 문제