我有几个来自同一个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>
发布于 2014-12-31 06:31:14
您可以通过使用带有flatten选项的复制任务来使用maven antrun插件,如以下线程中所述:Maven : copy files without subdirectory structure
最好的
发布于 2018-01-26 03:43:11
刚刚遇到了一个类似的问题,(因为我不是在Maven中运行过时Ant的狂热粉丝,在今天和今天)我最终使用了org.apache.portals.jetspeed-2:jetspeed-unpack-maven-plugin (mvnrepository link here)。在它的配置中,您可以指定一个true选项,该选项将根据需要扁平化目录结构。
发布于 2021-08-03 08:24:25
你可以使用Maven Dep. plugin "Rewriting target path and file name"中描述的文件映射器:我可以像这样使用它:
<execution>
<id>include-run-java-sh-for-docker</id>
<phase>package</phase>
<goals>
<goal>unpack</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>io.fabric8</groupId>
<artifactId>run-java-sh</artifactId>
<version>1.3.8</version>
<classifier>sources</classifier>
<includes>**/fp-files/*.sh</includes>
<outputDirectory>${project.build.directory}/jkube</outputDirectory>
<fileMappers>
<org.codehaus.plexus.components.io.filemappers.FlattenFileMapper />
</fileMappers>
</artifactItem>
</artifactItems>
https://stackoverflow.com/questions/27708247
复制相似问题