Search code examples
javamavenmaven-assembly-plugin

What could lead to a jar-with-dependencies being empty except for the manifest?


I started with an existing maven build of an open-source project I'd like to use. It builds fine.

I added a new profile (standalone-server-and-client) to the parent pom hoping to construct two jars using the maven-assembly-plugin, one for the client, one for the server, each with all their dependencies and a main class specified in the pom. Both jars are built when running the build with the profile activated.

However, they are empty except for the manifest. What could lead to that behavior? The original pom also includes the maven-jar-plugin, could these mess with each other?

This is the full pom.xml:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>org.eclipse.milo</groupId>
    <artifactId>milo</artifactId>
    <version>0.2.0-SNAPSHOT</version>
    <packaging>pom</packaging>

    <name>Eclipse Milo - OPC-UA (IEC 62541)</name>
    <description>An open source implementation of OPC-UA (IEC 62541).</description>
    <url>https://github.com/eclipse/milo</url>

    <scm>
        <url>https://github.com/eclipse/milo</url>
        <connection>scm:git:git://github.com/eclipse/milo.git</connection>
        <developerConnection>scm:git:git@github.com:eclipse/milo.git</developerConnection>
        <tag>HEAD</tag>
    </scm>

    <developers>
        <developer>
            <id>kevinherron</id>
            <name>Kevin Herron</name>
            <email>kevinherron@gmail.com</email>
        </developer>
    </developers>

    <licenses>
        <license>
            <name>Eclipse Public License 1.0</name>
            <url>https://eclipse.org/org/documents/epl-v10.php</url>
            <distribution>repo</distribution>
        </license>
        <license>
            <name>Eclipse Distribution License 1.0</name>
            <url>https://eclipse.org/org/documents/edl-v10.php</url>
            <distribution>repo</distribution>
        </license>
    </licenses>

    <modules>
        <module>build-tools</module>
        <module>milo-examples</module>
        <module>opc-ua-stack</module>
        <module>opc-ua-sdk</module>
    </modules>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
    </properties>

    <prerequisites>
        <maven>3.0.5</maven>
    </prerequisites>

    <profiles>
        <profile>
            <id>release</id>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-source-plugin</artifactId>
                        <version>3.0.1</version>
                        <executions>
                            <execution>
                                <id>attach-sources</id>
                                <goals>
                                    <goal>jar-no-fork</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>

                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-javadoc-plugin</artifactId>
                        <version>2.10.4</version>
                        <configuration>
                            <failOnError>false</failOnError>
                            <additionalparam>-Xdoclint:none</additionalparam>
                        </configuration>
                        <executions>
                            <execution>
                                <id>attach-javadocs</id>
                                <goals>
                                    <goal>jar</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>

                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-jar-plugin</artifactId>
                        <version>3.0.2</version>
                        <extensions>false</extensions>
                        <inherited>true</inherited>
                    </plugin>

                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-gpg-plugin</artifactId>
                        <version>1.6</version>
                        <executions>
                            <execution>
                                <id>sign-artifacts</id>
                                <phase>verify</phase>
                                <goals>
                                    <goal>sign</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>

                    <plugin>
                        <groupId>org.sonatype.plugins</groupId>
                        <artifactId>nexus-staging-maven-plugin</artifactId>
                        <version>1.6.7</version>
                        <extensions>true</extensions>
                        <configuration>
                            <serverId>ossrh</serverId>
                            <nexusUrl>https://oss.sonatype.org/</nexusUrl>
                            <autoReleaseAfterClose>true</autoReleaseAfterClose>
                        </configuration>
                    </plugin>
                </plugins>
            </build>
        </profile>

        <profile>
            <id>javadoc-and-source</id>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-source-plugin</artifactId>
                        <version>3.0.1</version>
                        <executions>
                            <execution>
                                <id>attach-sources</id>
                                <goals>
                                    <goal>jar-no-fork</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>

                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-javadoc-plugin</artifactId>
                        <version>2.9.1</version>
                        <configuration>
                            <failOnError>false</failOnError>
                            <additionalparam>-Xdoclint:none</additionalparam>
                        </configuration>
                        <executions>
                            <execution>
                                <id>attach-javadocs</id>
                                <goals>
                                    <goal>jar</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>

        <profile>
            <id>standalone-server-and-client</id>
            <build>
                <plugins>
                    <plugin>
                        <artifactId>maven-assembly-plugin</artifactId>
                        <version>3.1.0</version>
                        <executions>
                            <execution>
                                <id>build-client</id>
                                <configuration>
                                    <archive>
                                        <manifest>
                                            <mainClass>org.eclipse.milo.examples.client.SecureClientStandalone</mainClass>
                                        </manifest>
                                    </archive>
                                    <descriptorRefs>
                                        <descriptorRef>jar-with-dependencies</descriptorRef>
                                    </descriptorRefs>
                                    <finalName>${project.artifactId}-client</finalName>
                                </configuration>
                                <phase>package</phase>
                                <goals>
                                    <goal>single</goal>
                                </goals>
                            </execution>
                            <execution>
                                <id>build-server</id>
                                <configuration>
                                    <archive>
                                        <manifest>
                                            <mainClass>org.eclipse.milo.examples.server.SecureServerStandalone</mainClass>
                                        </manifest>
                                    </archive>
                                    <descriptorRefs>
                                        <descriptorRef>jar-with-dependencies</descriptorRef>
                                    </descriptorRefs>
                                    <finalName>${project.artifactId}-server</finalName>
                                </configuration>
                                <phase>package</phase>
                                <goals>
                                    <goal>single</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>
    </profiles>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-checkstyle-plugin</artifactId>
                <version>2.17</version>
                <configuration>
                    <configLocation>milo/checkstyle.xml</configLocation>
                    <excludes>
                        **/Ua*Loader*,
                        **/org/eclipse/milo/opcua/stack/core/types/structured/*,
                        **/org/eclipse/milo/opcua/stack/core/types/enumerated/*,
                        **/org/eclipse/milo/opcua/sdk/core/CefactEngineeringUnits.java,
                        **/org/eclipse/milo/opcua/sdk/client/model/nodes/objects/*,
                        **/org/eclipse/milo/opcua/sdk/client/model/nodes/variables/*,
                        **/org/eclipse/milo/opcua/sdk/client/model/types/objects/*,
                        **/org/eclipse/milo/opcua/sdk/client/model/types/variables/*,
                        **/org/eclipse/milo/opcua/sdk/server/model/nodes/objects/*,
                        **/org/eclipse/milo/opcua/sdk/server/model/nodes/variables/*,
                        **/org/eclipse/milo/opcua/sdk/server/model/types/objects/*,
                        **/org/eclipse/milo/opcua/sdk/server/model/types/variables/*,
                        **/org/eclipse/milo/opcua/stack/core/Identifiers.java,
                        **/org/eclipse/milo/opcua/stack/core/types/builtin/unsigned/*,
                        **/org/eclipse/milo/opcua/stack/core/StatusCodes.java,
                        **/org/opcfoundation/opcua/binaryschema/*
                    </excludes>
                </configuration>
                <dependencies>
                    <dependency>
                        <groupId>com.puppycrawl.tools</groupId>
                        <artifactId>checkstyle</artifactId>
                        <version>7.1.1</version>
                    </dependency>
                    <dependency>
                        <groupId>org.eclipse.milo</groupId>
                        <artifactId>build-tools</artifactId>
                        <version>${project.version}</version>
                    </dependency>
                    <dependency>
                        <groupId>org.slf4j</groupId>
                        <artifactId>jcl-over-slf4j</artifactId>
                        <version>1.7.21</version>
                    </dependency>
                    <dependency>
                        <groupId>org.slf4j</groupId>
                        <artifactId>slf4j-jdk14</artifactId>
                        <version>1.7.21</version>
                    </dependency>
                </dependencies>
                <executions>
                    <execution>
                        <id>validate</id>
                        <phase>validate</phase>
                        <configuration>
                            <configLocation>milo/checkstyle.xml</configLocation>
                            <excludes>
                                **/Ua*Loader*,
                                **/org/eclipse/milo/opcua/stack/core/types/structured/*,
                                **/org/eclipse/milo/opcua/stack/core/types/enumerated/*,
                                **/org/eclipse/milo/opcua/sdk/core/CefactEngineeringUnits.java,
                                **/org/eclipse/milo/opcua/sdk/client/model/nodes/objects/*,
                                **/org/eclipse/milo/opcua/sdk/client/model/nodes/variables/*,
                                **/org/eclipse/milo/opcua/sdk/client/model/types/objects/*,
                                **/org/eclipse/milo/opcua/sdk/client/model/types/variables/*,
                                **/org/eclipse/milo/opcua/sdk/server/model/nodes/objects/*,
                                **/org/eclipse/milo/opcua/sdk/server/model/nodes/variables/*,
                                **/org/eclipse/milo/opcua/sdk/server/model/types/objects/*,
                                **/org/eclipse/milo/opcua/sdk/server/model/types/variables/*,
                                **/org/eclipse/milo/opcua/stack/core/Identifiers.java,
                                **/org/eclipse/milo/opcua/stack/core/types/builtin/unsigned/*,
                                **/org/eclipse/milo/opcua/stack/core/StatusCodes.java,
                                **/org/opcfoundation/opcua/binaryschema/*
                            </excludes>
                            <encoding>UTF-8</encoding>
                            <consoleOutput>true</consoleOutput>
                            <failsOnError>true</failsOnError>
                            <failOnViolation>true</failOnViolation>
                        </configuration>
                        <goals>
                            <goal>check</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>

        <pluginManagement>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <version>3.5.1</version>
                    <configuration>
                        <source>1.8</source>
                        <target>1.8</target>
                    </configuration>
                    <executions>
                        <!-- Replacing default-compile as it is treated specially by maven -->
                        <execution>
                            <id>default-compile</id>
                            <phase>none</phase>
                        </execution>
                        <!-- Replacing default-testCompile as it is treated specially by maven -->
                        <execution>
                            <id>default-testCompile</id>
                            <phase>none</phase>
                        </execution>
                        <execution>
                            <id>java-compile</id>
                            <phase>compile</phase>
                            <goals>
                                <goal>compile</goal>
                            </goals>
                        </execution>
                        <execution>
                            <id>java-test-compile</id>
                            <phase>test-compile</phase>
                            <goals>
                                <goal>testCompile</goal>
                            </goals>
                        </execution>
                    </executions>
                </plugin>

                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-jar-plugin</artifactId>
                    <version>3.0.2</version>
                    <configuration>
                        <archive>
                            <manifest>
                                <addDefaultImplementationEntries>true</addDefaultImplementationEntries>
                            </manifest>
                            <manifestFile>${project.build.outputDirectory}/META-INF/MANIFEST.MF</manifestFile>
                        </archive>
                    </configuration>
                </plugin>

                <plugin>
                    <groupId>org.apache.felix</groupId>
                    <artifactId>maven-bundle-plugin</artifactId>
                    <version>3.2.0</version>
                    <executions>
                        <execution>
                            <id>generate-manifest</id>
                            <phase>process-classes</phase>
                            <goals>
                                <goal>manifest</goal>
                            </goals>
                            <configuration>
                                <supportedProjectTypes>
                                    <supportedProjectType>jar</supportedProjectType>
                                    <supportedProjectType>bundle</supportedProjectType>
                                </supportedProjectTypes>
                                <instructions>
                                    <Import-Package>
                                        com.sun.management.*;resolution:=optional,
                                        !javax.annotation.*,
                                        *
                                    </Import-Package>
                                </instructions>
                            </configuration>
                        </execution>
                    </executions>
                </plugin>

                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-release-plugin</artifactId>
                    <version>2.5.3</version>
                    <configuration>
                        <autoVersionSubmodules>true</autoVersionSubmodules>
                        <useReleaseProfile>false</useReleaseProfile>
                        <releaseProfiles>release</releaseProfiles>
                        <goals>deploy</goals>
                        <tagNameFormat>v@{project.version}</tagNameFormat>
                    </configuration>
                </plugin>
            </plugins>
        </pluginManagement>
    </build>

    <reporting>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-checkstyle-plugin</artifactId>
                <version>2.17</version>
                <configuration>
                    <configLocation>milo/checkstyle.xml</configLocation>
                    <excludes>
                        **/Ua*Loader*,
                        **/org/eclipse/milo/opcua/stack/core/types/structured/*,
                        **/org/eclipse/milo/opcua/stack/core/types/enumerated/*,
                        **/org/eclipse/milo/opcua/sdk/client/api/model/nodes/objects/*,
                        **/org/eclipse/milo/opcua/sdk/client/api/model/nodes/variables/*,
                        **/org/eclipse/milo/opcua/sdk/client/api/model/types/objects/*,
                        **/org/eclipse/milo/opcua/sdk/client/api/model/types/variables/*,
                        **/org/eclipse/milo/opcua/sdk/server/model/nodes/objects/*,
                        **/org/eclipse/milo/opcua/sdk/server/model/nodes/variables/*,
                        **/org/eclipse/milo/opcua/sdk/server/model/types/objects/*,
                        **/org/eclipse/milo/opcua/sdk/server/model/types/variables/*,
                        **/org/eclipse/milo/opcua/stack/core/Identifiers.java,
                        **/org/eclipse/milo/opcua/stack/core/types/builtin/unsigned/*,
                        **/org/eclipse/milo/opcua/stack/core/StatusCodes.java
                    </excludes>
                </configuration>
            </plugin>
        </plugins>
    </reporting>

    <distributionManagement>
        <snapshotRepository>
            <id>ossrh</id>
            <url>https://oss.sonatype.org/content/repositories/snapshots</url>
        </snapshotRepository>
        <repository>
            <id>ossrh</id>
            <url>https://oss.sonatype.org/service/local/staging/deploy/maven2/</url>
        </repository>
    </distributionManagement>
