Skip to content

Commit 1ad7b08

Browse files
committed
feat: Don't set default bukkit.apiVersion
1 parent b7a5836 commit 1ad7b08

File tree

5 files changed

+39
-21
lines changed

5 files changed

+39
-21
lines changed

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,15 @@
4141
papermc()
4242
}
4343
```
44+
- **Breaking change!**
45+
Don't set default `bukkit.apiVersion`.
46+
It was implicitly set to `1.16.4` for the sake of simplicity, but in fact it was unobvious behavior.
47+
Now, `bukkit.apiVersion` should be set explicitly:
48+
```kotlin
49+
bukkit {
50+
apiVersion = "1.20.5"
51+
}
52+
```
4453
- Set the default [JVM toolchain](https://docs.gradle.org/current/userguide/toolchains.html) version
4554
instead of setting JVM target and source compatibility to 1.8.
4655
By default, the minimal supported JVM version compatible with the specified `bukkit.server.version` is used.

README.md

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -88,12 +88,13 @@ description = "My first Bukkit plugin built by Gradle"
8888
version = "0.1"
8989

9090
bukkit {
91-
apiVersion = "1.16.5"
91+
// Target API version. Will be used both for plugin.yml and for dependencies
92+
apiVersion = "1.21.5"
9293
}
9394

9495
// Add the necessary API to the project
9596
dependencies {
96-
compileOnly(paperApi())
97+
compileOnly(paperApi)
9798
// See the 'Dependencies' section for more info
9899
}
99100

@@ -106,7 +107,7 @@ That's it!
106107
During the plugin compilation `plugin.yml` will be generated with the following content:
107108

108109
```yaml
109-
api-version: '1.16'
110+
api-version: 1.21.5
110111
name: MyPlugin
111112
version: '0.1'
112113
main: com.example.myplugin.MyPlugin
@@ -124,10 +125,6 @@ The `plugin.yml` content can be configured using `bukkit.plugin { ... }` block.
124125

125126
```kotlin
126127
bukkit {
127-
// Version of API. By default, 1.16.5 is used
128-
apiVersion = "1.15.2"
129-
130-
// Configure plugin.yml content
131128
plugin {
132129
name = "MyPlugin"
133130
description = "My amazing plugin"
@@ -234,7 +231,7 @@ bukkit {
234231
// INFO: Default values are used here
235232
server {
236233
// Server version
237-
version = "1.16.4" // If not specified, bukkit.apiVersion will be used
234+
version = "1.21.5" // If not specified, bukkit.apiVersion will be used
238235
// Accept EULA
239236
eula = false
240237
// Set online-mode flag
@@ -275,13 +272,20 @@ bukkit {
275272
}
276273
}
277274
```
275+
276+
3. Specify `bukkit.apiVersion` explicitly. Previously it was implicitly set to `1.16.4`:
277+
```kotlin
278+
bukkit {
279+
apiVersion = "1.21.5"
280+
}
281+
```
278282

279-
3. Remove server core selection: `bukkit.server.coreType` and `bukkit.server.setCore(...)`.
283+
4. Remove server core selection: `bukkit.server.coreType` and `bukkit.server.setCore(...)`.
280284
Paper is the only supported server core now.
281285

282-
4. If you have `plugin.yml`, move it's content to `bukkit.plugin { ... }` block and delete the file.
286+
5. If you have `plugin.yml`, move it's content to `bukkit.plugin { ... }` block and delete the file.
283287

284-
5. Explicitly add `mavenCentral()` to the repositories if you're using dependencies from it:
288+
6. Explicitly add `mavenCentral()` to the repositories if you're using dependencies from it:
285289
```kotlin
286290
repositories {
287291
mavenCentral()

src/main/kotlin/BukkitExtension.kt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import org.gradle.kotlin.dsl.property
88
import ru.endlesscode.bukkitgradle.extensions.finalizeAndGet
99
import ru.endlesscode.bukkitgradle.plugin.plugin
1010
import ru.endlesscode.bukkitgradle.plugin.util.MinecraftVersion
11-
import ru.endlesscode.bukkitgradle.server.ServerConstants
1211
import ru.endlesscode.bukkitgradle.server.extension.ServerConfigurationImpl
1312
import xyz.jpenilla.resourcefactory.bukkit.BukkitPluginYaml
1413

@@ -22,9 +21,11 @@ public open class BukkitExtension internal constructor(
2221
.convention(true)
2322

2423
public final override val apiVersion: Property<String> = objects.property<String>()
25-
.convention(ServerConstants.DEFAULT_VERSION)
2624

27-
internal val finalApiVersion = providers.provider { apiVersion.finalizeAndGet() }
25+
internal val finalApiVersion = providers.provider {
26+
check(apiVersion.isPresent) { "Please, set 'bukkit.apiVersion' property." }
27+
apiVersion.finalizeAndGet()
28+
}
2829
internal val parsedApiVersion = finalApiVersion.map(MinecraftVersion::parse)
2930

3031
public fun server(body: Action<ServerConfigurationImpl>) {

src/main/kotlin/server/Constants.kt

Lines changed: 0 additions & 5 deletions
This file was deleted.

src/test/groovy/ru/endlesscode/bukkitgradle/BukkitGradlePluginSpec.groovy

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,20 @@ class BukkitGradlePluginSpec extends PluginSpecification {
77
project.apply(plugin: BukkitGradlePlugin)
88
}
99

10+
def "when initialized - and apiVersion is not set - should show an error"() {
11+
when: "use some API requiring apiVersion to be set"
12+
project.java.toolchain.languageVersion.get()
13+
14+
then:
15+
def exception = thrown(RuntimeException)
16+
exception.cause.message == "Please, set 'bukkit.apiVersion' property."
17+
}
18+
1019
def "when initialized - should set default JVM toolchain"(String apiVersion, int jvmVersion) {
11-
when: "apiVersion is set"
20+
given: "apiVersion is set"
1221
project.bukkit.apiVersion = apiVersion
1322

14-
then: "JVM toolchain version should be"
23+
expect: "JVM toolchain version should be"
1524
project.java.toolchain.languageVersion.get().asInt() == jvmVersion
1625

1726
where:

0 commit comments

Comments
 (0)