Kryo库在maven shade-package阶段有“重叠类”警告

时间:2016-11-03 17:06:17

标签: maven maven-shade-plugin kryo uberjar

我正在尝试创建一个带阴影的jar文件但是阴影插件给了我警告。 我不知道如何修复它们。

这是我的pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>example.shade.group</groupId>
    <artifactId>myproj-shade-kryo</artifactId>
    <name>myproj-shade-kryo</name>
    <version>1.0.0-SNAPSHOT</version>

    <dependencies>
        <dependency>
            <groupId>com.esotericsoftware.kryo</groupId>
            <artifactId>kryo</artifactId>
            <version>2.21</version>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-enforcer-plugin</artifactId>
                <executions>
                    <execution>
                        <id>enforce</id>
                        <configuration>
                            <rules>
                                <DependencyConvergence/>
                            </rules>
                        </configuration>
                        <goals>
                            <goal>enforce</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-shade-plugin</artifactId>
                <version>2.4.2</version>
                <executions>
                    <execution>
                        <id>package</id>
                        <phase>package</phase>
                        <goals>
                            <goal>shade</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

</project>

警告是:

[INFO] --- maven-shade-plugin:2.4.2:shade (package) @ myproj-shade-kryo ---
[INFO] Including com.esotericsoftware.kryo:kryo:jar:2.21 in the shaded jar.
[INFO] Including com.esotericsoftware.reflectasm:reflectasm:jar:shaded:1.07 in the shaded jar.
[INFO] Including org.ow2.asm:asm:jar:4.0 in the shaded jar.
[INFO] Including com.esotericsoftware.minlog:minlog:jar:1.2 in the shaded jar.
[INFO] Including org.objenesis:objenesis:jar:1.2 in the shaded jar.
[WARNING] minlog-1.2.jar, kryo-2.21.jar define 2 overlapping classes: 
[WARNING]   - com.esotericsoftware.minlog.Log
[WARNING]   - com.esotericsoftware.minlog.Log$Logger
[WARNING] reflectasm-1.07-shaded.jar, kryo-2.21.jar define 23 overlapping classes: 
[WARNING]   - com.esotericsoftware.reflectasm.shaded.org.objectweb.asm.Opcodes
[WARNING]   - com.esotericsoftware.reflectasm.AccessClassLoader
[WARNING]   - com.esotericsoftware.reflectasm.shaded.org.objectweb.asm.Label
[WARNING]   - com.esotericsoftware.reflectasm.shaded.org.objectweb.asm.ClassWriter
[WARNING]   - com.esotericsoftware.reflectasm.shaded.org.objectweb.asm.AnnotationVisitor
[WARNING]   - com.esotericsoftware.reflectasm.shaded.org.objectweb.asm.Type
[WARNING]   - com.esotericsoftware.reflectasm.FieldAccess
[WARNING]   - com.esotericsoftware.reflectasm.ConstructorAccess
[WARNING]   - com.esotericsoftware.reflectasm.shaded.org.objectweb.asm.ClassVisitor
[WARNING]   - com.esotericsoftware.reflectasm.shaded.org.objectweb.asm.Edge
[WARNING]   - 13 more...
[WARNING] objenesis-1.2.jar, kryo-2.21.jar define 32 overlapping classes: 
[WARNING]   - org.objenesis.ObjenesisBase
[WARNING]   - org.objenesis.instantiator.gcj.GCJInstantiator
[WARNING]   - org.objenesis.ObjenesisHelper
[WARNING]   - org.objenesis.instantiator.jrockit.JRockitLegacyInstantiator
[WARNING]   - org.objenesis.instantiator.sun.SunReflectionFactoryInstantiator
[WARNING]   - org.objenesis.instantiator.ObjectInstantiator
[WARNING]   - org.objenesis.instantiator.gcj.GCJInstantiatorBase$DummyStream
[WARNING]   - org.objenesis.instantiator.basic.ObjectStreamClassInstantiator
[WARNING]   - org.objenesis.ObjenesisException
[WARNING]   - org.objenesis.Objenesis
[WARNING]   - 22 more...
[WARNING] maven-shade-plugin has detected that some class files are
[WARNING] present in two or more JARs. When this happens, only one
[WARNING] single version of the class is copied to the uber jar.
[WARNING] Usually this is not harmful and you can skip these warnings,
[WARNING] otherwise try to manually exclude artifacts based on
[WARNING] mvn dependency:tree -Ddetail=true and the above output.
[WARNING] See http://maven.apache.org/plugins/maven-shade-plugin/

我也尝试了mvn dependency:tree -Ddetail=true,但这并没有给我任何线索如何解决:

[INFO] ------------------------------------------------------------------------
[INFO] Building myproj-shade-kryo 1.0.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- maven-dependency-plugin:2.8:tree (default-cli) @ myproj-shade-kryo ---
[INFO] example.shade.group:myproj-shade-kryo:jar:1.0.0-SNAPSHOT
[INFO] \- com.esotericsoftware.kryo:kryo:jar:2.21:compile
[INFO]    +- com.esotericsoftware.reflectasm:reflectasm:jar:shaded:1.07:compile
[INFO]    |  \- org.ow2.asm:asm:jar:4.0:compile
[INFO]    +- com.esotericsoftware.minlog:minlog:jar:1.2:compile
[INFO]    \- org.objenesis:objenesis:jar:1.2:compile
[INFO] ------------------------------------------------------------------------

1 个答案:

答案 0 :(得分:0)

这是kryo-2.21中的问题,似乎已在kryo-2.22修复。

幕后:

kryo-2.21包中包含:

  • com
  • META-INF
  • 组织/ objenesis / *
  • minlog-1.2.jar
  • objenesis-1.2.jar
  • reflectasm-1.07-shaded.jar

objenesis-1.2.jar本身包含:

  • META-INF
  • 组织/ objenesis / *

因此,根kryo和内objenesis-1.2.jar档案都包含 org / objenesis / * 类!

reflectasm库的相同内容:它作为类直接包含在kryo/com/*和jar kryo/reflectasm-1.07-shaded.jar

这似乎已在kryo-2.22guess this minimizeJar build property makes the effect

中修复

对于其他案例,如何从多个库中排除重叠,请参阅Maven build [WARNING] we have a duplicate class

有时候(如果您确定依赖项中没有重叠的类) - 尝试清理项目:

mvn clean package