Skip to content
121 changes: 98 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@ Gradle utilities for easier writing Bukkit plugins.
2. [Usage](#usage)
1. [First steps](#first-steps)
2. [Configuring plugin](#configuring-plugin)
3. [Running Dev server](#running-dev-server)
1. [Quotes around values](#quotes-around-values)
3. [Repositories and Dependencies](#repositories-and-dependencies)
4. [Running Dev server](#running-dev-server)
1. [Server run configurations](#server-run-configurations)

#### Features:
- Automatically applies plugins: java, idea, eclipse
- Sets up compiler encoding to UTF-8
- Adds repositories: mavenCentral, mavenLocal, spigot-repo, sk89q-repo
- Provides short extension-functions to include bukkit/craftbukkit/spigot/spigot-api
- Provides short extension-functions to add common repositories and dependencies
- Generates plugin.yml from Gradle project information
- Allows to run dev server from IDE
- Automatically copies your plugin to plugins dir on server running
Expand Down Expand Up @@ -63,10 +64,16 @@ group "com.example"
description "My first Bukkit plugin with Gradle"
version "0.1"

// Wee need to add some repos
repositories {
spigot()
// see section 'Repositories' for more info
}

// Let's add needed API to project
dependencies {
compileOnly bukkit()
// You also can use craftbukkit(), spigot() and spigotApi()
// see section 'Dependencies' for more info
}
```
`compileOnly` - it's like provided scope in Maven. It means that this dependncy will not included to your final jar.
Expand All @@ -84,7 +91,7 @@ You can configure attributes that will be placed to `plugin.yml`:
```groovy
// Override default configurations
bukkit {
// Version of API (latest by default)
// Version of API (if you will not set this property, will be used latest available)
version = "1.12.2"

// Attributes for plugin.yml
Expand Down Expand Up @@ -112,17 +119,83 @@ authors: [OsipXD, Contributors]
Also you can add custom (unsupported by BukkitGradle) attributes like a `depend` etc.
Just create `plugin.yml` file and put custom attributes into.

#### Quotes around values
In some cases you may need put meta value in quotes. For this you can use `q` and `qq` functions.

For example we have meta:
```groovy
meta {
name = qq "Double Quoted Name"
description = q "Single quoted description"
url = "http://without.quot.es/"
}
```

And will be generated:
```yaml
name: "Double Quoted Name"
description: 'Single quoted description'
website: http://without.quot.es/
```

**Note:** In Groovy you can use functions in two ways: normal - `q("value")` and without braces - `q "value"`

### Repositories and Dependencies
BukkitGradle provides short extension-functions to add common repositories and dependencies.
There are list of its.

Usage example:
```groovy
repositories {
spigot() // Adds spigot repo
}

dependencies {
compileOnly paperApi() // Adds paper-api dependency
}
```

##### Repositories:
Name | Url
----------------|----------------------------------------------------------------
spigot | https://hub.spigotmc.org/nexus/content/repositories/snapshots/
sk98q | http://maven.sk89q.com/repo/
destroystokyo | https://repo.destroystokyo.com/repository/maven-public/
dmulloy2 | http://repo.dmulloy2.net/nexus/repository/public/
md5 | http://repo.md-5.net/content/groups/public/
vault | http://nexus.hc.to/content/repositories/pub_releases/
placeholderapi | http://repo.extendedclip.com/content/repositories/placeholderapi/

##### Dependencies:
Name | Signature
-------------|-----------------------------------------------
spigot | org.spigotmc:spigot:$apiVersion
spigotApi | org.spigotmc:spigot-api:$apiVersion
bukkit | org.bukkit:bukkit:$apiVersion
craftbukkit | org.bukkit:craftbukkit:$apiVersion
paperApi | com.destroystokyo.paper:paper-api:$apiVersion

**Note:** `$apiVersion` - is `${version}-R0.1-SNAPSHOT` (where `$version` is `bukkit.version`)


### Running Dev server
Before running server you should configure BuildTools and dev server location.
Before running server you should configure dev server location.

You can define it in `local.properties` file (that was automatically created in project root on refresh):
You can define it in `local.properties` file (that was automatically created in project directory on refresh):
```properties
# Absolute path to directory that contains BuildTools.jar
buildtools.dir=/path/to/buildtools/
# Absolute path to dev server
server.dir=/path/to/buildtools/
```
Or you can define it globally (for all projects that uses BukkitGradle) with environment variables `BUKKIT_DEV_SERVER_HOME`

If you use Spigot (see `bukkit.run.core`) you also should specify BuildTools location. For Paper no additional actions
needed.
```properties
# Absolute path to directory that contains BuildTools.jar
buildtools.dir=/path/to/buildtools/
```
If there no BuildTools.jar it will be automatically downloaded.

**TIP:** you can define it globally (for all projects that uses BukkitGradle) with environment variables `BUKKIT_DEV_SERVER_HOME`
and `BUILDTOOLS_HOME`.

##### On IntelliJ IDEA
Expand All @@ -132,26 +205,28 @@ server configurations.
![Run Configuration](http://image.prntscr.com/image/1a12a03b8ac54fccb7d5b70a335fa996.png)

##### On other IDEs
Run ':startServer' task.
Run `:startServer` task.

#### Server run configurations
To accept EULA and change settings use `bukkit.run` section:
```groovy
bukkit {
// INFO: Here used default values
run {
// Accept EULA
eula = false
// Set online-mode flag
onlineMode = false
// Debug mode (listen 5005 port, if you use running from IDEA this option will be ignored)
debug = true
// Set server encoding (flag -Dfile.encoding)
encoding = "UTF-8"
// JVM arguments
javaArgs = "-Xmx1G"
// Bukkit arguments
bukkitArgs = ""
// Core type. It can be 'spigot' or 'paper'
core = "spigot"
// Accept EULA
eula = false
// Set online-mode flag
onlineMode = false
// Debug mode (listen 5005 port, if you use running from IDEA this option will be ignored)
debug = true
// Set server encoding (flag -Dfile.encoding)
encoding = "UTF-8"
// JVM arguments
javaArgs = "-Xmx1G"
// Bukkit arguments
bukkitArgs = ""
}
}
```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import org.gradle.api.Project
import org.gradle.api.plugins.JavaPluginConvention
import org.gradle.api.tasks.compile.JavaCompile
import ru.endlesscode.bukkitgradle.util.Dependencies
import ru.endlesscode.bukkitgradle.util.Repositories

class BukkitGradlePlugin implements Plugin<Project> {
final static String GROUP = 'Bukkit'
Expand Down Expand Up @@ -64,21 +65,11 @@ class BukkitGradlePlugin implements Plugin<Project> {
* Adds needed repositories
*/
void addRepositories() {
project.with {
repositories {
mavenLocal()
mavenCentral()

maven {
name = 'sk89q'
url = 'http://maven.sk89q.com/repo/'
}
Repositories.configureProject(project)

maven {
name = 'spigot'
url = 'https://hub.spigotmc.org/nexus/content/repositories/snapshots/'
}
}
project.repositories {
mavenLocal()
mavenCentral()
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package ru.endlesscode.bukkitgradle

import org.gradle.api.GradleException
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.internal.impldep.org.apache.maven.lifecycle.LifecycleExecutionException
import ru.endlesscode.bukkitgradle.server.ServerCore
import ru.endlesscode.bukkitgradle.task.PrepareServer
import ru.endlesscode.bukkitgradle.task.RunServer
Expand All @@ -26,20 +26,20 @@ class DevServerPlugin implements Plugin<Project> {
PrepareServer prepareServer = project.task(
'prepareServer',
type: PrepareServer,
dependsOn: ['build', 'buildServerCore', 'copyServerCore']
dependsOn: ['build', 'copyServerCore']
) {
group = BukkitGradlePlugin.GROUP
description = 'Prepare server ro run. Configure server and copy compiled plugin to plugins dir'
core serverCore
} as PrepareServer

Path runConfigurationsDir = project.projectDir.toPath().resolve(".idea/runConfigurations")
Path runConfigurationsDir = project.rootProject.projectDir.toPath().resolve(".idea/runConfigurations")
project.task('buildIdeaRun', dependsOn: 'prepareServer') {
group = BukkitGradlePlugin.GROUP
description = 'Configure IDEA server run configuration'
}.doLast {
if (Files.notExists(runConfigurationsDir.parent)) {
throw new LifecycleExecutionException("This task only for IntelliJ IDEA.")
throw new GradleException("This task only for IntelliJ IDEA.")
}

Files.createDirectories(runConfigurationsDir)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package ru.endlesscode.bukkitgradle.extension

import groovy.xml.MarkupBuilder
import org.gradle.api.Project
import ru.endlesscode.bukkitgradle.server.CoreType
import ru.endlesscode.bukkitgradle.server.ServerCore
import ru.endlesscode.bukkitgradle.task.PrepareServer

Expand All @@ -21,9 +22,13 @@ class RunConfiguration {
String javaArgs
String bukkitArgs

private CoreType coreType

RunConfiguration(Project project) {
this.project = project

this.coreType = CoreType.SPIGOT

this.eula = false
this.onlineMode = false
this.debug = true
Expand All @@ -33,6 +38,20 @@ class RunConfiguration {
this.bukkitArgs = ''
}

void setCore(String core) {
try {
coreType = CoreType.valueOf(core.toUpperCase())
} catch (IllegalArgumentException ignored) {
project.logger.warn("Core type '$core' not found. May be it doesn't supported by BukkitGradle yet. " +
"You may write issue on GitHub to request supporting.\n" +
"Fallback core type is '${coreType.toString().toLowerCase()}'")
}
}

def getCoreType() {
return coreType
}

/**
* Returns arguments for java
*
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package ru.endlesscode.bukkitgradle.server

enum CoreType {
SPIGOT, PAPER
}
Loading