Solved How to add ProtocolLib as a dependency?

Discussion in 'Spigot Plugin Development' started by CorruptedCookies, May 25, 2020.

  1. Now I've added it into the plugin.yml like this
    Code (Text):

    name: testProtocol
    version: ${project.version}
    main: me.hishe.testProtocol
    api-version: 1.13
    authors: [Hishe]
    description: Test
    depend: [ProtocolLib]
     
    And have added it to the build path, but I'm really confused about what to do with this?

    Code (Text):

    <repositories>
      <repository>
       <id>dmulloy2-repo</id>
       <url>https://repo.dmulloy2.net/nexus/repository/public/</url>
      </repository>
      ...
    </repositories>

    <dependencies>
      <dependency>
       <groupId>com.comphenix.protocol</groupId>
       <artifactId>ProtocolLib</artifactId>
       <version>4.5.0</version>
      </dependency>
    </dependencies>
     
    I can't figure what to do with it, and without it I will get this error(in intellij) when I write something in the code that uses ProtocolLib.
    Code (Text):

    package com.comphenix.protocol does not exist
     
    Any help is appreciated :)
     
  2. The dependency in the plugin.yml is only for the server to know that your plugin requires ProtocolLib and if ProtocolLib does not exist it doesn’t load the plugin.
    But to use ProtocolLib in your code you have to do more. You can either add ProtocolLib as jar as local library or add it as repository and dependency to your pom.xml (if you are using maven). That’s what the code snippets you showed are for.
    Are you using maven?
     
    #2 MightyOne, May 25, 2020
    Last edited: May 25, 2020
  3. Yes, I am using maven, also protocol is in the plugins folder

    Can you also explain how to add it as a repository to the pom? (As stated at the end of your reply)

    I'm not sure how to add it as a repository can you please explain how?
     
    #3 CorruptedCookies, May 25, 2020
    Last edited: May 25, 2020
  4. If you also use maven to add a spigot version to your code then this should not be a big mystery.

    Well the snippet showed it already. I think you should have these two sections in your pom (for me they get auto generated)
    Code (Text):
    <repositories>
    ...
    </repositories>

    <dependencies>
    ...
    </dependencies>
    And between these tags or how you call them you have to insert the repository and the dependency part of ProtocolLib. In the end it should look like the snippet of pom you posted.

    Additionally I would add
    Code (Text):
    <scope>provided</scope>
    to the <dependency> part because ProtocolLib will be provided by the server for your plugin.
     
  5. It can't find the dependency?

    Code (Text):

    Dependency 'com.comphenix.protocol:ProtocolLib:4.5.0' not found
     
    Nevermind that problem was fixed now it can't find bukkit???


    Code (Text):

    package org.bukkit does not exist
     
     
    #5 CorruptedCookies, May 25, 2020
    Last edited: May 25, 2020
  6. How does your pom.xml looks now?
     
  7. Code (Text):

    <?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>me.hishe.anticheat</groupId>
        <artifactId>Angel</artifactId>
        <version>1.0-SNAPSHOT</version>
        <packaging>jar</packaging>

        <name>Angel</name>

        <description>This is my first anticheat :D</description>
        <properties>
            <java.version>1.8</java.version>
            <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        </properties>

        <build>
            <defaultGoal>clean package</defaultGoal>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <version>3.7.0</version>
                    <configuration>
                        <source>${java.version}</source>
                        <target>${java.version}</target>
                    </configuration>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-shade-plugin</artifactId>
                    <version>3.1.0</version>
                    <executions>
                        <execution>
                            <phase>package</phase>
                            <goals>
                                <goal>shade</goal>
                            </goals>
                            <configuration>
                                <createDependencyReducedPom>false</createDependencyReducedPom>
                            </configuration>
                        </execution>
                    </executions>
                </plugin>
            </plugins>
            <resources>
                <resource>
                    <directory>src/main/resources</directory>
                    <filtering>true</filtering>
                </resource>
            </resources>
        </build>

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


            <repository>
                <id>dmulloy2-repo</id>
                <url>https://repo.dmulloy2.net/nexus/repository/public/</url>
            </repository>





        </repositories>

        <dependencies>
            <dependency>
                <groupId>com.comphenix.protocol</groupId>
                <artifactId>ProtocolLib</artifactId>
                <version>4.5.0</version>
            </dependency>
        </dependencies>



    </project>

     
     
  8. You removed the spigot dependency by accident.
     
  9. Thanks for the help I've fixed it

    Solved
     
    • Like Like x 1