1

Below is my configuration of maven-assembly-plugin and it's working fine. However, when I add all my plugins inside the pluginManagement parent tag, it's not working.

I am not sure why it's not working.

<plugin>
    <artifactId>maven-assembly-plugin</artifactId>
    <version>2.2</version>
    <executions>
        <execution>
            <id>MyId</id>
            <phase>package</phase>
            <goals>
                <goal>single</goal>
            </goals>
            <configuration>
                <descriptor>assemblyFile.xml</descriptor>
                <appendAssemblyId>false</appendAssemblyId>
            </configuration>
        </execution>
    </executions>
</plugin>
Adrian Mole
  • 49,934
  • 160
  • 51
  • 83
Niraj Sonawane
  • 10,225
  • 10
  • 75
  • 104
  • 1
    First you are using an very old version of maven-assembly-plugin furthermore the pluginManagement is intended to define versions and configurations of plugins but not to really execute plugins (meaning binding to the life cycle)... – khmarbaise Jan 04 '18 at 08:15
  • @khmarbaise thanks, yes added dependency to bind to the life cycle . That was miss from my side :) – Niraj Sonawane Jan 04 '18 at 09:13

1 Answers1

2

The execution section of your maven-assembly-plugin should not be contained in a pluginManagement section. If it is, it will be ignored. The build will not throw an error - just won't create an executable jar. Then you would get "no main manifest attribute..." if you try to run it.

The pluginManagement section, generally defined in a "parent" pom, shares plugin configuration across modules. It can specify version and configuration and it ensures the version matches across child poms, but is not intended to contain execution details.

Here's a valid example where pluginManagement specifies only the plugin's version (just keep in mind the pluginManagement would typically be in a separate, parent, pom):

<build>
    <pluginManagement>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-assembly-plugin</artifactId>
                <version>2.4.1</version>
            </plugin>
        </plugins>
    </pluginManagement>
    <plugins>
        <plugin>
            <artifactId>maven-assembly-plugin</artifactId>
            <configuration>
                <descriptorRefs>
                    <descriptorRef>jar-with-dependencies</descriptorRef>
                </descriptorRefs>
                <archive>
                    <manifest>
                        <mainClass>com.my.App</mainClass>
                    </manifest>
                </archive>
            </configuration>
            <executions>
                <execution>
                    <id>make-assembly</id>
                    <phase>package</phase>
                    <goals>
                        <goal>single</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

And here's an example where pluginManagement has the plugin's version and also its configuration. The regular plugin section specifies only the execution details:

<build>
    <pluginManagement>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-assembly-plugin</artifactId>
                <version>2.4.1</version>
                <configuration>
                    <descriptorRefs>
                        <descriptorRef>jar-with-dependencies</descriptorRef>
                    </descriptorRefs>
                    <archive>
                        <manifest>
                            <mainClass>com.my.App</mainClass>
                        </manifest>
                    </archive>
                </configuration>
            </plugin>
        </plugins>
    </pluginManagement>
    <plugins>
        <plugin>
            <artifactId>maven-assembly-plugin</artifactId>
            <version>2.3</version>
            <executions>
                <execution>
                    <id>make-assembly</id>
                    <phase>package</phase>
                    <goals>
                        <goal>single</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

Note that child poms can override pluginManagement definitions.

See also this question and its answers.

Woodchuck
  • 3,869
  • 2
  • 39
  • 70