2
votes

Hi i created a assembly to zip images of the project, and i hooked it to package phase in my pom file, the problem here is when i execute "clean compile package " it is creating my required zip file along with a file -jar-with-dependencies.jar which i dont want to create. how can i supress generating this jar file

here is my pom

<plugin>
    <artifactId>maven-assembly-plugin</artifactId>
    <inherited>false</inherited>
    <configuration>
        <descriptors>
            <descriptor>
                src/main/assembly/cat_image_resources_assembly.xml
            </descriptor>
        </descriptors>
    </configuration>
    <executions>
      <execution>
        <id>cat_image_resources</id>
        <phase>package</phase>
        <goals>
          <goal>single</goal>
        </goals>
        <configuration>
            <!-- appendAssemblyId>false</appendAssemblyId>
            <Change the name to standard name >
            <finalName>renameImages</finalName-->
        </configuration>
      </execution>
    </executions>
</plugin>

assembly file cat_image_resources_assembly.xml

<assembly>
<id>cat_image_resources</id>
<formats>
    <format>zip</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<baseDirectory>${artifactId}</baseDirectory>
<fileSets>
    <fileSet>
        <directory>exportedImages</directory>
        <outputDirectory/>
        <fileMode>644</fileMode>
    </fileSet>
</fileSets>
</assembly>

it is generating following files

CATImageExport2-1.0-SNAPSHOT-cat_image_resources.zip (5mb which is required), CATImageExport2-1.0-SNAPSHOT-jar-with-dependencies.jar(58mb this is with dependencies which i want to exclude generating)

4

4 Answers

1
votes

the problem here is when i execute "clean compile package " it is creating my required zip file along with a file -jar-with-dependencies.jar which i dont want to create.

The -jar-with-dependencies.jar file is typically created if you use the jar-with-dependencies pre-defined descriptor. The snippet you provided doesn't show anything like that and works as expected (after pasting it in a test POM):

$ ls target
archive-tmp     Q4068706-1.0-SNAPSHOT-cat_image_resources.zip  test-classes
classes         Q4068706-1.0-SNAPSHOT.jar
maven-archiver  surefire-reports

Double check that you're not inheriting a plugin configuration from a parent POM (for example with mvn help:effective-pom) because the XML snippet you provided works as expected.

0
votes

Are you sure that it's the assembly plug-in creating the dependencies jar file?

I say that because it looks like the assembly plug-in is doing exactly as you specified. However, without seeing more of project's pom.xml file, I cannot rule out that there's not another plug-in in pom.xml file for the project or even a parent pom.xml file that could be creating the dependencies jar file for you.

0
votes

re:"is there a way that i can override parent poms definition? i mean is it possible to ignore parent pom definition and had my own descriptor so that jar-with-dependencies should not interfere my pom."

I've fumbled around with this a bit in the past, and could never quite get maven to do what I wanted. I'm pretty sure the short answer is "no", but I'll elaborate on what I've tried.

  1. I created pluginManagement entry for the assembly plugin with two executions, each with a unique ID and configuration. Then in the assembly plugin in the plugins section, I added an executions section with ONLY one execution with an id matching the id of the execution I really wanted to run. It still ran both.

  2. I created a pluginManagement entry for the assembly plugin with one execution with a unique id and configuration. Then in the plugins section I created an entry for the assembly plugin with one execution and a different id and configuration. It still ran both.

  3. I created a pluginManagement entry for the assembly plugin with one execution with a unique id and configuration. Then in the plugins section I created an entry for the assembly plugin with one execution and the same id, this time specifying a completely different configuration. It apparently merged the two configurations together and produced the result of both of the configurations. Note: the configuration in the pluginManagement section used a descriptor entry, and the one in the plugins section used a descriptorRef entry. I tried adding an empty descriptors entry to the configuration in the plugins section hoping it would override (and essentially wipe out) the usage of the descriptor specified in the pluginManagement section, but no such luck.

I believe maven will always merge the parent plugins with child plugins and essentially overwrites nothing, greedily merging matching tags (more is better philosophy, so it doesn't choose the subelements of one tag over the subelements of another).

As far as the philosophy goes, the assembly plugin is there to help you build custom artifacts (and in maven each project should produce one main artifact, not counting sources classifiers, etc.), so if multiple children need to use the assembly plugin you would only put what is common to all of them in the parent pom. If you don't have anything that is common to all of the maven-assembly-plugin configurations/executions, I think you need to move the assembly plugin configuration to each of the child projects.

0
votes

Not much to add to Kevin's answer regarding all the configuration inheritance that Maven is doing. However, if you can change the parent POM (without affecting it's behaviour) one option is the following:

  1. In the parent, define the <descriptorRefs> element that links to jar-with-dependencies in a <configuration> element for a 'default' <execution>. I.e. not as part of the <configuration> of the plugin.
  2. In the child, skip the 'default' <execution> (which will thus disble jar-with-dependencies) and add your own <execution> with its <configuration>.

An example of this can be found here:

https://github.com/demobox/jar-with-deps-vs-spi/blob/master/pom.xml

There, the default is overridden in the 'with-services-handler' profile rather than a child POM, but the mechanism should be the same.