我有来自同一个groupId(org.webjars
)的多个构件,我需要将它们解压缩,并将其中包含的所有js文件复制到相同的目录中。
这些构件的归档文件具有以下层次结构(作为jar压缩):
artifact1
- resources
- webjars
- ...
- sample-1.js
- sample-2.js
我需要在最后将每个JS文件复制到同一个目录中,不保留它们的层次结构,具体操作如下:
outputDirectory
- sample-1.js
- sample-2.js
- ...
- sample-n.js
我能够得到的结果是以下内容:
outputDirectory
- artifact-1
- resources
- webjars
- ...
- sample-1.js
- sample-2.js
- ...
- artifact-m
- resources
- webjars
- ...
- sample-n.js
为此,我使用了maven-dependency-plugin
:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>unpack org.webjars dependencies</id>
<goals>
<goal>unpack-dependencies</goal>
</goals>
<configuration>
<includeGroupIds>org.webjars</includeGroupIds>
<includes>**/*.js</includes>
<outputDirectory>${project.build.directory}/static</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
这个插件有没有类似魔法选项可以完成这个任务,还是我需要另一个插件来完成?
编辑:这是我最终使用的解决方案:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<id>copy org.webjars dependency to jar</id>
<phase>package</phase>
<goals><goal>run</goal></goals>
<configuration>
<target>
<copy todir="${project.build.directory}/classes/static" flatten="true">
<fileset dir="${project.build.directory}/static">
<include name="**/*.js"/>
</fileset>
</copy>
</target>
</configuration>
</execution>
</executions>
</plugin>
<!-- Force the generation of the jar to be done after the javascript dependencies have been copied.
Note : This is a half solution, as the jar is generated twice: a first time before the javascript get copied, and
another one after. As a result, there is the correct jar, but after two creations... -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<executions>
<execution>
<id>Force the jar-plugin to be called after the javascripts dependencies have been copied to be embedded</id>
<phase>package</phase>
<goals><goal>jar</goal></goals>
</execution>
</executions>
</plugin>