Skip to content

Instantly share code, notes, and snippets.

@HybridEidolon
Created May 4, 2016 18:43
Show Gist options
  • Save HybridEidolon/6e108df0338557e3011fd05537b8ca13 to your computer and use it in GitHub Desktop.
Save HybridEidolon/6e108df0338557e3011fd05537b8ca13 to your computer and use it in GitHub Desktop.
Maven/Gradle bukkit examples

Using Maven

  1. Create a pom.xml in your project root (base it on the one below if you so feel)
  2. Move your Java sources to src/main/java
  3. Move your plugin.yml/whatever to src/main/resources
  4. Use with Eclipse
  5. Use with IntelliJ IDEA
  6. You can export a jar with the mvn package command. You'll need command line maven installed. Goes into target somewhere... I don't use Maven personally.

Using Gradle

  1. Create a build.gradle in your project root (base it on the example if you want)
  2. Move your Java sources to src/main/java
  3. Move your plugin.yml/whatever to src/main/resources
  4. Delete the .idea/.iml files (the IDEA project metadata) in your project folder
  5. Reopen the project folder in IntelliJ
  6. IntelliJ will prompt you to import the gradle project, let it (On the import prompt, tell it to use an automatic gradle wrapper)
  7. No idea how to do it in Eclipse, YMMV
  8. You can generate a package jar with the command prompt/terminal, type ./gradlew jar. This goes into build/libs
apply plugin: "java"
buildscript {
ext.bukkit_version = "1.9.2-R0.1-SNAPSHOT"
}
repositories {
mavenCentral()
maven {
url "https://hub.spigotmc.org/nexus/content/repositories/snapshots/"
}
}
version = "0.1"
sourceCompatibility = "1.6"
targetCompatibility = "1.6"
configurations {
shade
compile.extendsFrom shade
}
// Use the shade configuration to include the dependency's class files in your final JAR
dependencies {
compile "org.bukkit:bukkit:$bukkit_version"
// shade "org.somewebsite:some-dependency:version"
}
jar {
configurations.shade.each { dep ->
from(project.zipTree(dep)) {
exclude 'META-INF', 'META-INF/**'
}
}
}
<!-- Taken from https://github.com/Bukkit/SamplePlugin/blob/d6c474cd324cc09489ad33e8aace76d6e4ecb9cc/pom.xml -->
<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>org.bukkit</groupId>
<artifactId>bukkit-sample-plugin</artifactId>
<version>0.5</version>
<name>BukkitSamplePlugin</name>
<url>http://www.bukkit.org</url>
<repositories>
<repository>
<id>bukkit-repo</id>
<url>http://repo.bukkit.org/content/groups/public</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>org.bukkit</groupId>
<artifactId>bukkit</artifactId>
<version>1.4.6-R0.3</version>
<type>jar</type>
<scope>compile</scope>
</dependency>
</dependencies>
<build>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.0</version>
<configuration>
<source>1.5</source>
<target>1.5</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
@SpikeVN
Copy link

SpikeVN commented Jul 15, 2021

Do I need to type gradlew jar or fully ./gradlew jar, because the second one doesn't recognize as a command

I think that is a Linux shell command

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment