You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@maven.apache.org by "Sundling, Paul" <pa...@sonyconnect.com> on 2008/04/26 04:27:59 UTC

shade, assemble and uberwars

My use case is the following
1. include all the dependent jars into a shaded jar/jar with
dependencies/uberjar with some environment specific properties file
filtered/excluded.
2. include the resulting uberjar into an assembly with a bunch of other
files in a zip file. 
 
Shade incompatibility
 
The shade plugin works great for creating a jar with the included
dependencies, however because of this bug
(http://jira.codehaus.org/browse/MSHADE-23) I can't use it with the
assembly plugin.  A workaround would be to comment out the assembly part
of the pom, run maven, uncomment assembly part and comment out shade and
then do a non clean build.  Obviously that's not acceptable.  So I gave
up on the shade plugin.
 
Problems with Assemble
 
The assembly plugin by itself can do 90% of what I need.  I ran into
some problems:
1. excluding specific files for the jar-with-dependencies like the shade
plugin (UNSOLVED)
2. why is junit (test scope) brought in when using runtime scope?
(UNSOLVED)
3. controlling assembly order (SOLVED)
 
UNSOLVED assembly issue 1
 
The shade has great support for filtering, like below where I can
exclude specific files from a specific artifact.  In the assembly
dependencySet section I can exclude overall dependencies (junit:junit),
but not files or directories within an artifact.  Is there something I'm
missing in how to exclude thing at a more granular level?  Anyone have a
workaround?
 
Example shade filtering section:
              <filters>
                <!-- beanutils contains a subset of commons collections
classes, causing conflict -->
                <filter>
 
<artifact>commons-beanutils:commons-beanutils</artifact>
                  <excludes>
                    <exclude>org/apache/commons/collections/**</exclude>
                  </excludes>
                </filter>
                <filter>
 
<artifact>${project.groupId}:${project.artifactId}</artifact>
                  <excludes>
                    <exclude>log4j.properties</exclude>
                    <exclude>packager.properties</exclude>
                  </excludes>
                </filter>
 
Actual assembly:
<assembly>
  <id>jar-with-dependencies</id>
  <formats>
    <format>jar</format>
  </formats>
  <includeBaseDirectory>false</includeBaseDirectory>
  <dependencySets>
    <dependencySet>
      <outputDirectory></outputDirectory>
      <outputFileNameMapping></outputFileNameMapping>
      <unpack>true</unpack>
      <scope>runtime</scope>
      <excludes>
        <exclude>junit:junit</exclude>
        <exclude>log4j:log4j</exclude>
        <!-- This didn't work <exclude>log4j.properties</exclude>
        <exclude>packager.properties</exclude>-->
      </excludes>
    </dependencySet>
  </dependencySets>
</assembly>

 
UNSOLVED assembly issue 2
 I'm not sure why junit was brought in since it's test scope.  Note the
assembly has scope runtime and I ran 'mvn help:effective-pom' to verify
junit was indeed test scope.  Seems like a bug. 
 
 
 
SOLUTION assemble issue 3
The first gotcha with assembly plugin, if mixing and matching descriptor
and descriptorRef, you can't control order.  So if using the built in
jar-with-dependencies descriptorRef, it would always build the zip file
then build the uberjar that was meant to be in inserted in the zip!
 
This is an example:
 
          <descriptorRefs>
            <descriptorRef>jar-with-dependencies</descriptorRef>
          </descriptorRefs>
          <descriptors>
            <descriptor>${basedir}/assembly.xml</descriptor>
          </descriptors>
 
First approach to fix it (and second gotcha) was to use two seperate
declarations of the assembly plugin and apply them with different
lifecycle methods to control ordering.  Instead what happens is
whichever declaration of the assembly plugin is first gets done twice!
 
So what does work?  Don't mix descriptorRef and descriptor.  Just create
your own copy of the deployment descriptor which you can find at
http://maven.apache.org/plugins/maven-assembly-plugin/descriptor-refs.ht
ml and save it as a file locally.  Then refer to it as in your config in
the order you want them executed:
 
          <descriptors>
 
<descriptor>${basedir}/assembly-with-dependencies.xml</descriptor>   
            <descriptor>${basedir}/assembly.xml</descriptor>
          </descriptors>
 
Paul Sundling

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org