diff --git a/bukkit/paper.mcdev.template.json b/bukkit/paper.mcdev.template.json index b28837d..e75c7b4 100644 --- a/bukkit/paper.mcdev.template.json +++ b/bukkit/paper.mcdev.template.json @@ -306,7 +306,7 @@ "destination": "gradle/wrapper/gradle-wrapper.properties", "condition": "$BUILD_SYSTEM=='Gradle'", "properties": { - "GRADLE_VERSION": "9.3.0" + "GRADLE_VERSION": "9.4.0" } }, { diff --git a/messages.properties b/messages.properties index ee4e83e..67abf71 100644 --- a/messages.properties +++ b/messages.properties @@ -34,6 +34,8 @@ creator.ui.gradle_plugins.label=Gradle Plugins creator.ui.use_datagen.label=Use Datagen: creator.ui.use_paper_manifest.label=Use Paper Manifest: creator.ui.use_paper_manifest.warning=Paper plugins are still experimental, their usage is discouraged for general purpose development. +creator.ui.use_annotation_processor.label=Use velocity-plugin.json annotation processor: +creator.ui.use_build_constants_templating.label=Enable source templating for constants: creator.ui.language.label=Language: diff --git a/velocity/.mcdev.template.json b/velocity/.mcdev.template.json index 2c0749c..3b8c52b 100644 --- a/velocity/.mcdev.template.json +++ b/velocity/.mcdev.template.json @@ -15,6 +15,17 @@ "Maven" ] }, + { + "name": "USE_VERSION_CATALOG", + "type": "boolean", + "default": false, + "visible": { + "dependsOn": [ + "BUILD_SYSTEM" + ], + "condition": "$BUILD_SYSTEM == 'Gradle'" + } + }, { "name": "LANGUAGE", "type": "string", @@ -28,6 +39,7 @@ "type": "semantic_version", "forceDropdown": true, "options": [ + "3.5.0-SNAPSHOT", "3.4.0-SNAPSHOT", "3.3.0-SNAPSHOT", "3.2.0-SNAPSHOT", @@ -46,10 +58,22 @@ "sourceUrl": "https://repo1.maven.org/maven2/org/jetbrains/kotlin/kotlin-stdlib-jdk8/maven-metadata.xml" }, "visible": { - "dependsOn": ["LANGUAGE"], + "dependsOn": [ + "LANGUAGE" + ], "condition": "$LANGUAGE == 'Kotlin'" } }, + { + "name": "USE_ANNOTATION_PROCESSOR", + "type": "boolean", + "default": false + }, + { + "name": "USE_BUILD_CONSTANTS_TEMPLATING", + "type": "boolean", + "default": "USE_ANNOTATION_PROCESSOR" + }, { "name": "PLUGIN_NAME", "type": "string", @@ -60,7 +84,9 @@ "type": "string", "validator": "[a-z][a-z0-9-_]{1,63}", "derives": { - "parents": ["PROJECT_NAME"], + "parents": [ + "PROJECT_NAME" + ], "method": "replace", "parameters": { "regex": "[^a-z0-9-_]+", @@ -74,7 +100,10 @@ "name": "MAIN_CLASS", "type": "class_fqn", "derives": { - "parents": ["BUILD_COORDS", "PLUGIN_NAME"], + "parents": [ + "BUILD_COORDS", + "PLUGIN_NAME" + ], "method": "suggestClassName" } }, @@ -102,6 +131,65 @@ } ] }, + { + "label": "creator.ui.gradle_plugins.label", + "collapsible": true, + "order": 2, + "visible": { + "dependsOn": [ + "BUILD_SYSTEM" + ], + "condition": "$BUILD_SYSTEM == 'Gradle'" + }, + "groupProperties": [ + { + "name": "RUN_VELOCITY_PLUGIN", + "type": "gradle_plugin", + "default": true, + "parameters": { + "sourceUrl": "https://plugins.gradle.org/m2/xyz/jpenilla/run-velocity/xyz.jpenilla.run-velocity.gradle.plugin/maven-metadata.xml" + } + }, + { + "name": "SHADOW_PLUGIN", + "type": "gradle_plugin", + "default": "$LANGUAGE=='Kotlin'", + "parameters": { + "sourceUrl": "https://repo.maven.apache.org/maven2/com/gradleup/shadow/shadow-gradle-plugin/maven-metadata.xml" + }, + "forceValue": { + "dependsOn": [ + "LANGUAGE" + ], + "condition": "$LANGUAGE == 'Kotlin'", + "value": "true" + } + }, + { + "name": "RESOURCE_FACTORY_PLUGIN", + "type": "gradle_plugin", + "default": false, + "parameters": { + "sourceUrl": "https://plugins.gradle.org/m2/xyz/jpenilla/resource-factory/maven-metadata.xml" + }, + "forceValue": { + "dependsOn": [ + "USE_ANNOTATION_PROCESSOR" + ], + "condition": "$USE_ANNOTATION_PROCESSOR", + "value": "false" + } + }, + { + "name": "IDEA_EXT_PLUGIN", + "type": "gradle_plugin", + "parameters": { + "sourceUrl": "https://plugins.gradle.org/m2/org/jetbrains/gradle/plugin/idea-ext/org.jetbrains.gradle.plugin.idea-ext.gradle.plugin/maven-metadata.xml" + }, + "visible": false + } + ] + }, { "name": "JAVA_VERSION", "type": "integer", @@ -109,9 +197,15 @@ "default": 17, "visible": false, "derives": { - "parents": ["VELOCITY_VERSION"], + "parents": [ + "VELOCITY_VERSION" + ], "default": 8, "select": [ + { + "condition": "$VELOCITY_VERSION.compareTo($semver.release(3, 5)) >= 0", + "value": 21 + }, { "condition": "$VELOCITY_VERSION.compareTo($semver.release(3, 3)) >= 0", "value": 17 @@ -137,40 +231,48 @@ "condition": "$USE_GIT" }, { - "template": "build.gradle.ft", - "destination": "build.gradle", - "condition": "$BUILD_SYSTEM=='Gradle' && $LANGUAGE=='Java'" + "template": "../.gitattributes.ft", + "destination": ".gitattributes", + "condition": "$USE_GIT" }, { - "template": "settings.gradle.ft", - "destination": "settings.gradle", - "condition": "$BUILD_SYSTEM=='Gradle' && $LANGUAGE=='Java'" + "template": "../gradle-wrapper.properties.ft", + "destination": "gradle/wrapper/gradle-wrapper.properties", + "condition": "$BUILD_SYSTEM=='Gradle'", + "properties": { + "GRADLE_VERSION": "9.4.0" + } }, { "template": "build.gradle.kts.ft", "destination": "build.gradle.kts", - "condition": "$BUILD_SYSTEM=='Gradle' && $LANGUAGE=='Kotlin'" + "condition": "$BUILD_SYSTEM=='Gradle'" + }, + { + "template": "libs.versions.toml.ft", + "destination": "gradle/libs.versions.toml", + "condition": "$BUILD_SYSTEM=='Gradle' && $USE_VERSION_CATALOG" }, { "template": "settings.gradle.kts.ft", "destination": "settings.gradle.kts", - "condition": "$BUILD_SYSTEM=='Gradle' && $LANGUAGE=='Kotlin'" + "condition": "$BUILD_SYSTEM=='Gradle'" }, { "template": "gradle.properties.ft", "destination": "gradle.properties", "condition": "$BUILD_SYSTEM=='Gradle'" }, - { - "template": "../gradle-wrapper.properties.ft", - "destination": "gradle/wrapper/gradle-wrapper.properties", - "condition": "$BUILD_SYSTEM=='Gradle'" - }, { "template": "pom.xml.ft", "destination": "pom.xml", "condition": "$BUILD_SYSTEM=='Maven'" }, + { + "template": "velocity-plugin.json.ft", + "destination": "src/main/resources/velocity-plugin.json", + "condition": "!$USE_ANNOTATION_PROCESSOR && !$RESOURCE_FACTORY_PLUGIN.enabled" + }, { "template": "MainClass.java.ft", "destination": "src/main/java/${MAIN_CLASS.path}.java", @@ -186,13 +288,15 @@ { "template": "BuildConstants.java.ft", "destination": "src/main/templates/${MAIN_CLASS.packagePath}/BuildConstants.java", - "condition": "$BUILD_SYSTEM=='Gradle'" + "condition": "$USE_BUILD_CONSTANTS_TEMPLATING" } ], "finalizers": [ { "type": "run_gradle_tasks", - "tasks": ["wrapper"], + "tasks": [ + "wrapper --gradle-version=latest" + ], "condition": "$BUILD_SYSTEM=='Gradle'" }, { @@ -207,6 +311,15 @@ "name": "Build", "condition": "$BUILD_SYSTEM=='Gradle'" }, + { + "type": "add_gradle_run", + "tasks": [ + "runVelocity" + ], + "name": "Run", + "select": true, + "condition": "$RUN_VELOCITY_PLUGIN.enabled && $BUILD_SYSTEM=='Gradle'" + }, { "type": "import_maven_project", "condition": "$BUILD_SYSTEM=='Maven'" diff --git a/velocity/BuildConstants.java.ft b/velocity/BuildConstants.java.ft index 2332b29..9cefaee 100644 --- a/velocity/BuildConstants.java.ft +++ b/velocity/BuildConstants.java.ft @@ -1,7 +1,6 @@ package ${MAIN_CLASS.packageName}; -// The constants are replaced before compilation +// These constants are replaced before compilation public class BuildConstants { - public static final String VERSION = "${version}"; } diff --git a/velocity/MainClass.java.ft b/velocity/MainClass.java.ft index 9c0eda0..885b9bc 100644 --- a/velocity/MainClass.java.ft +++ b/velocity/MainClass.java.ft @@ -3,14 +3,17 @@ package ${MAIN_CLASS.packageName}; import com.google.inject.Inject; import com.velocitypowered.api.event.proxy.ProxyInitializeEvent; import com.velocitypowered.api.event.Subscribe; +#if ($USE_ANNOTATION_PROCESSOR) import com.velocitypowered.api.plugin.Plugin; +#end import org.slf4j.Logger; +#if ($USE_ANNOTATION_PROCESSOR) @Plugin( id = "${PLUGIN_ID}", name = "${PLUGIN_NAME}", #if ($BUILD_SYSTEM == 'Gradle') - version = BuildConstants.VERSION + version = #if ($USE_BUILD_CONSTANTS_TEMPLATING) BuildConstants.VERSION #else "$VERSION" #end #elseif ($BUILD_SYSTEM == 'Maven') version = "${BUILD_COORDS.version}" #end @@ -24,11 +27,13 @@ import org.slf4j.Logger; ,authors = {${AUTHORS.toString('", "', '"', '"')}} #end ) +#end public class ${MAIN_CLASS.className} { @Inject private Logger logger; @Subscribe public void onProxyInitialization(ProxyInitializeEvent event) { + // Plugin initialization logic goes here } } diff --git a/velocity/MainClass.kt.ft b/velocity/MainClass.kt.ft index 2771364..aae0864 100644 --- a/velocity/MainClass.kt.ft +++ b/velocity/MainClass.kt.ft @@ -3,9 +3,12 @@ package ${MAIN_CLASS.packageName}; import com.google.inject.Inject import com.velocitypowered.api.event.Subscribe import com.velocitypowered.api.event.proxy.ProxyInitializeEvent +#if ($USE_ANNOTATION_PROCESSOR) import com.velocitypowered.api.plugin.Plugin +#end import org.slf4j.Logger +#if ($USE_ANNOTATION_PROCESSOR) @Plugin( id = "${PLUGIN_ID}", name = "${PLUGIN_NAME}", @@ -24,6 +27,7 @@ import org.slf4j.Logger ,authors = [${AUTHORS.toString('", "', '"', '"')}] #end ) +#end class ${MAIN_CLASS.className} @Inject constructor(val logger: Logger) { @Subscribe diff --git a/velocity/build.gradle.ft b/velocity/build.gradle.ft deleted file mode 100644 index 446636c..0000000 --- a/velocity/build.gradle.ft +++ /dev/null @@ -1,59 +0,0 @@ -plugins { - id 'java' - id 'eclipse' - id 'org.jetbrains.gradle.plugin.idea-ext' version '1.1.8' - id("xyz.jpenilla.run-velocity") version "2.3.1" -} - -group = '${BUILD_COORDS.groupId}' -version = '${BUILD_COORDS.version}' - -repositories { - mavenCentral() - maven { - name = "papermc-repo" - url = "https://repo.papermc.io/repository/maven-public/" - } -} - -dependencies { - compileOnly("com.velocitypowered:velocity-api:${VELOCITY_VERSION}") - annotationProcessor("com.velocitypowered:velocity-api:${VELOCITY_VERSION}") -} - -tasks { - runVelocity { - // Configure the Velocity version for our task. - // This is the only required configuration besides applying the plugin. - // Your plugin's jar (or shadowJar if present) will be used automatically. - velocityVersion("${VELOCITY_VERSION}") - } -} - -def targetJavaVersion = ${JAVA_VERSION} -java { - toolchain.languageVersion = JavaLanguageVersion.of(targetJavaVersion) -} - -tasks.withType(JavaCompile).configureEach { - options.encoding = 'UTF-8' - options.release.set(targetJavaVersion) -} - -def templateSource = file('src/main/templates') -def templateDest = layout.buildDirectory.dir('generated/sources/templates') -def generateTemplates = tasks.register('generateTemplates', Copy) { task -> - def props = [ - 'version': project.version - ] - task.inputs.properties props - - task.from templateSource - task.into templateDest - task.expand props -} - -sourceSets.main.java.srcDir(generateTemplates.map { it.outputs }) - -project.idea.project.settings.taskTriggers.afterSync generateTemplates -project.eclipse.synchronizationTasks(generateTemplates) diff --git a/velocity/build.gradle.kts.ft b/velocity/build.gradle.kts.ft index aa12e42..e8f903b 100644 --- a/velocity/build.gradle.kts.ft +++ b/velocity/build.gradle.kts.ft @@ -1,44 +1,137 @@ +#if ($USE_BUILD_CONSTANTS_TEMPLATING) import org.jetbrains.gradle.ext.settings import org.jetbrains.gradle.ext.taskTriggers +#end plugins { - kotlin("jvm") version "2.0.20-Beta1" - kotlin("kapt") version "2.0.20-Beta1" - id("com.github.johnrengelman.shadow") version "8.1.1" +#if ($LANGUAGE == 'Kotlin') + kotlin("jvm") version #if ($USE_VERSION_CATALOG) libs.versions.kotlin.get() #else "${KOTLIN_VERSION}" #end +#if ($USE_ANNOTATION_PROCESSOR) + kotlin("kapt") version #if ($USE_VERSION_CATALOG) libs.versions.kotlin.get() #else "${KOTLIN_VERSION}" #end +#end +#elseif ($LANGUAGE == 'Java') + id("java-library") +#end +#if ($USE_VERSION_CATALOG) +#if ($SHADOW_PLUGIN.enabled) + alias(libs.plugins.shadow) +#end +#if ($RUN_VELOCITY_PLUGIN.enabled) + alias(libs.plugins.run.velocity) +#end +#if ($RESOURCE_FACTORY_PLUGIN.enabled) + alias(libs.plugins.resource.factory.velocity) +#end +#if ($USE_BUILD_CONSTANTS_TEMPLATING) id("eclipse") - id("org.jetbrains.gradle.plugin.idea-ext") version "1.1.8" - id("xyz.jpenilla.run-velocity") version "2.3.1" + alias(libs.plugins.idea.ext) +#end +#else +#if ($SHADOW_PLUGIN.enabled) + id("com.gradleup.shadow") version "$SHADOW_PLUGIN.version" +#end +#if ($RUN_VELOCITY_PLUGIN.enabled) + id("xyz.jpenilla.run-velocity") version "$RUN_VELOCITY_PLUGIN.version" +#end +#if ($RESOURCE_FACTORY_PLUGIN.enabled) + id("xyz.jpenilla.resource-factory-velocity-convention") version "$RESOURCE_FACTORY_PLUGIN.version" +#end +#if ($USE_BUILD_CONSTANTS_TEMPLATING) + id("eclipse") + id("org.jetbrains.gradle.plugin.idea-ext") version "$IDEA_EXT_PLUGIN.version" +#end +#end } -group = "${BUILD_COORDS.groupId}" -version = "${BUILD_COORDS.version}" - repositories { mavenCentral() - maven("https://repo.papermc.io/repository/maven-public/") { - name = "papermc-repo" - } + maven("https://repo.papermc.io/repository/maven-public/") } dependencies { +#if ($USE_VERSION_CATALOG) + compileOnly(libs.velocity.api) +#if ($USE_ANNOTATION_PROCESSOR && $LANGUAGE == 'Java') + annotationProcessor(libs.velocity.api) +#elseif ($USE_ANNOTATION_PROCESSOR && $LANGUAGE == 'Kotlin') + kapt(libs.velocity.api) +#end +#if ($LANGUAGe == 'Kotlin') + implementation(libs.kotlin.stdlib) +#end +#else compileOnly("com.velocitypowered:velocity-api:${VELOCITY_VERSION}") +#if ($USE_ANNOTATION_PROCESSOR && $LANGUAGE == 'Java') + annotationProcessor("com.velocitypowered:velocity-api:${VELOCITY_VERSION}") +#elseif ($USE_ANNOTATION_PROCESSOR && $LANGUAGE == 'Kotlin') kapt("com.velocitypowered:velocity-api:${VELOCITY_VERSION}") +#end +#if ($LANGUAGe == 'Kotlin') implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8") +#end +#end +} +#if ($RESOURCE_FACTORY_PLUGIN.enabled) + +velocityPluginJson { + id = "${PLUGIN_ID}" + name = "${PLUGIN_NAME}" + main = "${MAIN_CLASS}" +#if ($AUTHORS) + authors = listOf(${AUTHORS.toStringQuoted()}) +#end +#if ($WEBSITE) + url = "$WEBSITE" +#end +} +#end + +#if ($LANGUAGE == 'Java') +java { + toolchain.languageVersion = JavaLanguageVersion.of(${JAVA_VERSION}) } +#else +kotlin { + jvmToolchain(${JAVA_VERSION}) +} +#end +#if ($SHADOW_PLUGIN.enabled || $RUN_VELOCITY_PLUGIN.enabled || !$RESOURCE_FACTORY_PLUGIN.enabled) tasks { +#if ($SHADOW_PLUGIN.enabled) + build { + dependsOn(shadowJar) + } +#end +#if ($RUN_VELOCITY_PLUGIN.enabled) +#if ($SHADOW_PLUGIN.enabled) + +#end runVelocity { +#if ($USE_VERSION_CATALOG) + velocityVersion(libs.versions.velocity.api.get()) +#else // Configure the Velocity version for our task. // This is the only required configuration besides applying the plugin. // Your plugin's jar (or shadowJar if present) will be used automatically. velocityVersion("${VELOCITY_VERSION}") +#end } -} +#end +#if (!$USE_ANNOTATION_PROCESSOR && !$RESOURCE_FACTORY_PLUGIN.enabled) +#if ($SHADOW_PLUGIN.enabled || $RUN_VELOCITY_PLUGIN.enabled) -val targetJavaVersion = 17 -kotlin { - jvmToolchain(targetJavaVersion) +#end + processResources { + val props = mapOf("version" to version #if ($DESCRIPTION), "description" to project.description #end) + filesMatching("velocity-plugin.json") { + expand(props) + } + } +#end } +#end +#if ($USE_BUILD_CONSTANTS_TEMPLATING) val templateSource = file("src/main/templates") val templateDest = layout.buildDirectory.dir("generated/sources/templates") @@ -55,3 +148,4 @@ sourceSets.main.configure { java.srcDir(generateTemplates.map { it.outputs }) } project.idea.project.settings.taskTriggers.afterSync(generateTemplates) project.eclipse.synchronizationTasks(generateTemplates) +#end diff --git a/velocity/gradle.properties.ft b/velocity/gradle.properties.ft index e69de29..fd2d0d6 100644 --- a/velocity/gradle.properties.ft +++ b/velocity/gradle.properties.ft @@ -0,0 +1,9 @@ +group=${BUILD_COORDS.groupId} +version=${BUILD_COORDS.version} +#if ($DESCRIPTION) +description=${DESCRIPTION} +#end + +org.gradle.configuration-cache=true +org.gradle.parallel=true +org.gradle.caching=true diff --git a/velocity/libs.versions.toml.ft b/velocity/libs.versions.toml.ft new file mode 100644 index 0000000..d8c857f --- /dev/null +++ b/velocity/libs.versions.toml.ft @@ -0,0 +1,39 @@ +[versions] +#if ($LANGUAGE == 'Kotlin') +kotlin = "$KOTLIN_VERSION" + +#end +velocity-api = "${VELOCITY_VERSION}" + +#if ($SHADOW_PLUGIN.enabled) +shadow = "$SHADOW_PLUGIN.version" +#end +#if ($RUN_VELOCITY_PLUGIN.enabled) +run-task = "$RUN_VELOCITY_PLUGIN.version" +#end +#if ($RESOURCE_FACTORY_PLUGIN.enabled) +resource-factory = "$RESOURCE_FACTORY_PLUGIN.version" +#end +#if ($USE_BUILD_CONSTANTS_TEMPLATING) +idea-ext = "$IDEA_EXT_PLUGIN.version" +#end + +[libraries] +velocity-api = { module = "com.velocitypowered:velocity-api", version.ref = "velocity-api" } +#if ($LANGUAGE == 'Kotlin') +kotlin-stdlib = { module = "org.jetbrains.kotlin:kotlin-stdlib-jdk8", version.ref = "kotlin" } +#end + +[plugins] +#if ($SHADOW_PLUGIN.enabled) +shadow = { id = "com.gradleup.shadow", version.ref = "shadow" } +#end +#if ($RUN_VELOCITY_PLUGIN.enabled) +run-velocity = { id = "xyz.jpenilla.run-velocity", version.ref = "run-task" } +#end +#if ($RESOURCE_FACTORY_PLUGIN.enabled) +resource-factory-velocity = { id = "xyz.jpenilla.resource-factory-velocity-convention", version.ref = "resource-factory" } +#end +#if ($USE_BUILD_CONSTANTS_TEMPLATING) +idea-ext = { id = "org.jetbrains.gradle.plugin.idea-ext", version.ref = "idea-ext" } +#end diff --git a/velocity/settings.gradle.ft b/velocity/settings.gradle.ft deleted file mode 100644 index 9e1c33f..0000000 --- a/velocity/settings.gradle.ft +++ /dev/null @@ -1 +0,0 @@ -rootProject.name = '${PROJECT_NAME}' diff --git a/velocity/velocity-plugin.json.ft b/velocity/velocity-plugin.json.ft new file mode 100644 index 0000000..79fa895 --- /dev/null +++ b/velocity/velocity-plugin.json.ft @@ -0,0 +1,15 @@ +{ + "id": "${PLUGIN_ID}", + "name": "${PLUGIN_NAME}", + "version": "$version", + "main": "${MAIN_CLASS}" +#if ($DESCRIPTION) + ,"description": "${DESCRIPTION}" +#end +#if ($WEBSITE) + ,"url": "${WEBSITE}" +#end +#if ($AUTHORS) + ,"authors": [${AUTHORS.toString('", "', '"', '"')}] +#end +}