Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Maven creating flat zip assembly

Tags:

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:

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

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> 

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> 

Maybe I just need to use antrun and execute ant zip task?

like image 507
Bostone Avatar asked Sep 30 '09 21:09

Bostone


People also ask

What is fileset in Maven?

Defines the rules for matching and working with files in a given base directory. Element.

What is assembly descriptor in Maven?

This descriptor specifies the type of assembly archive to create, the contents of the assembly, and the ways in which dependencies or its modules are bundled with an assembly. <assembly xmlns="http://maven.apache.org/ASSEMBLY/2.1.1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

What is the purpose of Maven Assembly plugin?

The Assembly Plugin for Maven enables developers to combine project output into a single distributable archive that also contains dependencies, modules, site documentation, and other files. Your project can easily build distribution "assemblies" using one of the prefabricated assembly descriptors.


1 Answers

As you've seen, there isn't a zip packaging type, so it makes sense to use pom packaging as you've chosen to.

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.

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:

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> 

The assembly:

 <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> 
like image 183
Rich Seller Avatar answered Oct 13 '22 22:10

Rich Seller