Joe DiNottra
Joe DiNottra

Reputation: 1008

Maven Assembly Plugin - Multi-Release:true

My multi-jar app runs in Java 11 and shows a warning related to Log4j2:

WARNING: sun.reflect.Reflection.getCallerClass is not supported. This will impact performance.

It doesn't crash, but quite bothers me since the Operations team (AppDynamics monitor) has asked me about it. I read that I need to use the "Multi-Release:true" entry in the manifest, but I don't kow how to tell the Maven Assembly Plugin to add it.

I don't use any other plugin in the pom.xml. Should I use the Maven Shade Plugin instead?

Anyway, here's the Maven Assembly Plugin section of my pom.xml.

<plugin>
  <artifactId>maven-assembly-plugin</artifactId>
  <version>3.2.0</version>
  <configuration>
    <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>

The library I'm including (that I also wrote) uses Log4j 2 as a dependency, as shown below:

<!-- Log4j 2 -->

<dependency>
  <groupId>org.apache.logging.log4j</groupId>
  <artifactId>log4j-api</artifactId>
  <version>2.12.1</version>
</dependency>
<dependency>
  <groupId>org.apache.logging.log4j</groupId>
  <artifactId>log4j-core</artifactId>
  <version>2.12.1</version>
</dependency>

How can I get rid of this warning?

Upvotes: 6

Views: 7925

Answers (2)

acm
acm

Reputation: 2120

You can use maven-assembly-plugin for this as follows:

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-assembly-plugin</artifactId>
  <executions>
    <execution>
      ...
      <configuration>
        <archive>
          ...
          <manifestEntries>
            <Multi-Release>true</Multi-Release>
          </manifestEntries>
        </archive>
        ...
      </configuration>
    </execution>
  </executions>
</plugin>

Upvotes: 2

rgoers
rgoers

Reputation: 9141

You need to set Multi-Release to true in the jar's MANIFEST.MF. In the assembly plugin you should be able to do that by adding

      <archive>
        <manifestEntries>
          <Multi-Release>true</Multi-Release>
        </manifestEntries>
      </archive>

to the configuration section of your assembly configuration.

You could also use the jar plugin to create your jar. For that you would do

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-jar-plugin</artifactId>
  <configuration>
    <archive>
        <manifestEntries>
            <Multi-Release>true</Multi-Release>
        </manifestEntries>
    </archive>
    <finalName>mr-jar-demo.jar</finalName>
  </configuration>
</plugin>

Upvotes: 14

Related Questions