我只是想在我的 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
pom.xml
有誰知道如何解決這些問題,以便在構建后立即作業?
uj5u.com熱心網友回復:
您正在使用 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,就永遠不需要更新。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/464837.html
