Skip to content
Advertisement

Does maven shade plugin automatically downcase the package names on Windows?

I have two local artifacts: one with com.org.abc, another with COM.org.xyz. I have created a shaded jar including these 2 and all the other needed dependencies.

WHEN I CREATE A SHADED JAR ON LINUX, 2 SEPARATE FOLDERS ARE CREATED : com and COM. BUT ON WINDOWS ONLY SINGLE FOLDER IS CREATED.

When I create a shaded jar on windows, it creates a single folder: com.org with folders abc and xyz inside. No separate uppercase COM folder is created. Therefore the code dependent on uppercase COM package fails with could not initialize class error.

(I didn’t name the above 2, they were created and distributed individually by 2 separate teams and many teams have been using these jars so changing the package name is a long cycle)

Maven config:

<plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-install-plugin</artifactId>
                <version>2.5.2</version>
                <executions>
                    <execution>
                        <id>add-mylocal</id>
                        <phase>clean</phase>
                        <configuration>
                            <file>${jars.path}/mylocal.jar</file>
                            <repositoryLayout>default</repositoryLayout>
                            <groupId>com.org</groupId>
                            <artifactId>mylocal</artifactId>
                            <version>1.0</version>
                            <packaging>jar</packaging>
                            <generatePom>true</generatePom>
                            <localRepositoryPath>${local.repo.path}</localRepositoryPath> 
                        </configuration>
                        <goals>
                            <goal>install-file</goal>
                        </goals>
                    </execution>    
                </executions>
            </plugin>
            <plugin>                                
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-shade-plugin</artifactId>
                <version>3.1.0</version>
                <executions>
                    <execution>                 
                        <phase>package</phase>
                        <goals>
                            <goal>shade</goal>
                        </goals>
                        <configuration>
                            <source>1.7</source>
                            <target>1.7</target>
                            <transformers>
                                <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                                  <manifestEntries>
                                    <Build-Version>${buildversion} (${timestamp})</Build-Version>
                                  </manifestEntries>
                                </transformer>
                            </transformers>
                        </configuration>                                                                        
                    </execution>                                        
                </executions>
            </plugin>
        </plugins>

Any solution to make it work on windows?

Advertisement

Answer

I found the solution to the above problem. Although the best practice, as also suggested by Ferrybig and Mureinik in their answers, is to enforce the lowercase package name standards to the projects but since in my case this was not possible, I have followed following approach.

Issue in short:

On Windows, shade plugin was merging COM folders with com , because Windows treat them as case-insensitive so if a package com is already created, it would add contents of COM in this only rather than creating new one.

Solution:

In my shade plugin, I have created 2 uber jars – one containing uppercase COM packages and second with all the other dependencies. This solved the issue because because there was no conflict with com in the first jar as it containing only COM.

The configuration that I used was from this post.

Basically in first execution block, I included artifacts containing COM packages and excluded the same from second execution block:

Execution block 1:

<include><artifact_name_with_COM_package></include> 

Execution block 2:

<exclude><artifact_name_with_COM_package></exclude> 

NOTE: Once again, the first choice should be to enforce naming standards in packages. But if you want a quick workaround you can try this.

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement