Skip to content

Revise unobvious defaults #68

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Apr 18, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 29 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,22 @@
### Added

- Support setting "api-version" containing a patch version for v1.20.5+
- Add dependency substitution rules fixing paper groupId and substituting bukkit version.
In version catalogs placeholder value `{bukkit.version}` can be used, and it will be replaced with the actual version:
```toml
[libraries]
paperApi = { module = "io.papermc.paper:paper-api", version = "{bukkit.apiVersion}" }
```

### Changed

- **Breaking change!**
Refactor development server implementation to use [jpenilla/run-task](https://github.com/jpenilla/run-task/) plugin and integrate run-paper for server execution,
improving maintainability and compatibility with various server versions.
- Remove `bukkit.server.coreType` property.
Spigot is not supported anymore, PaperMC is the only supported server.
If you need to run other server cores,
please [file an issue](https://github.com/EndlessCodeGroup/BukkitGradle/issues/new).
- **Breaking change!**
Use [jpenilla/resource-factory](https://github.com/jpenilla/resource-factory) to generate `plugin.yml`.
This change comes with some renames:
Expand All @@ -17,11 +27,29 @@
- Task `:parsePluginMetaFile` -> `:parsePluginYaml`
- Task `:mergePluginMeta` has been dropped. Use `:mainResourceFactory` instead
- Package `ru.endlesscode.bukkitgradle.meta` -> `ru.endlesscode.bukkitgradle.plugin`
- Change API for disabling `plugin.yml` generation:
- - **Breaking change!** Change API for disabling `plugin.yml` generation:
```diff
-bukkit.disableMetaGeneration()
+bukkit.generatePluginYaml.set(false)
```
- **Breaking change!** Don't add repositories implicitly.
It was impossible to opt out from automatic repositories adding.
From now, repositories should be added manually. For example:
```kotlin
repositories {
mavenCentral()
papermc()
}
```
- **Breaking change!**
Don't set default `bukkit.apiVersion`.
It was implicitly set to `1.16.4` for the sake of simplicity, but in fact it was unobvious behavior.
Now, `bukkit.apiVersion` should be set explicitly:
```kotlin
bukkit {
apiVersion = "1.20.5"
}
```
- Set the default [JVM toolchain](https://docs.gradle.org/current/userguide/toolchains.html) version
instead of setting JVM target and source compatibility to 1.8.
By default, the minimal supported JVM version compatible with the specified `bukkit.server.version` is used.
Expand Down
109 changes: 66 additions & 43 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,14 @@ Gradle utilities to simplify Bukkit/Spigot plugins writing and debugging.
- [Running Dev server](#running-dev-server)
- [Dev server configuration](#dev-server-configuration)
- [Migration Guide](#migration-guide)
- [Upgrade from 0.10.x](#upgrade-from-010x)
- [Upgrade from 0.8.x](#upgrade-from-08x)
- [License](#license)

<!-- END doctoc generated TOC please keep comment here to allow auto update -->

#### Features:

- Sets up compiler encoding to UTF-8
- Sets archivesBaseName to plugin name
- Supports APIs: Bukkit, CraftBukkit, Spigot, Paper
Expand All @@ -29,17 +31,14 @@ Gradle utilities to simplify Bukkit/Spigot plugins writing and debugging.
- Allows running dev server from IDE
- Runs server using [jpenilla/run-task]

#### TODO:
- Add smart dependency system

## Installation

> [!NOTE]
> [!NOTE]
> BukkitGradle requires Gradle 8.0+ to run

```kotlin
plugins {
id("ru.endlesscode.bukkitgradle") version "0.10.1"
id("ru.endlesscode.bukkitgradle") version "0.10.1"
}
```

Expand All @@ -50,6 +49,7 @@ plugins {
<summary>Using snapshots</summary>

To use snapshots, add jitpack repository to the `settings.gradle.kts` and specify version `develop-SNAPSHOT`:

```kotlin
// settings.gradle

Expand All @@ -62,6 +62,7 @@ pluginManagement {

rootProject.name = "<your project name>"
```

```kotlin
// build.gradle

Expand All @@ -87,21 +88,26 @@ description = "My first Bukkit plugin built by Gradle"
version = "0.1"

bukkit {
apiVersion = "1.16.5"
// Target API version. Will be used both for plugin.yml and for dependencies
apiVersion = "1.21.5"
}

// Add the necessary API to the project
dependencies {
compileOnly(bukkitApi())
compileOnly(paperApi)
// See the 'Dependencies' section for more info
}

repositories {
papermc()
}
```

That's it!
During the plugin compilation `plugin.yml` will be generated with the following content:

```yaml
api-version: '1.16'
api-version: 1.21.5
name: MyPlugin
version: '0.1'
main: com.example.myplugin.MyPlugin
Expand All @@ -119,10 +125,6 @@ The `plugin.yml` content can be configured using `bukkit.plugin { ... }` block.

```kotlin
bukkit {
// Version of API. By default, 1.16.5 is used
apiVersion = "1.15.2"

// Configure plugin.yml content
plugin {
name = "MyPlugin"
description = "My amazing plugin"
Expand All @@ -140,42 +142,44 @@ BukkitGradle provides shortcuts to add common repositories and dependencies:

```kotlin
repositories {
spigot()
papermc()
}

dependencies {
compileOnly(paperApi())
compileOnly(paperApi)
}
```

#### Repositories

Name | Url
----------------|-------------------------------------------------------------------
spigot | https://hub.spigotmc.org/nexus/content/repositories/snapshots/
sk98q | https://maven.sk89q.com/repo/
papermc | https://repo.papermc.io/repository/maven-public/
dmulloy2 | https://repo.dmulloy2.net/nexus/repository/public/
md5 | https://repo.md-5.net/content/groups/public/
jitpack | https://jitpack.io/
placeholderapi | https://repo.extendedclip.com/content/repositories/placeholderapi/
aikar | https://repo.aikar.co/content/groups/aikar/
codemc | https://repo.codemc.org/repository/maven-public/
| Name | Url |
|------------------|--------------------------------------------------------------------|
| `spigot` | https://hub.spigotmc.org/nexus/content/repositories/snapshots/ |
| `sk98q` | https://maven.sk89q.com/repo/ |
| `papermc` | https://repo.papermc.io/repository/maven-public/ |
| `dmulloy2` | https://repo.dmulloy2.net/nexus/repository/public/ |
| `md5` | https://repo.md-5.net/content/groups/public/ |
| `jitpack` | https://jitpack.io/ |
| `placeholderapi` | https://repo.extendedclip.com/content/repositories/placeholderapi/ |
| `aikar` | https://repo.aikar.co/content/groups/aikar/ |
| `codemc` | https://repo.codemc.org/repository/maven-public/ |

#### Dependencies

Some dependencies also add a repository needed for them.
When adding dependencies, make sure you've added the corresponding repository.

Name | Signature | Adds repository
-------------|----------------------------------------|-----------------
spigot | org.spigotmc:spigot:$apiVersion | mavenLocal
spigotApi | org.spigotmc:spigot-api:$apiVersion | spigot
bukkitApi | org.bukkit:bukkit:$apiVersion | spigot
paperApi | io.papermc.paper:paper-api:$apiVersion | papermc

**Note:** `$apiVersion` - is `${version}-R0.1-SNAPSHOT` (where `$version` is `bukkit.version`)
| Name | Signature | Official repository |
|-------------|------------------------------------------|---------------------|
| `spigot` | `org.spigotmc:spigot:$apiVersion` | `mavenLocal()`* |
| `spigotApi` | `org.spigotmc:spigot-api:$apiVersion` | `spigot()` |
| `bukkitApi` | `org.bukkit:bukkit:$apiVersion` | `mavenLocal()`** |
| `paperApi` | `io.papermc.paper:paper-api:$apiVersion` | `papermc()` |

If you need more extension-functions, [file an issue][issue].
\* Spigot is available in `mavenLocal()` only if you've built it locally using [Spigot BuildTools][buildtools]. \
\*\* Bukkit should be built locally. However, some versions are available in `spigot()` repository. \
\*\*\* `$apiVersion` - is `${version}-R0.1-SNAPSHOT` (where `$version` is `bukkit.apiVersion`).

If you need more shortcuts, [file an issue][issue].

## Running Dev server

Expand Down Expand Up @@ -212,9 +216,9 @@ tasks.runServer {
```

> [!TIP]
> It is possible to configure server directory shared between multiple projects.
> It is possible to configure a server directory shared between multiple projects.
> Set the `bukkitgradle.server.dir` property in `$HOME/.gradle/gradle.properties`.
>
>
> This file contains local configurations to be used for all Gradle projects.
> The value specified in project's `gradle.properties` takes precedence over the global one.

Expand All @@ -227,7 +231,7 @@ bukkit {
// INFO: Default values are used here
server {
// Server version
version = "1.16.4" // If not specified, bukkit.apiVersion will be used
version = "1.21.5" // If not specified, bukkit.apiVersion will be used
// Accept EULA
eula = false
// Set online-mode flag
Expand All @@ -253,9 +257,9 @@ bukkit {
### Upgrade from 0.10.x

1. Update Gradle to 8.0 or newer (the latest version is recommended):
```shell
./gradlew wrapper --gradle-version 8.13
```
```shell
./gradlew wrapper --gradle-version 8.13
```

2. Replace deprecated and removed APIs:
```diff
Expand All @@ -268,8 +272,26 @@ bukkit {
}
}
```

3. Specify `bukkit.apiVersion` explicitly. Previously it was implicitly set to `1.16.4`:
```kotlin
bukkit {
apiVersion = "1.21.5"
}
```

4. Remove server core selection: `bukkit.server.coreType` and `bukkit.server.setCore(...)`.
Paper is the only supported server core now.

3. If you have `plugin.yml`, move it's content to `bukkit.plugin { ... }` block
5. If you have `plugin.yml`, move it's content to `bukkit.plugin { ... }` block and delete the file.

6. Explicitly add `mavenCentral()` to the repositories if you're using dependencies from it:
```kotlin
repositories {
mavenCentral()
}
```
Add repositories for Bukkit/Spigot/Paper according to the [dependency table](#dependencies).

### Upgrade from 0.8.x

Expand Down Expand Up @@ -316,12 +338,13 @@ bukkit {
```
5. Remove `q` and `qq` functions calls in `meta { ... }`
6. Check generated plugin.yml contents after build.

If there are any problems, [create an issue][issue].

## License

[MIT](LICENSE) (c) 2020 EndlessCode Group

[jpenilla/run-task]: https://github.com/jpenilla/run-task/
[buildtools]: https://www.spigotmc.org/wiki/buildtools/
[issue]: https://github.com/EndlessCodeGroup/BukkitGradle/issues/new
18 changes: 10 additions & 8 deletions src/main/kotlin/BukkitExtension.kt
Original file line number Diff line number Diff line change
@@ -1,28 +1,32 @@
package ru.endlesscode.bukkitgradle

import org.gradle.api.Action
import org.gradle.api.Project
import org.gradle.api.model.ObjectFactory
import org.gradle.api.provider.Property
import org.gradle.kotlin.dsl.getByType
import org.gradle.api.provider.ProviderFactory
import org.gradle.kotlin.dsl.property
import ru.endlesscode.bukkitgradle.extensions.finalizedOnRead
import ru.endlesscode.bukkitgradle.extensions.finalizeAndGet
import ru.endlesscode.bukkitgradle.plugin.plugin
import ru.endlesscode.bukkitgradle.server.ServerConstants
import ru.endlesscode.bukkitgradle.plugin.util.MinecraftVersion
import ru.endlesscode.bukkitgradle.server.extension.ServerConfigurationImpl
import xyz.jpenilla.resourcefactory.bukkit.BukkitPluginYaml

public open class BukkitExtension internal constructor(
public final override val server: ServerConfigurationImpl,
objects: ObjectFactory,
providers: ProviderFactory,
) : Bukkit {

override val generatePluginYaml: Property<Boolean> = objects.property<Boolean>()
.convention(true)

public final override val apiVersion: Property<String> = objects.property<String>()
.convention(ServerConstants.DEFAULT_VERSION)
.finalizedOnRead()

internal val finalApiVersion = providers.provider {
check(apiVersion.isPresent) { "Please, set 'bukkit.apiVersion' property." }
apiVersion.finalizeAndGet()
}
internal val parsedApiVersion = finalApiVersion.map(MinecraftVersion::parse)

public fun server(body: Action<ServerConfigurationImpl>) {
body.execute(server)
Expand All @@ -46,5 +50,3 @@ public open class BukkitExtension internal constructor(
public const val NAME: String = "bukkit"
}
}

internal val Project.bukkit: Bukkit get() = extensions.getByType()
Loading
Loading