Home > OS >  Adding the JGIT library to project causes overlapping resources
Adding the JGIT library to project causes overlapping resources

Time:04-26

I'm just simply trying to include JGIT in my Spigot plugin project. When I compile it gives me an error about overlapping resources and builds an unusable plugin unless I delete the 2 bottom files:

Manifest

[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

Also, even though Spigot is already downloaded, sometimes it also starts trying to download it from 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

Does anyone know how to fix these problems so it works right after building it?

CodePudding user response:

You are using maven shade plugin to copy contents of some of your dependencies and include it into your resulting artifact as its own. The problem is, the files from directory META-INF are generally specific to the original jar file they are distributed from, and their naming is quite standard, so its not surprising multiple jars contain file named MANIFEST.MF.

This is the cause of the warning about overlapping resources - which in itself is quite harmless for your purposes. If however existence of the remaining files packaged into META-INF of JGIT causes problems, exclude them.

This configuration will prevent copying META-INF from any dependencies you include in your project:

        <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>
                                    <exlude>META-INF/**</exlude>
                                </excludes>
                            </filter>
                        </filters>
                    </configuration>
                </execution>
            </executions>
        </plugin>

Or, in case the plugin specification in fact requires that you include your own MANIFEST.MF, you can create one like this:

                    <configuration>
                        <filters>
                            <filter>
                                <artifact>*:*</artifact>
                                <excludes>
                                    <exlude>META-INF/**</exlude>
                                </excludes>
                            </filter>
                        </filters>
                        <transformers>
                            <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                                <manifestEntries>
                                    <Title>this is title</Title>
                                    <Some-Field-Name>some value</Some-Field-Name>
                                </manifestEntries>
                            </transformer>
                        </transformers>
                    </configuration>

Also, about the last part of the question - your project depends on spigot-api in version with SNAPSHOT suffix, meaning this version may be updated any time by the developer without changing number. For maven to know if there is a newer version, it has to go through the list of repositories and ask each one if they have an updated artifact.

You have 3 repos in repositories section, and you might want to disable checks for updates of snapshots like this:

<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>

You should not disable this for spigotmc-repo though, and expect a daily check for update from this repo, unless you choose a non-snapshot version, which once released and downloaded to you PC, should never need updating.

  • Related