Skip to content

Commit 8abd039

Browse files
committed
use template class instead of token replacer
1 parent 0e1711e commit 8abd039

File tree

4 files changed

+36
-11
lines changed

4 files changed

+36
-11
lines changed

build.gradle.kts

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1+
import org.jetbrains.gradle.ext.settings
2+
import org.jetbrains.gradle.ext.taskTriggers
13
import java.time.OffsetDateTime
24
import java.time.ZoneOffset
35

46
plugins {
57
java
6-
id("net.raphimc.class-token-replacer") version("1.1.4")
7-
idea
8+
id("org.jetbrains.gradle.plugin.idea-ext") version "1.1.10"
89
}
910

1011
group = properties["maven_group"] as String
@@ -81,6 +82,24 @@ tasks {
8182
dependsOn(copyPluginTask)
8283
}
8384

85+
val templateTask = register("generateTemplates", Copy::class.java) {
86+
group = "build"
87+
description = "Generates class templates"
88+
val props = mapOf(
89+
"version" to project.version
90+
)
91+
inputs.properties(props)
92+
from(file("src/main/templates"))
93+
into(layout.buildDirectory.dir("generated/sources/templates"))
94+
expand(props)
95+
}
96+
sourceSets.main.get().java.srcDir(templateTask.map { it.outputs })
97+
project.idea.project.settings.taskTriggers.afterSync(templateTask)
98+
99+
compileJava {
100+
dependsOn(templateTask)
101+
}
102+
84103
jar {
85104
manifest { // metadata about the plugin build
86105
attributes(mapOf(
@@ -92,14 +111,6 @@ tasks {
92111
}
93112
}
94113

95-
sourceSets {
96-
main {
97-
classTokenReplacer {
98-
property("\${version}", project.version)
99-
}
100-
}
101-
}
102-
103114
idea {
104115
module {
105116
excludeDirs.add(runDirectory.asFile)

settings.gradle.kts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,8 @@
1+
pluginManagement {
2+
repositories {
3+
mavenLocal()
4+
gradlePluginPortal()
5+
}
6+
}
7+
18
rootProject.name = "ZenithProxyExamplePlugin"

src/main/java/org/example/ExamplePlugin.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
@Plugin(
1313
id = "example-plugin",
14-
version = "${version}",
14+
version = BuildConstants.VERSION,
1515
description = "ZenithProxy Example Plugin",
1616
url = "https://github.com/rfresh2/ZenithProxyExamplePlugin",
1717
authors = {"rfresh2"},
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package org.example;
2+
3+
// The constants are replaced before compilation
4+
public class BuildConstants {
5+
6+
public static final String VERSION = "${version}";
7+
}

0 commit comments

Comments
 (0)