-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.gradle.kts
More file actions
263 lines (224 loc) · 8.34 KB
/
Copy pathbuild.gradle.kts
File metadata and controls
263 lines (224 loc) · 8.34 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
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
/*
* Copyright (c) 2025 Florian Ohldag. All rights reserved.
*
* This software is proprietary and confidential.
* Unauthorized copying, modification, distribution, or use is strictly prohibited
* without prior written permission.
*/
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
import java.time.Instant
plugins {
java
`maven-publish`
id("com.gradleup.shadow") version "9.0.0-beta13"
}
group = "ovh.fedox"
version = "1.0.0"
val mainClassName = "FTemplate"
val purpose = "Template for FeDoX plugins"
val gitRef: String = System.getenv("CI_COMMIT_REF_NAME") ?: "local"
val isReleaseBuild: Boolean = !version.toString().contains("SNAPSHOT")
val localEnvFile = File("${System.getProperty("user.home")}/.gradle/reposilite-credentials.gradle.kts")
val reposiliteConfig = mutableMapOf<String, String>()
if (localEnvFile.exists()) {
logger.info("Loading Reposilite configuration from: ${localEnvFile.absolutePath}")
apply(from = localEnvFile.absolutePath)
reposiliteConfig["url"] = extra.get("reposilite.url") as String? ?: "https://repo.fedox.ovh"
reposiliteConfig["username"] = extra.get("reposilite.username") as String? ?: ""
reposiliteConfig["password"] = extra.get("reposilite.password") as String? ?: ""
reposiliteConfig["repository"] = extra.get("reposilite.repository") as String? ?: if (isReleaseBuild) "releases" else "snapshots"
} else {
logger.warn("Local Reposilite configuration file not found: ${localEnvFile.absolutePath}")
logger.warn("Create the file with your credentials for publishing.")
reposiliteConfig["url"] = System.getenv("REPOSILITE_URL") ?: "https://repo.fedox.ovh"
reposiliteConfig["username"] = System.getenv("REPOSILITE_USERNAME") ?: ""
reposiliteConfig["password"] = System.getenv("REPOSILITE_PASSWORD") ?: ""
reposiliteConfig["repository"] = System.getenv("REPOSILITE_REPOSITORY") ?: if (isReleaseBuild) "releases" else "snapshots"
}
// Java configuration
java {
sourceCompatibility = JavaVersion.VERSION_21
targetCompatibility = JavaVersion.VERSION_21
withSourcesJar()
}
// Repository configuration
repositories {
mavenCentral()
maven {
name = "JitPack"
url = uri("https://jitpack.io")
}
maven {
name = "Reposilite"
url = uri("${reposiliteConfig["url"]}/releases")
credentials {
username = reposiliteConfig["username"]
password = reposiliteConfig["password"]
}
}
}
// Dependencies
dependencies {
// Compile-only dependencies
compileOnly(libs.lombok)
// Annotation processors
annotationProcessor(libs.lombok)
}
val pluginNameLower = project.name.lowercase()
val mainClass = "${group}.${pluginNameLower}.${mainClassName}"
tasks.processResources {
val props = mapOf(
"NAME" to mainClassName,
"VERSION" to project.version,
"DESCRIPTION" to purpose,
"AUTHOR" to "FeDoX Development",
"AUTHORS" to "\"Florian Ohldag\", \"FeDoX Development\"",
"WEBSITE" to "https://fedox.ovh",
"MAIN" to mainClass,
)
inputs.properties(props)
filteringCharset = "UTF-8"
filesMatching("plugin.yml") {
expand(props)
}
filesMatching("**/*.yml") {
expand(props)
}
filesMatching("**/*.yaml") {
expand(props)
}
filesMatching("**/*.properties") {
expand(props)
}
}
// Task configuration
tasks {
withType<JavaCompile>().configureEach {
options.encoding = "UTF-8"
options.release.set(21)
}
named<Jar>("jar") {
enabled = false
archiveClassifier.set("thin")
}
named<ShadowJar>("shadowJar") {
archiveClassifier.set("")
mergeServiceFiles()
// Exclude unnecessary files
exclude("META-INF/*.SF")
exclude("META-INF/*.DSA")
exclude("META-INF/*.RSA")
exclude("META-INF/DEPENDENCIES")
exclude("META-INF/LICENSE*")
exclude("META-INF/NOTICE*")
manifest {
attributes(
mapOf(
"Implementation-Title" to project.name,
"Implementation-Version" to project.version,
"Implementation-Vendor" to "Florian Ohldag",
"Built-By" to System.getProperty("user.name"),
"Built-JDK" to System.getProperty("java.version"),
"Built-Date" to Instant.now().toString(),
"Git-Ref" to gitRef
)
)
}
}
build {
dependsOn(shadowJar)
}
publish {
dependsOn(shadowJar)
doFirst {
if (reposiliteConfig["username"].isNullOrEmpty() || reposiliteConfig["password"].isNullOrEmpty()) {
throw GradleException("Reposilite credentials missing! Create ~/.gradle/reposilite-credentials.gradle.kts")
}
}
}
}
// Publishing configuration for Reposilite
publishing {
publications {
create<MavenPublication>("maven") {
groupId = project.group.toString()
artifactId = project.name
version = project.version.toString()
artifact(tasks.shadowJar)
pom {
name.set(project.name)
description.set("${project.name} for FeDoX.ovh")
url.set("https://github.com/FeDoX-Network/${project.name}")
licenses {
license {
name.set("GNU Affero General Public License v3.0")
url.set("https://www.gnu.org/licenses/agpl-3.0.en.html")
}
}
developers {
developer {
id.set("florian-ohldag")
name.set("Florian Ohldag")
email.set("contact@fedox.ovh")
}
}
scm {
connection.set("scm:git:git://github.com/FeDoX-Network/${project.name}.git")
developerConnection.set("scm:git:ssh://github.com/FeDoX-Network/${project.name}.git")
url.set("https://github.com/FeDoX-Network/${project.name}")
}
}
}
}
repositories {
maven {
name = "Reposilite"
url = uri("${reposiliteConfig["url"]}/${reposiliteConfig["repository"]}")
credentials {
username = reposiliteConfig["username"]
password = reposiliteConfig["password"]
}
// Reposilite-specific configuration
isAllowInsecureProtocol = reposiliteConfig["url"]?.startsWith("http://") == true
}
}
}
// Custom Tasks
tasks.register("printReposiliteConfig") {
group = "help"
description = "Displays the current Reposilite configuration"
doLast {
println("=== Reposilite Configuration ===")
println("URL: ${reposiliteConfig["url"]}")
println("Repository: ${reposiliteConfig["repository"]}")
println("Username: ${reposiliteConfig["username"]?.let { if (it.isNotEmpty()) "***" else "NOT SET" }}")
println("Password: ${reposiliteConfig["password"]?.let { if (it.isNotEmpty()) "***" else "NOT SET" }}")
println("Local config file: ${if (localEnvFile.exists()) "✓ Found" else "✗ Not found"}")
println("Project version: ${project.version}")
println("Git reference: $gitRef")
println("Release build: $isReleaseBuild")
}
}
tasks.register("createReposiliteConfig") {
group = "setup"
description = "Creates a template for the Reposilite configuration file"
doLast {
val configContent = """
// Reposilite configuration for ${project.name}
// File: ${localEnvFile.absolutePath}
extra.set("reposilite.url", "https://repo.zflockii.de")
extra.set("reposilite.username", "your-username")
extra.set("reposilite.password", "your-password")
extra.set("reposilite.repository", "releases") // or "snapshots"
""".trimIndent()
localEnvFile.parentFile.mkdirs()
localEnvFile.writeText(configContent)
println("Reposilite configuration file created: ${localEnvFile.absolutePath}")
println("Please edit the file and insert your actual credentials!")
}
}
// Gradle Wrapper
tasks.wrapper {
gradleVersion = "8.5"
distributionType = Wrapper.DistributionType.BIN
}