我有多个模块项目,每个模块都有不同的配置文件夹。现在,我想使用Maven和Assembly创建基于zip文件的配置文件夹。
Project
|
---module 1
| |
| ---dir 1
| |
| ---dir 2
| |
| ---dir3
| |
| ---src
|
---module 2
|
---dir 1
|
---dir 2
|
---src
我的要求是根据目录名称创建zip文件。该项目有50多个模块,每个模块都有不同的目录名称。
请提出建议。
添加子pom.xml
<build>
<plugins>
<plugin>
<groupId>com.soebes.maven.plugins</groupId>
<artifactId>iterator-maven-plugin</artifactId>
<executions>
<execution>
<id>collective-package</id>
<configuration>
<items>
<item>dir 1</item>
<item>dir 2</item>
<item>dir 3</item>
</items>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
<testSourceDirectory>test-integration-src</testSourceDirectory>
</build>
父pom.xml
<plugin>
<groupId>com.soebes.maven.plugins</groupId>
<artifactId>iterator-maven-plugin</artifactId>
<version>0.5.0</version>
<executions>
<execution>
<id>collective-package</id>
<phase>package</phase>
<goals>
<goal>iterator</goal>
</goals>
<configuration>
<pluginExecutors>
<pluginExecutor>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>3.1.0</version>
</plugin>
<configuration>
<descriptors>
<descriptor>assembly/zip_assembly.xml</descriptor>
</descriptors>
<finalName>@item@</finalName>
</configuration>
<goal>single</goal>
</pluginExecutor>
</pluginExecutors>
</configuration>
</execution>
</executions>
</plugin>
zip_assembly.xml
<assembly
xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0 http://maven.apache.org/xsd/assembly-1.1.0.xsd">
<id>${project.version}</id>
<includeBaseDirectory>false</includeBaseDirectory>
<formats>
<format>tar.gz</format>
</formats>
<moduleSets>
<moduleSet>
<useAllReactorProjects>true</useAllReactorProjects>
<includes>
<include>com.test:*</include>
</includes>
<sources>
<excludeSubModuleDirectories>false</excludeSubModuleDirectories>
<fileSets>
<fileSet>
<directory>${project.basedir}/target/classes</directory>
<outputDirectory>conf</outputDirectory>
<includes>
<include>*</include>
</includes>
<excludes>
<exclude>com</exclude>
<exclude>schema</exclude>
</excludes>
</fileSet>
<fileSet>
<directory>${project.basedir}/../modulex/conf</directory>
<outputDirectory>conf</outputDirectory>
<includes>
<include>*</include>
</includes>
</fileSet>
<fileSet>
<directory>${project.basedir}/../modulex/scripts</directory>
<outputDirectory>/</outputDirectory>
<includes>
<include>*.sh</include>
</includes>
</fileSet>
<fileSet>
<directory>${project.basedir}/conf/<need here @item@></directory> <!--need directory name from parent/child pom.xml . sothat it picks the files from dir x-->
<outputDirectory>conf</outputDirectory>
<includes>
<include>*</include>
</includes>
</fileSet>
<fileSet>
<directory>${project.basedir}/../core/scripts</directory>
<outputDirectory>/</outputDirectory>
<includes>
<include>*.sh</include>
</includes>
</fileSet>
<fileSet>
<directory>${project.basedir}/target</directory>
<outputDirectory>lib</outputDirectory>
<includes>
<include>*.jar</include>
</includes>
<excludes>
<exclude>*-tests.jar</exclude>
</excludes>
</fileSet>
</fileSets>
</sources>
</moduleSet>
</moduleSets>
我可以为每个目录创建zip,但不能将dir x下的文件包含到zip中。因为我在运行时无法在zip_assembly.xml中获取目录名称
我们如何将@ item @的值传递给zip_assembly.xml文件
答案 0 :(得分:0)
找到解决方案。使用maven-antrun-plugin代替maven-assembly-plugin