Maven创建扁平拉链组件 [英] Maven creating flat zip assembly
问题描述
向Maven专家咨询: 我正在尝试将非Java项目工件(.NET)打包到单个zip文件中.我有2个问题:
To Maven gurus out there: I'm trying to package non-java project artifacts (.NET) into a single zip file. I'm having 2 problems:
如果我将POM中的包装更改为zip <packaging>zip</packaging>
,则会收到以下错误消息:[INFO] Cannot find lifecycle mapping for packaging: 'zip'.
Component descriptor cannot be found in the component repository: org.apache.mav
en.lifecycle.mapping.LifecycleMappingzip.
好,没什么大不了-我将其更改为<packaging>pom</packaging>
来消除否则会在容器中创建的无用jar目标目录
If I change packaging in my POM to zip <packaging>zip</packaging>
, I get this error message: [INFO] Cannot find lifecycle mapping for packaging: 'zip'.
Component descriptor cannot be found in the component repository: org.apache.mav
en.lifecycle.mapping.LifecycleMappingzip.
OK, no big deal - I changed it to <packaging>pom</packaging>
to get rid of useless jar that is otherwise created in the target dir
我的主要问题是我打包到ZIP中的文件嵌套在几个目录中,但是我需要将它们放入ZIP的顶级目录中.这是我的汇编文件:
My main problem is that files I'm packaging into ZIP are nested within few directories but I need put these into top directory of ZIP. Here's my assembly file:
<assembly>
<id>bin</id>
<formats>
<format>zip</format>
</formats>
<fileSets>
<fileSet>
<directory>${basedir}/${project.artifactId}</directory>
<includes>
<include>**/Bin/Release/*.dll</include>
<include>**/Bin/Release/*.pdb</include>
</includes>
</fileSet>
</fileSets>
</assembly>
运行此命令时-我将获取ZIP文件,但文件将以C:\开头,后跟完整路径,是嵌套文件.给您一个想法-项目将其二进制文件转储为以下结构
ProjectFoo\ProjectFoo\subproject1\Bin\Release\foo.dll
,我需要ZIP\foo.dll
When I run this - I'll get ZIP file but files will be nested starting with C:\ followed by full path. To give you idea - project dumps it's binaries into the following structure
ProjectFoo\ProjectFoo\subproject1\Bin\Release\foo.dll
and I need ZIP\foo.dll
这里是程序集插件配置:
Here's assembly plugin configuration:
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<descriptors>
<descriptor>assembly.xml</descriptor>
</descriptors>
</configuration>
<executions>
<execution>
<id>zip</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
也许我只需要使用antrun并执行ant zip任务?
Maybe I just need to use antrun and execute ant zip task?
推荐答案
如您所见,没有zip打包类型,因此按您的意愿使用pom打包是有意义的.
As you've seen, there isn't a zip packaging type, so it makes sense to use pom packaging as you've chosen to.
您在程序集插件的处理过程中遇到了一些漏洞.您可以通过在程序集中用<outputDirectory>/<outputDirectory>
指定多个fileSet来解决此问题,每个要包含的目录都指定一个,这显然是PITA,并且可能不是可接受的解决方案.
You've encountered a bit of a hole in the assembly plugin's processing. You could resolve this by specifying multiple fileSets in the assembly with <outputDirectory>/<outputDirectory>
, one for each directory you want to include, this is obviously a PITA, and probably not an acceptable solution.
另一种方法是使用Ant复制任务将所有DLL复制到暂存目录,然后将该目录包含在程序集中.
An alternative approach is to use the Ant copy task to copy all the DLLs into a staging directory, then include that directory in the assembly.
以下配置应执行的操作:
The following configuration should do what you're after:
antrun-plugin配置:
The antrun-plugin configuration:
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.3</version>
<executions>
<execution>
<phase>process-resources</phase>
<configuration>
<tasks>
<copy todir="${project.build.directory}/dll-staging">
<fileset dir="${basedir}/${project.artifactId}">
<include name="**/Bin/Release/*.dll"/>
<include name="**/Bin/Release/*.pdb"/>
</fileset>
<flattenmapper/>
</copy>
</tasks>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
程序集:
<assembly>
<id>bin</id>
<formats>
<format>zip</format>
</formats>
<fileSets>
<fileSet>
<directory>${project.build.directory}/dll-staging</directory>
<outputDirectory>/</outputDirectory>
<includes>
<include>*.dll</include>
<include>*.pdb</include>
</includes>
</fileSet>
</fileSets>
</assembly>
这篇关于Maven创建扁平拉链组件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!