Search code examples
mavenpom.xmlmaven-shade-plugin

How can I relocate the properties files from an EXTERNAL library using maven?


I want to shade and relocate a library into my plugin using the maven shade plugin. The classes are relocate but I am getting an error while using the plugin and, after asking on the support server, I was told that the properties files was not being relocated. How can I relocate it using maven?

These are the dependencies:

<dependencies>
    <dependency>
        <groupId>net.kyori</groupId>
        <artifactId>adventure-text-minimessage</artifactId>
        <version>4.14.0</version>
    </dependency>
    <dependency>
        <groupId>net.kyori</groupId>
        <artifactId>adventure-text-serializer-json</artifactId>
        <version>4.14.0</version>
    </dependency>
    <dependency>
        <groupId>net.kyori</groupId>
        <artifactId>adventure-text-serializer-gson</artifactId>
        <version>4.14.0</version>
    </dependency>
</dependencies>

I have tried using the maven shade plugin to relocate the library:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-shade-plugin</artifactId>
    <version>3.5.0</version>
    <executions>
        <execution>
            <phase>package</phase>
            <goals>
                <goal>shade</goal>
            </goals>
        </execution>
    </executions>
    <configuration>
        <minimizeJar>true</minimizeJar>
        <filters>
            <filter>
                <artifact>NmsTest:*</artifact>
                <includes>
                    <include>**</include>
                </includes>
            </filter>
        </filters>
        <artifactSet>
            <includes>
                <include>net.kyori:*</include>
                <include>NmsTest:*</include>
            </includes>
        </artifactSet>
        <relocations>
            <relocation>
                <pattern>net.kyori</pattern>
                <shadedPattern>nt-shaded.net.kyori</shadedPattern>
            </relocation>
        </relocations>
    </configuration>
</plugin>

The JAR is built using the "clean package" task. The error is:

Caused by: java.lang.UnsupportedOperationException: No JsonComponentSerializer implementation found

Are you missing an implementation artifact like adventure-text-serializer-gson?
Is your environment configured in a way that causes ServiceLoader to malfunction?

Solution

  • After A LOT of investigation I finally found the solution!

    I just had to add this in the relocation section:

    <includes>
        <include>**/*.properties</include>
    </includes>
    


    Turns out that solution did not fully work... Adding this transformer in the shade plugin configuration worked:

    <transformers>
        <transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer"/>
    </transformers>