我只是想在我的 Spigot 插件项目中包含 JGIT。当我编译它给我一个关于重叠资源的错误并构建一个不可用的插件,除非我删除 2 个底部文件:
[WARNING] CrucialPlugin-1.0.jar, JavaEWAH-1.1.13.jar, org.eclipse.jgit-6.1.0.202203080745-r.jar, slf4j-api-1.7.30.jar define 1 overlapping resource:
[WARNING] - META-INF/MANIFEST.MF
此外,即使 Spigot 已经下载,有时它也会开始尝试从 JGIT 下载它!
[INFO] Scanning for projects...
[INFO]
[INFO] --------------------------< me:CrucialPlugin >--------------------------
[INFO] Building CrucialPlugin 1.0
[INFO] --------------------------------[ jar ]---------------------------------
Downloading from jgit-repository: https://repo.eclipse.org/content/groups/releases/org/spigotmc/spigot-api/1.18.2-R0.1-SNAPSHOT/maven-metadata.xml
有谁知道如何解决这些问题,以便在构建后立即工作?
您正在使用 maven shade 插件来复制一些依赖项的内容,并将其作为自己的包含到生成的工件中。问题是,目录 META-INF 中的文件通常特定于它们分发的原始 jar 文件,并且它们的命名非常标准,因此多个 jar 包含名为 MANIFEST.MF 的文件也就不足为奇了。
这是有关重叠资源的警告的原因 - 这本身对您的目的是无害的。但是,如果打包到 JGIT 的 META-INF 中的剩余文件存在导致问题,请排除它们。
此配置将防止从您包含在项目中的任何依赖项中复制 META-INF:
<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/**</exclude>
</excludes>
</filter>
</filters>
</configuration>
</execution>
</executions>
</plugin>
或者,如果插件规范实际上要求您包含自己的 MANIFEST.MF,您可以像这样创建一个:
<configuration>
<filters>
<filter>
<artifact>*:*</artifact>
<excludes>
<exclude>META-INF/**</exclude>
</excludes>
</filter>
</filters>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<manifestEntries>
<Title>this is a title</Title>
<Some-Field-Name>some value</Some-Field-Name>
</manifestEntries>
</transformer>
</transformers>
</configuration>
另外,关于问题的最后一部分-您的项目取决于spigot-api
带有SNAPSHOT
后缀的版本,这意味着开发人员可以随时更新此版本而无需更改编号。为了让 maven 知道是否有更新的版本,它必须遍历存储库列表并询问每个存储库是否有更新的工件。
您在存储库部分有 3 个存储库,您可能希望禁用对快照更新的检查,如下所示:
<repositories>
<repository>
<id>spigotmc-repo</id>
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
</repository>
<repository>
<id>sonatype</id>
<url>https://oss.sonatype.org/content/groups/public/</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
<repository>
<id>jgit-repository</id>
<url>https://repo.eclipse.org/content/groups/releases/</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>
但是,您不应该禁用此功能spigotmc-repo
,并期望每天检查此存储库的更新,除非您选择非快照版本,一旦发布并下载到您的 PC,就永远不需要更新。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句