Noel Schenk
Noel Schenk

Reputation: 726

Maven add WorldEdit Dependencies

How can I add this WorldEdit dependency to my Maven project? http://maven.sk89q.com/artifactory/repo/com/sk89q/worldedit/worldedit-bukkit/ I need the 6.1.1-SNAPSHOT.

Is there an algorithm to get Group ID Artifact ID and Version?

Upvotes: 0

Views: 5183

Answers (1)

Tunaki
Tunaki

Reputation: 137084

It's important you understand the task at hand. Maven downloads dependencies from remote repositories based on their unique coordinates. There are two kind of repositories:

  • release repositories that host release versions of dependencies, i.e. final versions.
  • snapshot repositories that host snapshot versions of dependencies, i.e. versions that are currently in development, and are not stable yet.

A Maven coordinate is a set (groupId, artifactId, version). It uniquely identifies every dependency (truth be told, there are actually a packaging and a possibly a classifier but it's not important here).

Your problem is to declare a dependency to the worldedit-bukkit-6.1.1-SNAPSHOT dependency. Let's see:

  • the repository here is http://maven.sk89q.com/artifactory/repo: it is the root of the URL you linked to.
  • the groupId is com.sk89q.worldedit: this is the rest of the URL, right before
  • the artifactId, which is worldedit-bukkit and
  • the version, which is 6.1.1-SNAPSHOT.

If you breakdown the URL, you get

http://maven.sk89q.com/artifactory/repo/com/sk89q/worldedit/worldedit-bukkit/6.1.1-SNAPSHOT/

that is translated into the following Maven coordinates:

{REPOSITORY_URL}/{groupId where dots are slashes}/{artifactId}/{version}/

So now, we need to tell Maven about the repository. By default, Maven looks for artifacts in what's called Maven Central, so we need to add this repository. This is done either in the POM or in the settings.xml file, by adding the following configuration:

<repositories>
  <repository>
    <id>sk89q-snapshots</id>
    <url>http://maven.sk89q.com/artifactory/repo</url>
    <releases>
      <enabled>true</enabled> <!-- releases enabled: this specific repository also hosts release versions -->
    </releases>
    <snapshots>
      <enabled>true</enabled> <!-- snapshots enabled: we declare a SNAPSHOT repository because we need to download a SNAPSHOT dependency -->
    </snapshots>
  </repository>
</repositories>

Next step is to actually declare the dependency. This is done in the POM, with the following configuration:

<dependency>
  <groupId>com.sk89q.worldedit</groupId>
  <artifactId>worldedit-bukkit</artifactId>
  <version>6.1.1-SNAPSHOT</version>
</dependency>

And that's it!

Upvotes: 4

Related Questions