Skip to content

Commit f757bc0

Browse files
authored
Merge pull request #51 from EndlessCodeGroup/feature/smarter_meta
Smarter plugin.yml generation
2 parents 5e645d7 + 640e39e commit f757bc0

20 files changed

+644
-451
lines changed

CHANGELOG.md

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,24 +37,51 @@ bukkit {
3737
```
3838
If `bukkit.server.version` is not specified, will be used `bukkit.apiVersion` for server.
3939

40+
Now, BukkitGradle adds `api-version` field to `plugin.yml`.
41+
It will be parsed from `bukkit.apiVersion` but you can override it with `bukkit.meta.apiVersion` if need:
42+
```kotlin
43+
bukkit {
44+
apiVersion = "1.16.4" // Inferred api-version is 1.16
45+
46+
meta {
47+
apiVersion.set("1.13") // But here you can override it
48+
}
49+
}
50+
```
51+
52+
### Smarter plugin.yml generation
53+
54+
BukkitGradle will not "eat" your existing plugin.yml file.
55+
Its content will be used if you've not configured `bukkit.meta` in BukkitGradle.
56+
57+
If you don't want plugin.yml generation at all, you can disable it:
58+
```kotlin
59+
bukkit {
60+
disableMetaGeneration()
61+
}
62+
```
63+
4064
### Re-written in Kotlin
4165
The plugin has been converted to Kotlin to make support easier.
4266
The plugin still can be configured with Groovy DSL but
4367
now it is friendly to Kotlin DSL.
4468

4569
### Removed
46-
- Task `:rebuildServerCore`, use `:buildServerCore --rerun-tasks` instead
47-
- Extension `DependencyHandler.craftbukkit()`, use `DependencyHandler.spigot()` instead
48-
- Automatic `mavenLocal()` apply, you should apply it manually if you need it
70+
- Removed task `:rebuildServerCore`, use `:buildServerCore --rerun-tasks` instead
71+
- Removed extension `DependencyHandler.craftbukkit()`, use `DependencyHandler.spigot()` instead
72+
- Removed automatic `mavenLocal()` apply, you should apply it manually if you need it
73+
- Removed repository extension `RepositoryHandler.vault()`, use `RepositoryHandler.jitpack()` instead and read [VaultAPI README][vault]
4974

5075
### Changed
5176
- Add `nogui` argument by default to `bukkitArgs`
5277
- Type of properties `server.jvmArgs` and `server.bukkitArgs` changed from `String` to `List<String>`.
5378
It makes it easier to add arguments without overriding defaults
79+
- Default main class pattern changed from `<groupId>.<lowercased name>.<name>` to `<groupId>.<name>`
5480

5581
### Housekeeping
5682
- Default bukkit version now is 1.16.4
5783
- Update Gradle to 6.7.1
5884

5985
[tca]: https://docs.gradle.org/current/userguide/task_configuration_avoidance.html
6086
[uptodate]: https://docs.gradle.org/current/userguide/more_about_tasks.html#sec:up_to_date_checks
87+
[vault]: https://github.com/MilkBowl/VaultAPI

README.md

Lines changed: 30 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ Gradle utilities for easier writing Bukkit plugins.
3232

3333
## Apply plugin
3434
[BukkitGradle on plugins.gradle.org](https://plugins.gradle.org/plugin/ru.endlesscode.bukkitgradle)
35-
> **NOTE:** Gradle 5.0+ required
35+
> **Note:** Gradle 6.6+ required
3636
3737
#### With new plugins mechanism
3838
```groovy
@@ -66,7 +66,7 @@ plugins {
6666
}
6767
6868
// Project information
69-
group = "com.example"
69+
group = "com.example.myplugin"
7070
description = "My first Bukkit plugin with Gradle"
7171
version = "0.1"
7272
@@ -76,23 +76,27 @@ dependencies {
7676
// see section 'Dependencies' for more info
7777
}
7878
```
79-
`compileOnly` - it's like provided scope in Maven. It means that this dependncy will not included to your final jar.
80-
It's enough! Will be hooked latest version of Bukkit and automatically generated `plugin.yml` with next content:
79+
> **Note:** `compileOnly` - it's like `provided` scope in Maven.
80+
It means that this dependency will not be included to your final jar.
81+
82+
It's enough!
83+
Will be hooked the latest version of Bukkit and automatically generated `plugin.yml` with next content:
8184
```yaml
8285
name: MyPlugin
8386
description: My first Bukkit plugin with Gradle
8487
main: com.example.myplugin.MyPlugin
8588
version: 0.1
89+
api-version: 1.16
8690
```
87-
Main class build by pattern: `<groupId>.<lower case name>.<name>`
91+
> **Note:** Main class built by following pattern: `<groupId>.<name>`
8892

8993
### Configuring plugin
9094
You can configure attributes that will be placed to `plugin.yml`:
9195
```groovy
9296
// Override default configurations
9397
bukkit {
94-
// Version of API (if you will not set this property, will be used latest available)
95-
version = "1.12.2"
98+
// Version of API (if you will not set this property, will be used latest version at moment of BukkitGradle release)
99+
apiVersion = "1.15.2"
96100
97101
// Attributes for plugin.yml
98102
meta {
@@ -106,39 +110,19 @@ bukkit {
106110
}
107111
```
108112

109-
Will be generated next `plugin.yml` file:
113+
Will be generated `plugin.yml` file:
110114
```yaml
111115
name: MyPlugin
112116
description: My amazing plugin, that doing nothing
113117
main: com.example.plugin.MyPlugin
114118
version: 1.0
119+
api-version: 1.15
115120
website: http://www.example.com
116121
authors: [OsipXD, Contributors]
117122
```
118123

119-
Also you can add custom (unsupported by BukkitGradle) attributes like a `depend` etc.
120-
Just create `plugin.yml` file and put custom attributes into.
121-
122-
#### Quotes around values
123-
In some cases you may need put meta value in quotes. For this you can use `q` and `qq` functions.
124-
125-
For example, we have meta:
126-
```groovy
127-
meta {
128-
name.set(qq("Double Quoted Name"))
129-
description.set(q("Single quoted description"))
130-
url.set("http://without.quot.es/")
131-
}
132-
```
133-
134-
And will be generated:
135-
```yaml
136-
name: "Double Quoted Name"
137-
description: 'Single quoted description'
138-
website: http://without.quot.es/
139-
```
140-
141-
**Note:** In Groovy you can use functions in two ways: normal - `q("value")` and without braces - `q "value"`
124+
If you want to add unsupported by BukkitGradle attributes, like a `depend`, `commands` etc.
125+
Create `plugin.yml` file and put custom attributes there.
142126

143127
### Repositories and Dependencies
144128
BukkitGradle provides short extension-functions to add common repositories and dependencies.
@@ -158,13 +142,13 @@ dependencies {
158142
##### Repositories:
159143
Name | Url
160144
----------------|-------------------------------------------------------------------
161-
spigot | https://hub.spigotmc.org/nexus/content/repositories/snapshots/
162-
sk98q | http://maven.sk89q.com/repo/
163-
destroystokyo | https://repo.destroystokyo.com/repository/maven-public/
164-
dmulloy2 | http://repo.dmulloy2.net/nexus/repository/public/
165-
md5 | http://repo.md-5.net/content/groups/public/
166-
vault | http://nexus.hc.to/content/repositories/pub_releases/
167-
placeholderapi | http://repo.extendedclip.com/content/repositories/placeholderapi/
145+
spigot | https://hub.spigotmc.org/nexus/content/repositories/snapshots/
146+
sk98q | https://maven.sk89q.com/repo/
147+
papermc | https://papermc.io/repo/repository/maven-public/
148+
dmulloy2 | https://repo.dmulloy2.net/nexus/repository/public/
149+
md5 | https://repo.md-5.net/content/groups/public/
150+
jitpack | https://jitpack.io/
151+
placeholderapi | https://repo.extendedclip.com/content/repositories/placeholderapi/
168152
aikar | https://repo.aikar.co/content/groups/aikar/
169153

170154
##### Dependencies:
@@ -198,17 +182,19 @@ buildtools.dir=/path/to/buildtools/
198182
```
199183
If there no BuildTools.jar it will be automatically downloaded.
200184

201-
**TIP:** you can define it globally (for all projects that uses BukkitGradle) with environment variables `BUKKIT_DEV_SERVER_HOME`
185+
> **Tip:** you can define it globally, for all projects that uses BukkitGradle.
186+
> Specify environment variables `BUKKIT_DEV_SERVER_HOME`
202187
and `BUKKIT_BUILDTOOLS_HOME`.
203188

204189
##### On IntelliJ IDEA
205-
Run `:buildIdeaRun` task. To your IDE will be added Run Configuration that will dynamically refreshes when you change
206-
server configurations.
190+
Run `:buildIdeaRun` task.
191+
Run Configuration will be added to your IDE.
192+
It will be automatically refreshed when you change server configurations.
207193

208194
![Run Configuration](http://image.prntscr.com/image/1a12a03b8ac54fccb7d5b70a335fa996.png)
209195

210196
##### On other IDEs
211-
Run `:startServer` task.
197+
Run `:runServer` task.
212198

213199
#### Dev server configuration
214200
To accept EULA and change settings use `bukkit.server` section:
@@ -218,6 +204,8 @@ bukkit {
218204
server {
219205
// Core type. It can be 'spigot' or 'paper'
220206
core = "spigot"
207+
// Server version
208+
version = "1.16.4" // If not specified, apiVersion will be used
221209
// Accept EULA
222210
eula = false
223211
// Set online-mode flag

build.gradle.kts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ plugins {
33
`maven-publish`
44
groovy
55
kotlin("jvm") version "1.4.21"
6+
kotlin("plugin.serialization") version "1.4.21"
67
id("com.gradle.plugin-publish") version "0.12.0"
78
id("com.github.ben-manes.versions") version "0.36.0"
89
}
@@ -27,6 +28,8 @@ repositories {
2728

2829
dependencies {
2930
implementation("de.undercouch:gradle-download-task:4.1.1")
31+
implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.0.1")
32+
implementation("com.charleskorn.kaml:kaml:0.26.0")
3033
testImplementation("junit:junit:4.13")
3134
testImplementation(platform("org.spockframework:spock-bom:2.0-M2-groovy-2.5"))
3235
testImplementation("org.spockframework:spock-core")

src/main/kotlin/Bukkit.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,7 @@ public interface Bukkit {
1313

1414
/** Bukkit version. */
1515
public val apiVersion: String
16+
17+
/** Plugin Meta generation enabled. */
18+
public val generateMeta: Boolean
1619
}

src/main/kotlin/BukkitExtension.kt

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,14 @@ import ru.endlesscode.bukkitgradle.server.extension.ServerConfigurationImpl
1212

1313
// TODO 1.0: Remove deprecated fields on release
1414
public open class BukkitExtension(
15-
public override val meta: PluginMetaImpl,
16-
public override val server: ServerConfigurationImpl
15+
public final override val meta: PluginMetaImpl,
16+
public final override val server: ServerConfigurationImpl
1717
) : Bukkit {
1818

19-
public override var apiVersion: String = ServerConstants.DEFAULT_VERSION
19+
public final override var apiVersion: String = ServerConstants.DEFAULT_VERSION
20+
21+
public final override var generateMeta: Boolean = true
22+
private set
2023

2124
private val logger = LoggerFactory.getLogger("BukkitExtension")
2225

@@ -54,6 +57,11 @@ public open class BukkitExtension(
5457
logger.warnSyntaxChanged("bukkit.version = '...'", "bukkit.apiVersion = '...'")
5558
apiVersion = version
5659
}
60+
61+
/** Disabled plugin.yml generation. */
62+
public fun disableMetaGeneration() {
63+
generateMeta = false
64+
}
5765
}
5866

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

src/main/kotlin/BukkitGradlePlugin.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ public class BukkitGradlePlugin : Plugin<Project> {
4848
description.convention(provider { project.description })
4949
main.convention(name.map { "${project.group}.${StringUtils.toPascalCase(it)}" })
5050
version.convention(provider { project.version.toString() })
51+
apiVersion.convention(provider { StringUtils.parseApiVersion(bukkit.apiVersion) })
5152
url.convention(provider { findProperty("url")?.toString() })
5253
}
5354
}

src/main/kotlin/dependencies/Dependencies.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ internal object Dependencies {
2020
const val URL_PAPERMC = "https://papermc.io/repo/repository/maven-public/"
2121
const val URL_DMULLOY2 = "https://repo.dmulloy2.net/nexus/repository/public/"
2222
const val URL_MD5 = "https://repo.md-5.net/content/groups/public/"
23-
const val URL_VAULT = "http://nexus.hc.to/content/repositories/pub_releases/"
23+
const val URL_JITPACK = "https://jitpack.io"
2424
const val URL_PLACEHOLDERAPI = "https://repo.extendedclip.com/content/repositories/placeholderapi/"
2525
const val URL_AIKAR = "https://repo.aikar.co/content/groups/aikar/"
2626

@@ -46,7 +46,7 @@ internal object Dependencies {
4646
repoExtra["papermc"] = closureOf<Any?> { repoHandler.addRepo("PaperMC", URL_PAPERMC) }
4747
repoExtra["dmulloy2"] = closureOf<Any?> { repoHandler.addRepo("dmulloy2", URL_DMULLOY2) }
4848
repoExtra["md5"] = closureOf<Any?> { repoHandler.addRepo("md5", URL_MD5) }
49-
repoExtra["vault"] = closureOf<Any?> { repoHandler.addRepo("Vault", URL_VAULT) }
49+
repoExtra["jitpack"] = closureOf<Any?> { repoHandler.addRepo("jitpack", URL_JITPACK) }
5050
repoExtra["placeholderapi"] = closureOf<Any?> { repoHandler.addRepo("PlaceholderAPI", URL_PLACEHOLDERAPI) }
5151
repoExtra["aikar"] = closureOf<Any?> { repoHandler.addRepo("aikar", URL_AIKAR) }
5252

src/main/kotlin/dependencies/DependenciesExtensions.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@ import org.gradle.api.artifacts.dsl.RepositoryHandler
55
import org.gradle.api.artifacts.repositories.MavenArtifactRepository
66
import ru.endlesscode.bukkitgradle.dependencies.Dependencies.URL_AIKAR
77
import ru.endlesscode.bukkitgradle.dependencies.Dependencies.URL_DMULLOY2
8+
import ru.endlesscode.bukkitgradle.dependencies.Dependencies.URL_JITPACK
89
import ru.endlesscode.bukkitgradle.dependencies.Dependencies.URL_MD5
910
import ru.endlesscode.bukkitgradle.dependencies.Dependencies.URL_PAPERMC
1011
import ru.endlesscode.bukkitgradle.dependencies.Dependencies.URL_PLACEHOLDERAPI
1112
import ru.endlesscode.bukkitgradle.dependencies.Dependencies.URL_SK89Q
1213
import ru.endlesscode.bukkitgradle.dependencies.Dependencies.URL_SPIGOT
13-
import ru.endlesscode.bukkitgradle.dependencies.Dependencies.URL_VAULT
1414
import ru.endlesscode.bukkitgradle.dependencies.Dependencies.addRepo
1515
import ru.endlesscode.bukkitgradle.dependencies.Dependencies.api
1616

@@ -34,8 +34,8 @@ public fun RepositoryHandler.md5(configure: MavenArtifactRepository.() -> Unit =
3434
addRepo("md5", URL_MD5, configure)
3535
}
3636

37-
public fun RepositoryHandler.vault(configure: MavenArtifactRepository.() -> Unit = {}) {
38-
addRepo("Vault", URL_VAULT, configure)
37+
public fun RepositoryHandler.jitpack(configure: MavenArtifactRepository.() -> Unit = {}) {
38+
addRepo("jitpack", URL_JITPACK, configure)
3939
}
4040

4141
public fun RepositoryHandler.placeholderApi(configure: MavenArtifactRepository.() -> Unit = {}) {

0 commit comments

Comments
 (0)