Skip to content

Commit 2e82b62

Browse files
committed
feat: use project name, version, and description if not specified
1 parent 54a1988 commit 2e82b62

File tree

7 files changed

+43
-25
lines changed

7 files changed

+43
-25
lines changed

README.md

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,31 +5,40 @@ A Gradle plugin designed to boost Allay plugin development!
55
## Usage
66

77
```kt
8+
9+
group = "org.allaymc.gradle.sample"
10+
version = "0.1.0"
11+
description = "Test plugin for AllayGradle!"
12+
813
allay {
9-
// API dependency version (required if `apiOnly = true`).
14+
// API version (required if `apiOnly = true`).
1015
api = "0.15.0"
1116

12-
// Specify server version for `runServer` and dependency version when `apiOnly = false`.
13-
// Set to null for the latest version.
14-
server = null
15-
16-
// Depend on the server module instead of the API module for server-specific features.
17+
// Set this field to `false` to access the server module to use the internal APIs. However, this is not
18+
// recommended as internal APIs can change at any time.
19+
// The default value is `true`.
1720
apiOnly = true
1821

19-
// Configure the plugin descriptor.
22+
// Specify the server version used in the `runServer` task. This will also be the dependency version if
23+
// `apiOnly` is set to `false`. If this field is set to `null`, the latest server version will be used.
24+
// The default value is `null`.
25+
server = null
26+
27+
// Configure the plugin descriptor (plugin.json).
2028
plugin {
2129
entrance = "org.allaymc.gradle.sample.TestPlugin"
22-
// Or use relative path if project's group is set.
30+
// Or use the relative path if the project's group is set.
2331
// entrance = ".TestPlugin"
2432

25-
name = "TestPlugin"
26-
version = "0.1.0-alpha"
33+
apiVersion = ">=0.15.0"
2734
authors += "Cdm2883"
28-
api = ">= 0.15.0"
29-
description = "Test plugin for AllayGradle!"
3035
website = "https://github.com/AllayMC/AllayGradle"
36+
37+
// By default, the following fields are set to the project's group, version, and description.
38+
// However, you can override them if you want.
39+
// name = "..."
40+
// version = "..."
41+
// description = "..."
3142
}
3243
}
3344
```
34-
35-
> See a full example in [sample/build.gradle.kts](sample/build.gradle.kts).

gradle/libs.versions.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[versions]
2-
allay-gradle = "0.1.0-alpha"
2+
allay-gradle = "0.1.0-SNAPSHOT"
33

44
kotlin = "1.9.23"
55
kotlinx-serialization = "1.5.0"

plugin/src/main/kotlin/org/allaymc/gradle/plugin/AllayExtension.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ abstract class AllayExtension @Inject constructor(objects: ObjectFactory) {
3838
val version: Property<String> = objects.property(String::class.java)
3939
val authors: ListProperty<String> = objects.listProperty(String::class.java).convention(emptyList())
4040
fun authors(vararg names: String) = authors.addAll(names.toList())
41-
val api: Property<String> = objects.property(String::class.java)
41+
val apiVersion: Property<String> = objects.property(String::class.java)
4242
val description: Property<String> = objects.property(String::class.java)
4343
val dependencies: ListProperty<PluginDescriptor.Dependency> =
4444
objects.listProperty(PluginDescriptor.Dependency::class.java).convention(emptyList())

plugin/src/main/kotlin/org/allaymc/gradle/plugin/AllayPlugin.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ class AllayPlugin : Plugin<Project> {
5353

5454
private fun createShadowJarImplement(project: Project) = project.tasks.register("shadowJar", Jar::class.java) {
5555
group = Constant.TASK_GROUP
56-
archiveClassifier.set("shadow")
56+
archiveClassifier.set("shaded")
5757
val sourceSets = project.extensions.getByType(SourceSetContainer::class.java)
5858
from(sourceSets.getByName("main").output)
5959
val runtimeClasspath = project.configurations.getByName("runtimeClasspath")

plugin/src/main/kotlin/org/allaymc/gradle/plugin/descriptor/DescriptorInjector.kt

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,11 @@ fun descriptorInject(project: Project, extension: AllayExtension) =
5353

5454
private fun PluginDescriptor.inject(project: Project, extension: AllayExtension.Plugin) = copy(
5555
entrance = (entrance ?: extension.entrance.orNull).ensureEntrance(project),
56-
name = name.template(extension.name),
56+
name = name.ensureName(project, extension.name),
5757
version = version.ensureVersion(project, extension.version),
5858
authors = authors + extension.authors,
59-
api = api.template(extension.api),
60-
description = description.template(extension.description),
59+
apiVersion = apiVersion.template(extension.apiVersion),
60+
description = description.ensureDescription(project, extension.description),
6161
dependencies = dependencies + extension.dependencies,
6262
website = website.template(extension.website),
6363
)
@@ -67,6 +67,12 @@ private fun String?.ensureEntrance(project: Project) = this
6767
?.let { if (it.startsWith(".")) "${project.group}$it" else it }
6868
?: error("Entrance is not defined!")
6969

70+
private fun String?.ensureName(project: Project, property: Property<String>) =
71+
template(property) ?: project.name.takeUnless { it == "unspecified" } ?: error("Name is not defined!")
72+
73+
private fun String?.ensureDescription(project: Project, property: Property<String>) =
74+
template(property) ?: project.description ?: ""
75+
7076
private val SemVerRegex =
7177
Regex("^(0|[1-9]\\d*)\\.(0|[1-9]\\d*)\\.(0|[1-9]\\d*)(?:-((?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\\.(?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\\+([0-9a-zA-Z-]+(?:\\.[0-9a-zA-Z-]+)*))?\$")
7278

plugin/src/main/kotlin/org/allaymc/gradle/plugin/descriptor/PluginDescriptor.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ data class PluginDescriptor(
1010
val version: String?,
1111
val authors: List<String>?,
1212
@SerialName("api_version")
13-
val api: String?,
13+
val apiVersion: String?,
1414
val description: String?,
1515
val dependencies: List<Dependency>?,
1616
val website: String?,

sample/build.gradle.kts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,19 @@ plugins {
33
alias(libs.plugins.allay.gradle)
44
}
55

6-
group = "org.allaymc.gradle.sample" // for entrance splicing
6+
// for entrance splicing
7+
group = "org.allaymc.gradle.sample"
8+
version = libs.versions.allay.gradle.get()
9+
description = "Test plugin of AllayGradle!"
710

811
allay {
912
api = "0.15.0"
1013
plugin {
1114
name = "TestPlugin"
12-
entrance = ".TestPlugin" // "org.allaymc.gradle.sample.TestPlugin"
13-
description = "Test plugin of AllayGradle!"
15+
// "org.allaymc.gradle.sample.TestPlugin"
16+
entrance = ".TestPlugin"
17+
apiVersion = ">=0.15.0"
1418
authors += "Cdm2883"
15-
version = libs.versions.allay.gradle
1619
website = "https://github.com/AllayMC/AllayGradle"
1720
}
1821
}

0 commit comments

Comments
 (0)