views:

1973

answers:

1

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?

+5  A: 

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>
Rich Seller
Exactly what I needed! Thank you Rich!
DroidIn.net
you are welcome
Rich Seller
There's still one problem though. The zip still maintains one top directory of type "artifactId-Version". When I extract zip all my files end up not in `/` but in `/Foo-1.0-SNAPSHOT/`. Yet the files are correctly copied into target/dll-staging
DroidIn.net
Actually - putting `<includeBaseDirectory>false</includeBaseDirectory>` into assembly does the trick
DroidIn.net
(Thanks for saving our bacon here too - nice one!)
Jeremy McGee