maven Assembly plugin is not appending/merging META-INF/services/ spi.AutoDiscoverable

108 views Asked by At

We are using and the jar build with dependencies will have META-INF/services/org.glassfish.jersey.internal.spi.AutoDiscoverable with value "a.b.client.sdk.common.client.AutoConfigService"

Basically it should also have the value of "org.glassfish.jersey.jackson.internal.JacksonAutoDiscoverable"

Looks like there is no appending or merging of values happening for the key of org.glassfish.jersey.internal.spi.AutoDiscoverable.

How we can achieve so that it should have both values one after another?

Below is how the plugin we are using.

 <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-assembly-plugin</artifactId>
    <version>3.1.1</version>

    <executions>
      <execution>
        <id>assemble-all</id>
        <phase>package</phase>
        <goals>
          <goal>single</goal>
        </goals>
        <configuration>
          <descriptorRefs>
            <descriptorRef>jar-with-dependencies</descriptorRef>
          </descriptorRefs>
          <archive>
            <manifestEntries>
              <Multi-Release>true</Multi-Release>
            </manifestEntries>
          </archive>
        </configuration>
      </execution>
      <execution>
        <id>assemble-dist-zip</id>
        <phase>verify</phase>
        <goals>
          <goal>single</goal>
        </goals>
        <configuration>
          <appendAssemblyId>false</appendAssemblyId>
          <descriptors>
            <descriptor>src/main/assembly/app-zip-assemble.xml</descriptor>
          </descriptors>
        </configuration>
      </execution>
    </executions>
  </plugin>

How to achieve with maven plugin, so my expectation is, META-INF/services/org.glassfish.jersey.internal.spi.AutoDiscoverable to retain the values coming from different artifacts like below.

a.b.client.sdk.common.client.AutoConfigService org.glassfish.jersey.jackson.internal.JacksonAutoDiscoverable

1

There are 1 answers

0
Jordan Sheinfeld On

You could use a workaround like this:

Create a file named ${PROJECT_DIR}/AutoDiscoverable.txt with the content you wish like:

a.b.client.sdk.common.client.AutoConfigService org.glassfish.jersey.jackson.internal.JacksonAutoDiscoverable

Then run mvn package using the following section instead of the assembly-plugin in pom.xml:

This will exclude the original org.glassfish.jersey.internal.spi.AutoDiscoverable file from the package and replace it with your manually created one.

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-shade-plugin</artifactId>
            <version>3.2.4</version>
            <executions>
                <execution>
                    <phase>package</phase>
                    <goals>
                        <goal>shade</goal>
                    </goals>
                    <configuration>
                        <filters>
                            <filter>
                                <artifact>*:*</artifact>
                                <excludes>
                                    <exclude>META-INF/services/org.glassfish.jersey.internal.spi.AutoDiscoverable</exclude>
                                </excludes>
                            </filter>
                        </filters>
                        <transformers>
                            <transformer implementation="org.apache.maven.plugins.shade.resource.IncludeResourceTransformer">
                                <resource>META-INF/services/org.glassfish.jersey.internal.spi.AutoDiscoverable</resource>
                                <file>AutoDiscoverable.txt</file>
                            </transformer>
                        </transformers>

                    </configuration>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>