解包特定工件

这与复制特定工件示例非常相似。不同之处在于,它们不是复制工件,而是解包。要解压复制的工件,请使用dependency:unpackmojo 并将插件配置为类似于以下示例的内容:

<project>
   [...]
   <build>
     <plugins>
       <plugin>
         <groupId>org.apache.maven.plugins</groupId>
         <artifactId>maven-dependency-plugin</artifactId>
         <version>3.3.0</version>
         <executions>
           <execution>
             <id>unpack</id>
             <phase>package</phase>
             <goals>
               <goal>unpack</goal>
             </goals>
             <configuration>
               <artifactItems>
                 <artifactItem>
                   <groupId>junit</groupId>
                   <artifactId>junit</artifactId>
                   <version>3.8.1</version>
                   <type>jar</type>
                   <overWrite>false</overWrite>
                   <outputDirectory>${project.build.directory}/alternateLocation</outputDirectory>
                   <destFileName>optional-new-name.jar</destFileName>
                   <includes>**/*.class,**/*.xml</includes>
                   <excludes>**/*test.class</excludes>
                 </artifactItem>
               </artifactItems>
               <includes>**/*.java</includes>
               <excludes>**/*.properties</excludes>
               <outputDirectory>${project.build.directory}/wars</outputDirectory>
               <overWriteReleases>false</overWriteReleases>
               <overWriteSnapshots>true</overWriteSnapshots>
             </configuration>
           </execution>
         </executions>
       </plugin>
     </plugins>
   </build>
   [...]
 </project>

在调用之后mvn package,工件被解包。因为很难可靠地检查解压档案的存在,所以使用标记文件代替。标记文件的位置由markersDirectory参数控制。

从命令行解包

如果您打算将此 mojo 配置为在命令行上执行,请使用:

mvn dependency:unpack

您不能将配置放在executions标签内。您的配置应如下所示:

<project>
  [...]
  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-dependency-plugin</artifactId>
        <version>3.3.0</version>
        <configuration>
          <artifactItems>
            <artifactItem>
              <groupId>[ groupId ]</groupId>
              <artifactId>[ artifactId ]</artifactId>
              <version>[ version ]</version>
              <type>[ packaging ]</type>
              <classifier> [classifier - optional] </classifier>
              <overWrite>[ true or false ]</overWrite>
              <outputDirectory>[ output directory ]</outputDirectory>
              <destFileName>[ filename ]</destFileName>
              <includes>[ comma separated list of file filters ]</includes>
              <excludes>[ comma separated list of file filters ]</excludes>
            </artifactItem>
          </artifactItems>
          <!-- other configurations here -->
        </configuration>
      </plugin>
    </plugins>
  </build>
  [...]
</project>