2

我正在尝试创建一个阴影 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] ------------------------------------------------------------------------
4

1 回答 1

0

原来是个问题kryo-2.21,好像已经解决了kryo-2.22

幕后花絮:

kryo-2.21包装包含:

  • com
  • 元信息
  • 组织/目标/*
  • minlog-1.2.jar
  • objenesis-1.2.jar
  • reflectasm-1.07-shaded.jar

并且objenesis-1.2.jar本身包含:

  • 元信息
  • 组织/目标/*

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

库也一样reflectasm:它作为类直接包含在kryo/com/*jar 中kryo/reflectasm-1.07-shaded.jar

这似乎是固定的kryo-2.22猜猜这个minimizeJar构建属性会产生效果

对于其他情况,如何从多个库中排除重叠,请参阅Maven build [WARNING] 我们有一个重复的类

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

mvn clean package

于 2017-03-06T14:43:29.533 回答