javamavenjarjar-with-dependencies

Maven build appears to be overwriting classes when creating jar-with-dependencies


I'm using maven to build a jar-with-dependencies jar. One of the vendor jar files in the project has similarly named classes with different case. For example aM.class and am.class.

When the build creates the "jar-with-dependencies" jar file, only aM.class is present. am.class appears to have been overwritten or skipped. The same thing happens for every similarly named classes files.

We have a couple work-arounds, but I'm curious why the maven build is behaving this way. Thanks

My pom:

        <plugin>
            <artifactId>maven-assembly-plugin</artifactId>
            <version>2.1</version>
            <configuration>
                <archive>
                    <manifest>
                        <mainClass>com.mytest.MyTest</mainClass>
                    </manifest>
                </archive>
                <descriptorRefs>
                    <descriptorRef>jar-with-dependencies</descriptorRef>
                </descriptorRefs>
            </configuration>
            <executions>
                <execution>
                    <id>make-assembly</id>
                    <phase>package</phase>
                    <goals>
                        <goal>single</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>

<dependencies>
        <dependency>
            <groupId>com.bloomberglp</groupId>
            <artifactId>blpapi3</artifactId>
            <version>3.10.1</version>
        </dependency>   
</dependencies>

Solution

  • Same class conflict issue will happen with maven-assembly-plugin, this plugin extracts all dependency jars into raw classes, and group it together.It works in project with less dependencies only, for large project with many dependencies, it will cause Java class name conflict issue, check here.

    Better way to use maven-shade-plugin if you have many jars with potentially could conflict. You can also you relocating feature in shade plugin to explicitly avoid conflicts