</project>

Solution

  • The hint provided by a helpful commenter turned out to be correct:

    It did not work in the pom with <packaging>pom</packaging>. I moved the profile down two levels, into the module, where there was no packaging specified, so that the default packaging jar was used.

    Below is my working configuration (same thing has been done in the module with the server). It is the same configuration I had in the other pom (minus the server part), but it works here. Also make sure you look into the correct target folder now - it will be in the target folder of the module.

    <?xml version="1.0" encoding="UTF-8"?>
    <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
        <modelVersion>4.0.0</modelVersion>
    
        <parent>
            <groupId>org.eclipse.milo</groupId>
            <artifactId>milo-examples</artifactId>
            <version>0.2.0-SNAPSHOT</version>
        </parent>
    
        <artifactId>client-examples</artifactId>
    
        <profiles>
            <profile>
                <id>standalone-server-and-client</id>
                <build>
                    <plugins>
                        <plugin>
                            <artifactId>maven-assembly-plugin</artifactId>
                            <version>3.1.0</version>
                            <executions>
                                <execution>
                                    <id>build-client</id>
                                    <configuration>
                                        <archive>
                                            <manifest>
                                                <mainClass>org.eclipse.milo.examples.client.SecureClientStandalone</mainClass>
                                            </manifest>
                                        </archive>
                                        <descriptorRefs>
                                            <descriptorRef>jar-with-dependencies</descriptorRef>
                                        </descriptorRefs>
                                        <finalName>milo-opcua-client</finalName>
                                    </configuration>
                                    <phase>package</phase>
                                    <goals>
                                        <goal>single</goal>
                                    </goals>
                                </execution>
                            </executions>
                        </plugin>
                    </plugins>
                </build>
            </profile>
        </profiles>
    
        <dependencies>
            <dependency>
                <groupId>org.eclipse.milo</groupId>
                <artifactId>sdk-client</artifactId>
                <version>0.2.0-SNAPSHOT</version>
            </dependency>
    
            <!-- Redeclare our dependency on Bouncy Castle
            because we use SelfSignedCertificateBuilder -->
            <dependency>
                <groupId>org.bouncycastle</groupId>
                <artifactId>bcprov-jdk15on</artifactId>
                <version>1.58</version>
            </dependency>
            <dependency>
                <groupId>org.bouncycastle</groupId>
                <artifactId>bcpkix-jdk15on</artifactId>
                <version>1.58</version>
            </dependency>
    
            <dependency>
                <groupId>org.eclipse.milo</groupId>
                <artifactId>server-examples</artifactId>
                <version>0.2.0-SNAPSHOT</version>
            </dependency>
            <dependency>
                <groupId>ch.qos.logback</groupId>
                <artifactId>logback-classic</artifactId>
                <version>1.1.7</version>
            </dependency>
        </dependencies>
    </project>