0
我有一個任務來解壓pom.xml中提到的所有jar文件,然後將解壓後的內容打包到一個jar文件中。我能夠使用依賴插件和jar插件的解壓縮依賴目標來完成此操作。 但是,在我生成新的jar之後,我想要刪除解壓後創建的文件夾。我在我的pom.xml中使用了以下代碼片段(請閱讀每個插件上方的註釋)。如何在構建結束時從Maven的目標目錄中刪除特定的目錄?
<build>
<plugins>
<!-- This part of the code is used to unpack all the dependencies mentioned in my pom.xml -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.10</version>
<executions>
<execution>
<id>unpack-dependencies</id>
<phase>package</phase>
<goals>
<goal>unpack-dependencies</goal>
</goals>
<configuration>
<includes>**/*.class</includes>
<outputDirectory>${project.build.directory}/alternateLocation</outputDirectory>
<overWriteReleases>false</overWriteReleases>
<overWriteSnapshots>true</overWriteSnapshots>
</configuration>
</execution>
</executions>
</plugin>
<!-- This part of the code is used for creating a jar with all the contents of the "alternateLocation" directory above -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.4</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>jar</goal>
</goals>
<configuration>
<classesDirectory>${project.build.directory}/alternateLocation</classesDirectory>
<outputDirectory>${project.build.directory}</outputDirectory>
<finalName>abc</finalName>
</configuration>
</execution>
</executions>
</plugin>
<!-- I am using this part of the code to delete the "alternateLocation" after everything is done, but it deletes the target directory instead -->
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>3.0.0</version>
<executions>
<execution>
<id>auto-clean</id>
<phase>install</phase>
<goals>
<goal>clean</goal>
</goals>
<configuration>
<filesets>
<fileset>
<directory>${project.build.directory}/alternateLocation</directory>
</fileset>
</filesets>
<excludeDefaultDirectories>${project.build.directory}</excludeDefaultDirectories>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
乾淨的插件基本上是在默認情況下刪除目標目錄。 那麼,如何從構建結束時的目標目錄中刪除「alternateLocation」文件夾。 (我猜你可以用maven-antrun-plugin來做,但我不想用這個插件。)。