Spigot Maven

Discussion in 'Wiki Discussion' started by jtaylor69, Dec 8, 2014.

  1. jtaylor69

    jtaylor69 Retired Moderator
    Retired

    Spigot Maven

    Spigot Maven Repository

    Information on what to add to your pom.xml to access the Spigot API



    Maven Repository(top)

    SpigotMC has a Maven repository which can be used by plugin developers to add Spigot API to their build system.

    The SpigotMC Maven repository provides two artifacts relevant to Spigot plugin development, the Bukkit API and the Spigot API. Developers unsure of which artifact to include should default to using the Spigot API. Most, if not all, uses for the Bukkit API artifact are covered by the Spigot API artifact. Note that this repository does not provide the implementation artifacts. Developers wishing to use internal, version-dependent code (e.g. CraftBukkit or NMS classes) must run BuildTools to install those artifacts to their local Maven repository.

    pom.xml(top)

    In order to access the Spigot API using Maven, developers need to add both of the following to the pom.xml: 1) the Spigot Maven repository and 2) the Spigot API artifact. These additions are excerpted in the following code snippet:
    Code (XML):
    <repositories>
        <!-- This adds the Spigot Maven repository to the build -->
        <repository>
            <id>spigot-repo</id>
            <url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
        </repository>
    </repositories>

    <dependencies>
        <!--This adds the Spigot API artifact to the build -->
        <dependency>
               <groupId>org.spigotmc</groupId>
               <artifactId>spigot-api</artifactId>
               <version>1.15.1-R0.1-SNAPSHOT</version>
               <scope>provided</scope>
        </dependency>

        <!--This adds the Bukkit API artifact to the build -->
        <!-- Do not include this in the pom.xml file if the Spigot API is already added -->
        <dependency>
                <groupId>org.bukkit</groupId>
                <artifactId>bukkit</artifactId>
                <version>1.15.1-R0.1-SNAPSHOT</version>
                <scope>provided</scope>
        </dependency>
    </dependencies>

    build.gradle(top)

    Accessing the Spigot API using Gradle follows much the same process as with using Maven. Developers need to add both of the following to the build.gradle: 1) the Spigot Maven repository and 2) the Spigot API artifact.

    It is possible to add the SpigotMC Maven repository to a Gradle build with the following code snippet:
    Code (Text):
    maven {
       url "https://hub.spigotmc.org/nexus/content/repositories/snapshots"
    }
    It is also possible to to use the Spigot module by adding the local maven repository with using mavenLocal().

    The Spigot API artifact can then be added to the dependencies block with the following code snippet:
    Code (Text):
    compileOnly "org.spigotmc:spigot-api:1.15.1-R0.1-SNAPSHOT"
    Put together, a full build.gradle might look something like the following:
    Code (Text):
    plugins {
        id 'java'
    }

    group 'your.group'
    version '1.0-SNAPSHOT'

    repositories {
        mavenCentral()
        maven {
            url "https://hub.spigotmc.org/nexus/content/repositories/snapshots"
        }
    }

    dependencies {
        compileOnly "org.spigotmc:spigot-api:1.15.1-R0.1-SNAPSHOT"
    }
     
    • Like Like x 2
    • Informative Informative x 1
    • Useful Useful x 1
  2. Code (Text):

    * What went wrong:
    Could not resolve all dependencies for configuration ':compile'.
    > Could not resolve org.bukkit:bukkit:1.8-R0.1-SNAPSHOT.
      Required by:
          de.albionco:Highlighter:1.0.0
       > Unable to load Maven meta-data from https://hub.spigotmc.org/nexus/content/groups/public/org/bukkit/bukkit/1.8-R0.1-SNAPSHOT/maven-metadata.xml.
          > Could not GET 'https://hub.spigotmc.org/nexus/content/groups/public/org/bukkit/bukkit/1.8-R0.1-SNAPSHOT/maven-metadata.xml'.
             > Connection to https://hub.spigotmc.org refused
     
    Hmm, any thoughts?
    Using a third party repo currently, tried switching and this happened.

    I use Gradle by the way.

    Code (Text):
    repositories {
        mavenCentral()
        maven {
            url 'https://hub.spigotmc.org/nexus/content/groups/public/'
        }
    }

    dependencies {
        compile group: 'org.bukkit', name: 'bukkit', version: '1.8-R0.1-SNAPSHOT'
        testCompile group: 'junit', name: 'junit', version: '4.10'
    }
     
    #2 smrkn, Dec 10, 2014
    Last edited: Jul 15, 2015
  3. Fully working with Gradle now.
    Thanks for the continued work.
     
  4. I get this error.. after i write down the spigot dependcency and doesnt work.

    Code (Text):
    Failure to transfer net.md-5:bungeecord-chat:jar:1.8-20150606.084332-80 from https://oss.sonatype.org/content/repositories/snapshots was cached in the local repository, resolution will not be reattempted until the update interval of sonatype-nexus-snapshots has elapsed or updates are forced. Original error: Could not transfer artifact net.md-5:bungeecord-chat:jar:1.8-20150606.084332-80 from/to sonatype-nexus-snapshots (https://oss.sonatype.org/content/repositories/snapshots): The operation was cancelled.

    org.eclipse.aether.transfer.ArtifactTransferException: Failure to transfer net.md-5:bungeecord-chat:jar:1.8-20150606.084332-80 from https://oss.sonatype.org/content/repositories/snapshots was cached in the local repository, resolution will not be reattempted until the update interval of sonatype-nexus-snapshots has elapsed or updates are forced. Original error: Could not transfer artifact net.md-5:bungeecord-chat:jar:1.8-20150606.084332-80 from/to sonatype-nexus-snapshots (https://oss.sonatype.org/content/repositories/snapshots): The operation was cancelled.
        at org.eclipse.aether.internal.impl.DefaultUpdateCheckManager.newException(DefaultUpdateCheckManager.java:238)
        at org.eclipse.aether.internal.impl.DefaultUpdateCheckManager.checkArtifact(DefaultUpdateCheckManager.java:206)
        at org.eclipse.aether.internal.impl.DefaultArtifactResolver.gatherDownloads(DefaultArtifactResolver.java:585)
        at org.eclipse.aether.internal.impl.DefaultArtifactResolver.performDownloads(DefaultArtifactResolver.java:503)
        at org.eclipse.aether.internal.impl.DefaultArtifactResolver.resolve(DefaultArtifactResolver.java:421)
        at org.eclipse.aether.internal.impl.DefaultArtifactResolver.resolveArtifacts(DefaultArtifactResolver.java:246)
        at org.eclipse.aether.internal.impl.DefaultRepositorySystem.resolveDependencies(DefaultRepositorySystem.java:367)
        at org.apache.maven.project.DefaultProjectDependenciesResolver.resolve(DefaultProjectDependenciesResolver.java:205)
        at org.apache.maven.project.DefaultProjectBuilder.resolveDependencies(DefaultProjectBuilder.java:215)
        at org.apache.maven.project.DefaultProjectBuilder.build(DefaultProjectBuilder.java:188)
        at org.apache.maven.project.DefaultProjectBuilder.build(DefaultProjectBuilder.java:119)
        at org.eclipse.m2e.core.internal.embedder.MavenImpl.readMavenProject(MavenImpl.java:636)
        at org.eclipse.m2e.core.internal.project.registry.DefaultMavenDependencyResolver.resolveProjectDependencies(DefaultMavenDependencyResolver.java:63)
        at org.eclipse.m2e.core.internal.project.registry.ProjectRegistryManager.refreshPhase2(ProjectRegistryManager.java:529)
        at org.eclipse.m2e.core.internal.project.registry.ProjectRegistryManager$3.call(ProjectRegistryManager.java:491)
        at org.eclipse.m2e.core.internal.project.registry.ProjectRegistryManager$3.call(ProjectRegistryManager.java:1)
        at org.eclipse.m2e.core.internal.embedder.MavenExecutionContext.executeBare(MavenExecutionContext.java:176)
        at org.eclipse.m2e.core.internal.embedder.MavenExecutionContext.execute(MavenExecutionContext.java:151)
        at org.eclipse.m2e.core.internal.project.registry.ProjectRegistryManager.refresh(ProjectRegistryManager.java:495)
        at org.eclipse.m2e.core.internal.project.registry.ProjectRegistryManager.refresh(ProjectRegistryManager.java:350)
        at org.eclipse.m2e.core.internal.project.registry.ProjectRegistryManager.refresh(ProjectRegistryManager.java:297)
        at org.eclipse.m2e.core.internal.builder.MavenBuilder$BuildMethod.getProjectFacade(MavenBuilder.java:154)
        at org.eclipse.m2e.core.internal.builder.MavenBuilder$BuildMethod$1.call(MavenBuilder.java:89)
        at org.eclipse.m2e.core.internal.embedder.MavenExecutionContext.executeBare(MavenExecutionContext.java:176)
        at org.eclipse.m2e.core.internal.embedder.MavenExecutionContext.execute(MavenExecutionContext.java:151)
        at org.eclipse.m2e.core.internal.embedder.MavenExecutionContext.execute(MavenExecutionContext.java:99)
        at org.eclipse.m2e.core.internal.builder.MavenBuilder$BuildMethod.execute(MavenBuilder.java:86)
        at org.eclipse.m2e.core.internal.builder.MavenBuilder.build(MavenBuilder.java:200)
        at org.eclipse.core.internal.events.BuildManager$2.run(BuildManager.java:734)
        at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
        at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:205)
        at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:245)
        at org.eclipse.core.internal.events.BuildManager$1.run(BuildManager.java:300)
        at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
        at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:303)
        at org.eclipse.core.internal.events.BuildManager.basicBuildLoop(BuildManager.java:359)
        at org.eclipse.core.internal.events.BuildManager.build(BuildManager.java:382)
        at org.eclipse.core.internal.events.AutoBuildJob.doBuild(AutoBuildJob.java:144)
        at org.eclipse.core.internal.events.AutoBuildJob.run(AutoBuildJob.java:235)
        at org.eclipse.core.internal.jobs.Worker.run(Worker.java:55)
     
     
  5. dependency org.bukkit works though.. does this mean i have to use only that and not the org.spigotmc
     
  6. Go to your local maven repository and delete the folder org/spigotmc/spigot-api
     
  7. Doesn't work for the class reference MinecraftServer
     
  8. have you added craftbukkit as a dependency?
     
  9. You can't use this repository then, you would have to use the dependencies BuildTools installs to your local repository (which happens to be spigot and craftbukkit) and these ones have the NMS code in it. If you have used BuildTools you should be able to use these dependencies without any repositories.

    This is the dependency of spigot
    Code (Text):
    <dependency>
        <groupId>org.spigotmc</groupId>
        <artifactId>spigot</artifactId>
        <version>1.10.2-R0.1-SNAPSHOT</version>
        <scope>provided</scope>
    </dependency>
     
    • Like Like x 1
  10. I copied the repository and dependency information from here into my pom.xml, but I receive the following error. I am new to Maven and to plugin development. What might I be doing wrong?

    Code (Text):
    ArtifactDescriptorException: Failed to read artifact descriptor for org.spigotmc:spigot-api:jar:1.10.2-R0.1-SNAPSHOT: ArtifactResolutionException: Failure to transfer org.spigotmc:spigot-api:pom:1.10.2-R0.1-SNAPSHOT from https://hub.spigotmc.org/nexus/content/repositories/snapshots/ was cached in the local repository, resolution will not be reattempted until the update interval of spigot-repo has elapsed or updates are forced. Original error: Could not transfer artifact org.spigotmc:spigot-api:pom:1.10.2-R0.1-SNAPSHOT from/to spigot-repo (https://hub.spigotmc.org/nexus/content/repositories/snapshots/): sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
     
  11. electronicboy

    IRC Staff

    What are you trying to build that on? Looks like your cacerts are busted
     
    • Like Like x 1
  12. Run it with the `-U` flag for one time. e.g `mvn clean install` -> `mvn clean install -U` to force updates. Also if this fails, compile Spigot from build tools and run this command again.
     
  13. Which pom.xml file is meant in the article?

    Thats how my build directory looks:
    Code (Text):
    apache-maven-3.2.5  BuildTools.log.txt  craftbukkit-1.10.2.jar  work
    BuildData           Bukkit              Spigot
    BuildTools.jar      CraftBukkit         spigot-1.10.2.jar
    And those are all the pom.xml files:
    Code (Text):
    ./Bukkit/pom.xml
    ./CraftBukkit/pom.xml
    ./CraftBukkit/dependency-reduced-pom.xml
    ./Spigot/pom.xml
    ./Spigot/Spigot-Server/pom.xml
    ./Spigot/Spigot-Server/dependency-reduced-pom.xml
    ./Spigot/Spigot-API/pom.xml
    ./Spigot/Bukkit/pom.xml
    ./Spigot/CraftBukkit/pom.xml
     
  14. electronicboy

    IRC Staff

    the pom for your project, you don't need to touch the poms' from the repos for buildtools. I would suggest reading up on how to use maven, worth noting that IntelliJ makes maven nicer, and even has a plugin that will help setup a maven project folder for bukkit plugins, as well as a few other popular systems ^^
     
  15. Craftbukkit doesn't work.
     
  16. Now it's working. I forget the Buildtools :D
     
  17. FrostedSnowman, why did you revert the formatting I set? <dependencies> and <repositories> are supposed to be on the same level in the pom... they shouldn't be indented like that.