Maven解压缩以忽略原始文件夹 [英] Maven unpack to disregard original folder

查看:99
本文介绍了Maven解压缩以忽略原始文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的一个项目具有这样的结构:

One of my projects has a structure like this:

.\ca\<modulename>\dist\<modulename>.zip

我想制作一个仅包含zip文件的软件包,因此,如果我有子模块mod1mod2modn,我将得到:

I want to make a package that just has the zip files in a single package, so if I have submodules mod1, mod2, modn, I'll end up with:

ZIP CONTENT:
  mod1.zip
  mod2.zip
  ...
  modn.zip

到目前为止,我所做的是创建一个maven项目,并使用maven dependencyassembly插件达到了这一目的:

What I've done so far is create a maven project and, using maven dependency and assembly plugins I got to this:

<plugins>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <executions>
                    <execution>
                        <id>unpack</id>
                        <phase>generate-sources</phase>
                        <goals>
                            <goal>unpack</goal>
                        </goals>

                        <configuration>
                            <artifactItems>
                                <artifactItem>
                                    <groupId>es.xunta.emprego.cntxes</groupId>
                                    <artifactId>myproject-cas</artifactId>
                                    <version>${cas.version}</version>
                                    <overWrite>true</overWrite>
                                    <outputDirectory>target/dependency</outputDirectory>
                                    <type>zip</type>
                                    <includes>ca/**/dist/*.zip</includes>
                                </artifactItem>
                            </artifactItems>
                        </configuration>
                    </execution>
                </executions>
            </plugin>


            <plugin>
                <artifactId>maven-assembly-plugin</artifactId>
                <configuration>
                    <descriptor>src/main/assembly/zip.xml</descriptor>
                    <appendAssemblyId>false</appendAssemblyId>
                </configuration>
                <executions>
                    <execution>
                        <id>make-assembly</id>
                        <!-- this is used for inheritance merges -->
                        <phase>package</phase>
                        <!-- append to the packaging phase. -->
                        <goals>
                            <goal>single</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>

此为assembly/zip.xml:

<?xml version="1.0" encoding="UTF-8" ?>
<assembly>
    <id>bin</id>
    <formats>
        <!-- formato de salida del empaquetado -->
        <format>zip</format>
    </formats>
    <includeBaseDirectory>false</includeBaseDirectory>
    <fileSets>
        <fileSet>
            <outputDirectory>/</outputDirectory>
            <directory>target/dependency</directory>
            <includes>
                <include>/**/dist/*.zip</include>
            </includes>
            <useDefaultExcludes>true</useDefaultExcludes>
        </fileSet>
    </fileSets>
</assembly>  

但这尊重我原始zip的文件夹结构,因此结果是:

But this is respecting my original zip's folder structure, so the result is:

ZIP CONTENT
   ca\mod1\dist\mod1.zip
   ca\mod2\dist\mod2.zip
   ...
   ca\modn\dist\modn.zip

这似乎是个小问题,但是模块的数量很大,而且必须浏览每个文件夹非常麻烦.我一直在为assemblydependency苦苦挣扎,但还没有找到实现我想要的方法的方法.请注意,我正在使用通配符(ca/**/dist/*.zip),因为在编译之前我不知道将存在的文件名.

It might seem a small issue but the number of modules is big and gathering the different zip files is very annoying having to browse through every folder. I've been struggling with assembly and dependency but haven't found a way to achieve what I want. Note that I'm using wildcards (ca/**/dist/*.zip) because I don't know prior to compilation the name of the files that will be there.

有什么需要帮助的吗?

Any help please?

推荐答案

我不知道是否有办法做到这一点,但是这个问题可能会帮助您找到解决方法:

I don't know if there's a way to do this but this question might help you find a way through : execute ant / groovy script inside maven

根据链接的答案,这是一个使用maven ANT插件的ANT示例(我现在无法尝试):

According to the linked answer, here is an ANT example (I can't try it right now) with the maven ANT plugin :

<plugins>
    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-dependency-plugin</artifactId>
        <executions>
            <execution>
                <id>unpack</id>
                <phase>generate-sources</phase>
                <goals>
                    <goal>unpack</goal>
                </goals>
                <configuration>
                    <artifactItems>
                        <artifactItem>
                            <groupId>es.xunta.emprego.cntxes</groupId>
                            <artifactId>myproject-cas</artifactId>
                            <version>${cas.version}</version>
                            <overWrite>true</overWrite>
                            <outputDirectory>target/dependency</outputDirectory>
                            <type>zip</type>
                            <includes>ca/**/dist/*.zip</includes>
                        </artifactItem>
                    </artifactItems>
                </configuration>
            </execution>
        </executions>
    </plugin>
    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-antrun-plugin</artifactId>
        <version>1.8</version>
        <executions>
            <execution>
                <id>move</id>
                <phase>generate-sources</phase>
                <goals>
                    <goal>run</goal>
                </goals>
                <configuration>
                    <target>
                        <copy todir="${project.basedir}/target/dependency" flatten="true">
                            <fileset dir="${project.basedir}/ca">
                                <include name="**/dist/*.zip"/>
                            </fileset>
                        </copy>
                    </target>
                </configuration>
            </execution>
        </executions>
    </plugin>
    ...
</plugins>

至少,为了确保插件在同一阶段的执行顺序,至少需要Maven 3.0.3版本.

At least, the version 3.0.3 of Maven is required in order to insure plugins execution order on same phase.

这篇关于Maven解压缩以忽略原始文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