2013-07-24 6 views
12

까지 지금까지 Maven 어셈블리 플러그인을 사용하여 각 아티팩트에 대해 두 개의 JAR을 생성했습니다 - 컴파일 된 소스 및 종속성 - 이는 간단했습니다. 네트워크를 통해 컴파일 된 소스 만 배포하는 것이 배포보다 훨씬 빠릅니다. 40 MB의 데이터를 가진 올인원 JAR.두 개의 Jar를 생성하는 Maven Shade 플러그인

내부 파일을 덮어 쓰기 때문에 <transformers> 기능을 사용할 수 있도록 maven shade 플러그인으로 전환해야했습니다. 그러나 나는 두 개의 실행 모두를 실행하는 관리 드릴 수 없습니다 :

<plugins> 
    <plugin> 
    <groupId>org.apache.maven.plugins</groupId> 
    <artifactId>maven-shade-plugin</artifactId> 
    <executions> 
     <execution> 
     <id>shade-libs</id> 
     <phase>package</phase> 
     <goals> 
      <goal>shade</goal> 
     </goals> 
     <configuration> 
      <outputFile>target/assembly/${project.artifactId}-libs.jar</outputFile> 
      <artifactSet> 
      <excludes> 
       <exclude>...</exclude> 
      </excludes> 
      </artifactSet> 
      <transformers> 
      <transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer"> 
       <resource>META-INF/spring.handlers</resource> 
      </transformer> 
      <transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer"> 
       <resource>META-INF/spring.schemas</resource> 
      </transformer> 
      </transformers> 
     </configuration> 
     </execution> 
    </executions> 
    </plugin> 
    <plugin> 
    <groupId>org.apache.maven.plugins</groupId> 
    <artifactId>maven-shade-plugin</artifactId> 
    <executions> 
     <execution> 
     <id>shade-main</id> 
     <phase>package</phase> 
     <goals> 
      <goal>shade</goal> 
     </goals> 
     <configuration> 
      <outputFile>target/assembly/${project.artifactId}.jar</outputFile> 
      <artifactSet> 
      <includes> 
       <include>...</include> 
      </includes> 
      </artifactSet> 
     </configuration> 
     </execution> 
    </executions> 
    </plugin> 
</plugins> 

내가 mvn package을 실행

는 만 두 번째 실행이 실행됩니다. 첫 번째 것은 항상 무시됩니다. 메이븐 어셈블리 플러그인으로 완벽하게 작동했습니다.

물론 솔루션은 어셈블리와 그늘 플러그인을 동시에 사용할 수 있지만 더 일관된 해결책을 찾고 싶습니다.

+2

플러그인을 두 번 정의하는 대신 하나의 플러그인 정의 내에서 두 번째'실행 '을 정의 해 보았습니까? – DB5

+0

답변으로 게시하면 동의 할 것입니다. –

+0

감사합니다. 지금 해 보았습니다. 그것을 듣고 다행 당신의 문제를 해결. – DB5

답변

21

플러그인을 두 번 정의하는 대신 한 번만 정의하고 두 개의 execution 섹션으로 정의하면됩니다. 따라서 상황은 다음과 같습니다.

<plugins> 
    <plugin> 
    <groupId>org.apache.maven.plugins</groupId> 
    <artifactId>maven-shade-plugin</artifactId> 
    <executions> 
     <execution> 
     <id>shade-libs</id> 
     <phase>package</phase> 
     <goals> 
      <goal>shade</goal> 
     </goals> 
     <configuration> 
      <outputFile>target/assembly/${project.artifactId}-libs.jar</outputFile> 
      <artifactSet> 
      <excludes> 
       <exclude>...</exclude> 
      </excludes> 
      </artifactSet> 
      <transformers> 
      <transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer"> 
       <resource>META-INF/spring.handlers</resource> 
      </transformer> 
      <transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer"> 
       <resource>META-INF/spring.schemas</resource> 
      </transformer> 
      </transformers> 
     </configuration> 
     </execution> 
     <execution> 
     <id>shade-main</id> 
     <phase>package</phase> 
     <goals> 
      <goal>shade</goal> 
     </goals> 
     <configuration> 
      <outputFile>target/assembly/${project.artifactId}.jar</outputFile> 
      <artifactSet> 
      <includes> 
       <include>...</include> 
      </includes> 
      </artifactSet> 
     </configuration> 
     </execution> 
    </executions> 
    </plugin> 
</plugins>