11import java.nio.charset.StandardCharsets
2- import java.nio.file.Files
3- import java.nio.file.Path
4- import java.nio.file.StandardCopyOption
2+ // Explicit Gradle API imports to fix Kotlin DSL unresolved references
3+ import org.gradle.external.javadoc.CoreJavadocOptions
4+ import org.gradle.api.tasks.AbstractCopyTask
5+ import org.gradle.api.tasks.bundling.AbstractArchiveTask
6+ import org.gradle.api.tasks.compile.JavaCompile
7+ import org.gradle.api.tasks.javadoc.Javadoc
8+ import org.gradle.api.file.DuplicatesStrategy
9+ import org.gradle.api.DefaultTask
10+ import org.gradle.api.tasks.Copy
11+ import org.gradle.api.publish.maven.MavenPublication
12+ import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
13+ import org.gradle.testing.jacoco.tasks.JacocoReport
514
615plugins {
716 `java- library`
817 `maven- publish`
18+ java
919 idea
1020 jacoco
1121 id(" io.github.goooler.shadow" ) version " 8.1.7"
@@ -17,15 +27,8 @@ group = "org.powernukkitx"
1727version = " 2.0.0-SNAPSHOT"
1828description = " PNX Server"
1929java.sourceCompatibility = JavaVersion .VERSION_21
30+ java.targetCompatibility = JavaVersion .VERSION_21
2031
21- repositories {
22- mavenLocal()
23- mavenCentral()
24- maven(" https://repo.maven.apache.org/maven2/" )
25- maven(" https://jitpack.io" )
26- maven(" https://repo.opencollab.dev/maven-releases/" )
27- maven(" https://repo.opencollab.dev/maven-snapshots/" )
28- }
2932
3033dependencies {
3134 api(libs.bundles.netty)
@@ -127,7 +130,7 @@ tasks.register<DefaultTask>("buildForGithubAction") {
127130}
128131
129132tasks.build {
130- dependsOn(tasks. shadowJar)
133+ dependsOn(" shadowJar" )
131134 group = " alpha build"
132135}
133136
@@ -147,36 +150,38 @@ tasks.test {
147150 useJUnitPlatform()
148151 jvmArgs(listOf (" --add-opens" , " java.base/java.lang=ALL-UNNAMED" ))
149152 jvmArgs(listOf (" --add-opens" , " java.base/java.io=ALL-UNNAMED" ))
150- finalizedBy(tasks. jacocoTestReport) // report is always generated after tests run
153+ finalizedBy(" jacocoTestReport" ) // report is always generated after tests run
151154}
152155
153- tasks.jacocoTestReport {
156+ tasks.named< JacocoReport >( " jacocoTestReport" ) {
154157 reports {
155158 csv.required = false
156159 xml.required = true
157160 html.required = false
158161 }
159- dependsOn(tasks. test) // tests are required to run before generating the report
162+ dependsOn(" test" ) // tests are required to run before generating the report
160163}
161164
162165tasks.withType<AbstractCopyTask >() {
163166 duplicatesStrategy = DuplicatesStrategy .INCLUDE
164167}
165168
166169tasks.named<AbstractArchiveTask >(" sourcesJar" ) {
167- destinationDirectory = layout.buildDirectory
170+ destinationDirectory.set( layout.buildDirectory)
168171}
169172
170- tasks.jar {
171- destinationDirectory = layout.buildDirectory
172- doLast {// execution phase
173- val f: RegularFile = archiveFile.get()
174- val tf: RegularFile = layout.buildDirectory.file(" ${project.description} .jar" ).get()
175- Files .copy(Path .of(f.asFile.absolutePath), Path .of(tf.asFile.absolutePath), StandardCopyOption .REPLACE_EXISTING )
176- }
173+ // Improve build reproducibility for better caching
174+ tasks.withType<AbstractArchiveTask > {
175+ isPreserveFileTimestamps = false
176+ isReproducibleFileOrder = true
177177}
178178
179- tasks.shadowJar {
179+ tasks.named< org.gradle.jvm.tasks.Jar > (" jar" ) {
180+ destinationDirectory.set(layout.buildDirectory)
181+ archiveFileName.set(" ${project.description} .jar" )
182+ }
183+
184+ tasks.named<ShadowJar >(" shadowJar" ) {
180185 dependsOn(" copyDependencies" )
181186 manifest {
182187 attributes(
@@ -186,7 +191,7 @@ tasks.shadowJar {
186191
187192 transform(com.github.jengelman.gradle.plugins.shadow.transformers.Log4j2PluginsCacheFileTransformer ::class .java) // required to fix shadowJar log4j2 issue
188193
189- destinationDirectory = layout.buildDirectory
194+ destinationDirectory.set( layout.buildDirectory)
190195}
191196
192197tasks.register<Copy >(" copyDependencies" ) {
@@ -247,4 +252,4 @@ tasks.withType<JavaCompile> {
247252
248253tasks.withType<Javadoc > {
249254 options.encoding = " UTF-8"
250- }
255+ }
0 commit comments