gpt4 book ai didi

java - Maven Shading 多模块聚合与继承

转载 作者:行者123 更新时间:2023-12-05 02:55:39 29 4
gpt4 key购买 nike

上下文

我有一个包含多个模块的 IntelliJ 项目。我正在使用 maven-shade-plugin 来压缩依赖项,同时减少 jar 大小。项目结构如下;

  • 顶级父级 (pom)(聚合 api 和 world-teleport)
    • api(继承父类)
    • world-teleport(继承父级,api)

Pom(s)

parent

   <groupId>com.jsonmack</groupId>
<artifactId>mcplugins</artifactId>
<packaging>pom</packaging>
<version>1.10-SNAPSHOT</version>

<repositories>
<repository>
<id>spigot-repo</id>
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
</repository>
</repositories>

<modules>
<module>api</module>
<module>world-teleport</module>
</modules>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
<version>3.8.1</version>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.2.2</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<minimizeJar>true</minimizeJar>
<artifactSet>
<excludes>
<exclude>junit:junit</exclude>
</excludes>
</artifactSet>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>

<dependencyManagement>
<dependencies>
<dependency>
<groupId>io.github.classgraph</groupId>
<artifactId>classgraph</artifactId>
<version>4.8.68</version>
</dependency>

<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>1.15.2-R0.1-SNAPSHOT</version>
</dependency>

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13</version>
<scope>test</scope>
</dependency>
</dependencies>
</dependencyManagement>

接口(interface)

    <parent>
<artifactId>mcplugins</artifactId>
<groupId>com.jsonmack</groupId>
<version>1.10-SNAPSHOT</version>
</parent>

<modelVersion>4.0.0</modelVersion>
<artifactId>api</artifactId>
<packaging>jar</packaging>

<dependencies>
<dependency>
<groupId>io.github.classgraph</groupId>
<artifactId>classgraph</artifactId>
</dependency>

<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
</dependency>
</dependencies>

世界传送

   <parent>
<groupId>com.jsonmack</groupId>
<artifactId>mcplugins</artifactId>
<version>1.10-SNAPSHOT</version>
</parent>

<dependencies>
<dependency>
<groupId>com.jsonmack</groupId>
<artifactId>api</artifactId>
<version>1.10-SNAPSHOT</version>
</dependency>

<dependency>
<groupId>io.github.classgraph</groupId>
<artifactId>classgraph</artifactId>
</dependency>

<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
</dependency>

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</dependency>
</dependencies>

问题

每次我执行全新的安装或打包时,都会提示我存在重复的依赖项。


错误/警告

