Maven:复制没有子目录结构的文件 [英] Maven : copy files without subdirectory structure
问题描述
我正在尝试使用Maven将给定文件夹中包含的所有* .xsd文件移动到另一个文件夹,但没有源子目录结构.
I am trying to use Maven to move all the *.xsd files contained in a given folder to another one, but without the source subdirectory structure.
这是我到目前为止所拥有的:
This is what I have so far:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>2.3</version>
<executions>
<execution>
<id>move-schemas</id>
<phase>generate-sources</phase>
<goals>
<goal>resources</goal>
</goals>
<configuration>
<outputDirectory>${basedir}/schemas-target</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
...
<resources>
<resource>
<directory>${basedir}/schemas-source</directory>
<includes>
<include>**/*.xsd</include>
</includes>
</resource>
</resources>
而且(几乎)可以正常工作.唯一的问题是,它保留了源子目录的结构,而我需要删除该层次结构并将所有xsd文件放在目标文件夹中.示例:
And it is (almost) working. The only problem is that it keeps the source subdirectory structure, while I need to remove that hierarchy and put all the xsd files in the target folder. Example:
这是我在schemas-source文件夹中拥有的内容:
This is what I have in the schemas-source folder:
schemas-source
│- current
│ │- 0.3
│ │- myfile.xsd
│- old
│- 0.2
│- myfile-0.2.xsd
这是我在schemas-target文件夹中所需要的:
and this is what I'd need in the schemas-target folder:
schemas-target
│- myfile.xsd
│- myfile-0.2.xsd
推荐答案
我自己一次又一次地撞到了那个限制.
I banged my head against that restriction myself, again and again.
基本上:我不认为只有Maven的解决方案.您将不得不使用动态的东西,例如
Basically: I don't think there's a maven only solution. You will have to resort to using something dynamic like
-
Maven Antrun插件
将ant任务嵌入到maven中,在本例中为ant 复制任务,类似这样:
The Maven Antrun Plugin
Embed ant tasks in maven, in this case an ant copy task, something like this:
<copy todir="${project.basedir}/schemas-target" flatten="true">
<fileset dir="${project.basedir}/schemas-source">
<include name="**/*.xsd"/>
</fileset>
</copy>
GMaven插件 使您可以从pom执行Groovy代码,如下所示:
The GMaven plugin Lets you execute Groovy code from your pom, something like this:
new File(pom.basedir, 'schemas-source').eachFileRecurse(FileType.FILES){
if(it.name.endsWith('.xsd')){
new File(pom.basedir, 'schemas-target/${it.name}').text = it.text;
}
}
这篇关于Maven:复制没有子目录结构的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!