-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.gradle
More file actions
209 lines (180 loc) · 6.52 KB
/
build.gradle
File metadata and controls
209 lines (180 loc) · 6.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
plugins {
id 'java'
id("xyz.jpenilla.run-paper") version "2.3.1"
id 'maven-publish'
}
// Automatic versioning from environment variable or Git with Maven-compatible format
def getVersion() {
// First, try to get VERSION from environment (set by CI/CD)
def envVersion = System.getenv('VERSION')
if (envVersion && !envVersion.isEmpty()) {
def cleanVersion = cleanVersionString(envVersion)
println "Using VERSION from environment: ${cleanVersion}"
return cleanVersion
}
// Try to get version from Git tag (only if on a tag, not commits after tag)
try {
def stdout = new ByteArrayOutputStream()
exec {
commandLine 'git', 'describe', '--tags', '--exact-match', '--always'
standardOutput = stdout
errorOutput = new ByteArrayOutputStream()
}
def gitVersion = stdout.toString().trim()
if (gitVersion && !gitVersion.isEmpty()) {
def cleanVersion = cleanVersionString(gitVersion)
println "Using VERSION from Git tag: ${cleanVersion}"
return cleanVersion
}
} catch (Exception e) {
// Not on a tag, continue to fallback
}
// Fallback for development builds
try {
def stdout = new ByteArrayOutputStream()
exec {
commandLine 'git', 'rev-parse', '--short', 'HEAD'
standardOutput = stdout
errorOutput = new ByteArrayOutputStream()
}
def gitHash = stdout.toString().trim()
def devVersion = "1.0.0-dev-${gitHash}"
println "Using development version: ${devVersion}"
return devVersion
} catch (Exception e) {
println "Warning: Could not determine version. Using default."
return '1.0.0-dev'
}
}
// Clean version string to be Maven-compatible
def cleanVersionString(String version) {
// Remove 'v' prefix if present
version = version.startsWith('v') ? version.substring(1) : version
// If version contains git hash (like "1.3-2-g9d708f1"), it's not a release tag
// This should only happen if not on an exact tag
if (version.contains('-g')) {
throw new GradleException(
"""
❌ INVALID VERSION FORMAT: "${version}"
This looks like a commit reference, not a release tag.
You must create a proper Git tag for releases.
Examples of valid tags:
git tag v1.0.0
git tag v1.0.1
git tag v1.1.0-beta
Then push the tag:
git push origin v1.0.0
""".stripIndent()
)
}
// Ensure Maven-compatible format (major.minor.patch)
def parts = version.split('\\.')
if (parts.length < 3) {
// Add .0 patches if missing (1.4 -> 1.4.0)
while (parts.length < 3) {
version = version + ".0"
parts = version.split('\\.')
}
}
println "Normalized version to Maven format: ${version}"
return version
}
group = 'dev.steyon'
version = getVersion()
println "Building TranslateMC-Plugin version: ${version}"
repositories {
mavenCentral()
maven {
name = "papermc-repo"
url = "https://repo.papermc.io/repository/maven-public/"
}
maven {
url = 'https://repo.extendedclip.com/releases/'
}
}
dependencies {
compileOnly("io.papermc.paper:paper-api:1.21-R0.1-SNAPSHOT")
compileOnly 'me.clip:placeholderapi:2.11.7'
implementation 'com.google.code.gson:gson:2.10.1'
}
tasks {
runServer {
// Configure the Minecraft 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.
minecraftVersion("1.21")
}
}
def targetJavaVersion = 21
java {
def javaVersion = JavaVersion.toVersion(targetJavaVersion)
sourceCompatibility = javaVersion
targetCompatibility = javaVersion
if (JavaVersion.current() < javaVersion) {
toolchain.languageVersion = JavaLanguageVersion.of(targetJavaVersion)
}
}
tasks.withType(JavaCompile).configureEach {
options.encoding = 'UTF-8'
if (targetJavaVersion >= 10 || JavaVersion.current().isJava10Compatible()) {
options.release.set(targetJavaVersion)
}
}
processResources {
def props = [version: version]
inputs.properties props
filteringCharset 'UTF-8'
filesMatching('plugin.yml') {
expand props
}
}
publishing {
repositories {
maven {
name = "github"
url = uri("https://maven.pkg.github.com/steyondev/TranslateMC-Plugin")
credentials {
username = System.getenv("GITHUB_ACTOR") ?: "UNKNOWN"
password = System.getenv("GITHUB_TOKEN") ?: "UNKNOWN"
}
}
}
publications {
gpr(MavenPublication) {
from(components.java)
pom {
name = "TranslateMC-Plugin"
description = "Easily translate your server with our plugin!"
url = "https://github.com/steyondev/TranslateMC-Plugin"
scm {
url = "https://github.com/steyondev/TranslateMC-Plugin"
connection = "scm:git:git://github.com/steyondev/TranslateMC-Plugin.git"
developerConnection = "scm:git:ssh://git@github.com:steyondev/TranslateMC-Plugin.git"
}
licenses {
license {
name = "MIT License"
url = "https://opensource.org/licenses/MIT"
}
}
developers {
developer {
name = "Steyon Development"
}
}
}
}
}
}
// Debug: Print version info and credentials check
println "==========================================="
println "Project Configuration:"
println " Group: ${group}"
println " Artifact: ${rootProject.name}"
println " Version: ${version}"
println " Repository: https://maven.pkg.github.com/steyondev/TranslateMC-Plugin"
println "==========================================="
println "Credentials Check:"
println " GITHUB_ACTOR: ${System.getenv("GITHUB_ACTOR") ? "✅ Set" : "❌ NOT SET"}"
println " GITHUB_TOKEN: ${System.getenv("GITHUB_TOKEN") ? "✅ Set" : "❌ NOT SET"}"
println "==========================================="