[INFO] 
[INFO] --------------------< com.jsonmack:world_teleport >---------------------
[INFO] Building world_teleport 1.8-SNAPSHOT [7/7]
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ world_teleport ---
[INFO] Deleting /Users/Business/Documents/workspace/mcplugins/world_teleport/target
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ world_teleport ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 2 resources
[INFO]
[INFO] --- maven-compiler-plugin:3.8.1:compile (default-compile) @ world_teleport ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 19 source files to /Users/Business/Documents/workspace/mcplugins/world_teleport/target/classes
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ world_teleport ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory /Users/Business/Documents/workspace/mcplugins/world_teleport/src/test/resources
[INFO]
[INFO] --- maven-compiler-plugin:3.8.1:testCompile (default-testCompile) @ world_teleport ---
[INFO] Changes detected - recompiling the module!
[INFO]
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ world_teleport ---
[INFO]
[INFO] --- maven-jar-plugin:3.2.0:jar (default-jar) @ world_teleport ---
[INFO] Building jar: /Users/Business/Documents/workspace/mcplugins/world_teleport/target/world_teleport-1.8-SNAPSHOT.jar
[INFO]
[INFO] --- maven-shade-plugin:3.2.2:shade (default) @ world_teleport ---
[INFO] Including com.jsonmack:api:jar:1.10-SNAPSHOT in the shaded jar.
[INFO] Including io.github.classgraph:classgraph:jar:4.8.68 in the shaded jar.
[INFO] Including org.spigotmc:spigot-api:jar:1.15.2-R0.1-SNAPSHOT in the shaded jar.
[INFO] Including commons-lang:commons-lang:jar:2.6 in the shaded jar.
[INFO] Including com.google.guava:guava:jar:21.0 in the shaded jar.
[INFO] Including com.google.code.gson:gson:jar:2.8.0 in the shaded jar.
[INFO] Including net.md-5:bungeecord-chat:jar:1.15-SNAPSHOT in the shaded jar.
[INFO] Including org.yaml:snakeyaml:jar:1.25 in the shaded jar.
[INFO] Minimizing jar com.jsonmack:world_teleport:jar:1.8-SNAPSHOT
[WARNING] /Users/Business/Documents/workspace/mcplugins/world_teleport/target/classes (Is a directory)
[WARNING] api-1.10-SNAPSHOT.jar, snakeyaml-1.25.jar define 207 overlapping classes and resources:
[WARNING] - META-INF/maven/org.yaml/snakeyaml/pom.properties
[WARNING] - META-INF/maven/org.yaml/snakeyaml/pom.xml
[WARNING] - org.yaml.snakeyaml.DumperOptions
[WARNING] - org.yaml.snakeyaml.DumperOptions$FlowStyle
[WARNING] - org.yaml.snakeyaml.DumperOptions$LineBreak
[WARNING] - org.yaml.snakeyaml.DumperOptions$NonPrintableStyle
[WARNING] - org.yaml.snakeyaml.DumperOptions$ScalarStyle
[WARNING] - org.yaml.snakeyaml.DumperOptions$Version
[WARNING] - org.yaml.snakeyaml.LoaderOptions
[WARNING] - org.yaml.snakeyaml.TypeDescription
[WARNING] - 197 more...
[WARNING] api-1.10-SNAPSHOT.jar, guava-21.0.jar define 931 overlapping classes and resources:
[WARNING] - META-INF/maven/com.google.guava/guava/pom.properties
[WARNING] - META-INF/maven/com.google.guava/guava/pom.xml
[WARNING] - com.google.common.annotations.Beta
[WARNING] - com.google.common.annotations.GwtCompatible
[WARNING] - com.google.common.annotations.GwtIncompatible
[WARNING] - com.google.common.annotations.VisibleForTesting
[WARNING] - com.google.common.base.Absent
[WARNING] - com.google.common.base.AbstractIterator
[WARNING] - com.google.common.base.AbstractIterator$1
[WARNING] - com.google.common.base.AbstractIterator$State
[WARNING] - 921 more...
[WARNING] api-1.10-SNAPSHOT.jar, gson-2.8.0.jar define 161 overlapping classes and resources:
[WARNING] - META-INF/maven/com.google.code.gson/gson/pom.properties
[WARNING] - META-INF/maven/com.google.code.gson/gson/pom.xml
[WARNING] - com.google.gson.ExclusionStrategy
[WARNING] - com.google.gson.FieldAttributes
[WARNING] - com.google.gson.FieldNamingPolicy
[WARNING] - com.google.gson.FieldNamingPolicy$1
[WARNING] - com.google.gson.FieldNamingPolicy$2
[WARNING] - com.google.gson.FieldNamingPolicy$3
[WARNING] - com.google.gson.FieldNamingPolicy$4
[WARNING] - com.google.gson.FieldNamingPolicy$5
[WARNING] - 151 more...
[WARNING] api-1.10-SNAPSHOT.jar, bungeecord-chat-1.15-SNAPSHOT.jar define 17 overlapping classes and resources:
[WARNING] - META-INF/maven/net.md-5/bungeecord-chat/pom.properties
[WARNING] - META-INF/maven/net.md-5/bungeecord-chat/pom.xml
[WARNING] - mojang-translations/en_US.properties
[WARNING] - mojang-translations/en_us.json
[WARNING] - net.md_5.bungee.api.ChatColor
[WARNING] - net.md_5.bungee.api.ChatMessageType
[WARNING] - net.md_5.bungee.api.chat.BaseComponent
[WARNING] - net.md_5.bungee.api.chat.ClickEvent
[WARNING] - net.md_5.bungee.api.chat.ClickEvent$Action
[WARNING] - net.md_5.bungee.api.chat.ComponentBuilder
[WARNING] - 7 more...
[WARNING] api-1.10-SNAPSHOT.jar, commons-lang-2.6.jar define 63 overlapping classes and resources:
[WARNING] - META-INF/LICENSE.txt
[WARNING] - META-INF/NOTICE.txt
[WARNING] - META-INF/maven/commons-lang/commons-lang/pom.properties
[WARNING] - META-INF/maven/commons-lang/commons-lang/pom.xml
[WARNING] - org.apache.commons.lang.ArrayUtils
[WARNING] - org.apache.commons.lang.BooleanUtils
[WARNING] - org.apache.commons.lang.CharRange
[WARNING] - org.apache.commons.lang.CharRange$1
[WARNING] - org.apache.commons.lang.CharRange$CharacterIterator
[WARNING] - org.apache.commons.lang.CharSet
[WARNING] - 53 more...
[WARNING] api-1.10-SNAPSHOT.jar, bungeecord-chat-1.15-SNAPSHOT.jar, classgraph-4.8.68.jar, commons-lang-2.6.jar, gson-2.8.0.jar, guava-21.0.jar, snakeyaml-1.25.jar, spigot-api-1.15.2-R0.1-SNAPSHOT.jar, world_teleport-1.8-SNAPSHOT.jar define 1 overlapping resources:
[WARNING] - META-INF/MANIFEST.MF
[WARNING] api-1.10-SNAPSHOT.jar, spigot-api-1.15.2-R0.1-SNAPSHOT.jar define 710 overlapping classes and resources:
[WARNING] - META-INF/maven/org.spigotmc/spigot-api/pom.properties
[WARNING] - META-INF/maven/org.spigotmc/spigot-api/pom.xml
[WARNING] - org.bukkit.Art
[WARNING] - org.bukkit.Axis
[WARNING] - org.bukkit.BanEntry
[WARNING] - org.bukkit.BanList
[WARNING] - org.bukkit.BanList$Type
[WARNING] - org.bukkit.BlockChangeDelegate
[WARNING] - org.bukkit.Bukkit
[WARNING] - org.bukkit.ChatColor
[WARNING] - 700 more...
[WARNING] api-1.10-SNAPSHOT.jar, classgraph-4.8.68.jar define 228 overlapping classes and resources:
[WARNING] - LICENSE-ClassGraph.txt
[WARNING] - META-INF.versions.9.module-info
[WARNING] - META-INF/maven/io.github.classgraph/classgraph/pom.properties
[WARNING] - META-INF/maven/io.github.classgraph/classgraph/pom.xml
[WARNING] - io.github.classgraph.AnnotationClassRef
[WARNING] - io.github.classgraph.AnnotationEnumValue
[WARNING] - io.github.classgraph.AnnotationInfo
[WARNING] - io.github.classgraph.AnnotationInfo$AnnotationInvocationHandler
[WARNING] - io.github.classgraph.AnnotationInfoList
[WARNING] - io.github.classgraph.AnnotationInfoList$AnnotationInfoFilter
[WARNING] - 218 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/
[INFO] Minimized 6106 -> 4706 (77%)

问题

是什么导致了这个警告?如果我的 maven pom 结构有问题怎么办?


重复问题

如果这是一个重复的问题,请随时提供任何资源,我们将不胜感激。

最佳答案

我认为问题在于您在 api 和 module-1 中添加了 io.github.classgraphorg.spigotmc 依赖项。

那么会发生什么:

  1. api 模块将生成 jar Artifact io.github.classgraph和其中包含的 org.spigotmc 依赖项。
  2. 依赖于 api 模块的 module-1 模块将导入jar 文件。
  3. 现在 module-1 模块有 io.github.classgraphorg.spigotmc 依赖从 jar 中,它们在 module-1 模块的pom.xml 文件。

因此解决方案是从您的 module-1 模块 pom.xml 中删除 io.github.classgraphorg.spigotmc 依赖项:

<parent>
<groupId>com.jsonmack</groupId>
<artifactId>mcplugins</artifactId>
<version>1.10-SNAPSHOT</version>
</parent>

<dependencies>
<dependency>
<groupId>com.jsonmack</groupId>
<artifactId>api</artifactId>
<version>1.10-SNAPSHOT</version>
</dependency>

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</dependency>
</dependencies>

关于java - Maven Shading 多模块聚合与继承,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61132600/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com