11import com.github.jengelman.gradle.plugins.shadow.transformers.Log4j2PluginsCacheFileTransformer
2+ import java.util.Properties
23
34plugins {
45 alias(libs.plugins.shadow)
56 alias(libs.plugins.extra.java.module.info)
67}
78
89dependencies {
9- api(projects.api)
10+ implementation(project(" :api" )) {
11+ attributes {
12+ attribute(LibraryElements .LIBRARY_ELEMENTS_ATTRIBUTE , objects.named(LibraryElements .CLASSES ))
13+ }
14+ }
1015 api(libs.bedrock.connection) {
1116 exclude(" com.nukkitx.fastutil" )
1217 }
@@ -15,6 +20,8 @@ dependencies {
1520 api(libs.leveldb.mcpe.jni)
1621 api(libs.noise)
1722
23+ compileOnly(libs.jsr305)
24+
1825 implementation(libs.terminal.console.appender)
1926 implementation(libs.jline.terminal)
2027 implementation(libs.jline.reader)
@@ -28,14 +35,18 @@ dependencies {
2835 implementation(libs.jose.jwt)
2936 implementation(libs.upnp)
3037
31- compileOnly(libs.jsr305)
32-
3338 testImplementation(libs.junit.jupiter.api)
3439 testImplementation(libs.junit.jupiter.engine)
3540}
3641
3742extraJavaModuleInfo {
38- skipLocalJars = true
43+ failOnAutomaticModules.set(false )
44+ automaticModule(libs.block.state.updater, " org.cloudburstmc.blockstateupdater" ) {
45+ overrideModuleName()
46+ }
47+ automaticModule(libs.math.immutable, " org.cloudburstmc.math.immutable" ) {
48+ overrideModuleName()
49+ }
3950 automaticModule(libs.noise, " net.daporkchop.lib.noise" )
4051 automaticModule(libs.upnp, " org.cloudburstmc.upnp" )
4152 automaticModule(" net.daporkchop.lib:math" , " net.daporkchop.lib.math" )
@@ -51,11 +62,15 @@ extraJavaModuleInfo {
5162 automaticModule(" io.airlift:aircompressor" , " io.airlift.aircompressor" )
5263 automaticModule(" com.github.stephenc.jcip:jcip-annotations" , " com.github.stephenc.jcip.annotations" )
5364 automaticModule(" aopalliance:aopalliance" , " aopalliance.aop" )
54- knownModule(" com.google.guava:failureaccess" , " com.google.common.util.concurrent.internal" )
65+ module(" com.google.guava:failureaccess" , " com.google.guava.failureaccess" ) {
66+ patchRealModule()
67+ }
5568 automaticModule(" com.google.code.findbugs:jsr305" , " com.google.code.findbugs.jsr305" )
56- knownModule(" com.google.j2objc:j2objc-annotations" , " com.google.j2objc.annotations" )
57- automaticModule(" net.jodah:expiringmap" , " net.jodah.expiringmap" )
69+ module(" com.google.j2objc:j2objc-annotations" , " com.google.j2objc.annotations" ) {
70+ patchRealModule()
71+ }
5872 automaticModule(" com.google.guava:listenablefuture" , " com.google.guava.listenablefuture" )
73+ automaticModule(" net.jodah:expiringmap" , " net.jodah.expiringmap" )
5974 automaticModule(" org.osgi:org.osgi.resource" , " org.osgi.resource" )
6075 automaticModule(" org.osgi:org.osgi.service.serviceloader" , " org.osgi.service.serviceloader" )
6176}
@@ -76,7 +91,7 @@ tasks.shadowJar {
7691 transform(Log4j2PluginsCacheFileTransformer ())
7792 mergeServiceFiles()
7893
79- dependsOn(" :api:classes" )
94+ dependsOn(" :api:classes" , " :api:jar " )
8095 from(project(" :api" ).sourceSets.main.get().output)
8196}
8297
@@ -85,4 +100,58 @@ tasks.register<JavaExec>("run") {
85100 workingDir = projectDir.resolve(" run" )
86101 workingDir.mkdir()
87102 classpath = sourceSets[" main" ].runtimeClasspath
103+ jvmArgs(
104+ " --enable-native-access=ALL-UNNAMED" ,
105+ " --add-opens" , " java.base/java.lang=ALL-UNNAMED" ,
106+ " --add-opens" , " java.base/sun.nio.ch=ALL-UNNAMED"
107+ )
108+ systemProperty(" org.jline.terminal.disableDeprecatedProviderWarning" , " true" )
109+ systemProperty(" guice_bytecode_gen_option" , " DISABLED" )
110+ systemProperty(" io.netty.noUnsafe" , " true" )
111+ }
112+
113+ abstract class GenerateGitPropertiesTask : DefaultTask () {
114+ @get:OutputFile
115+ abstract val outputFile: RegularFileProperty
116+
117+ @get:Inject
118+ abstract val providers: ProviderFactory
119+
120+ @TaskAction
121+ fun generate () {
122+ val file = outputFile.get().asFile
123+ file.parentFile.mkdirs()
124+ val properties = Properties ()
125+
126+ try {
127+ val gitCommit = providers.exec {
128+ commandLine(" git" , " rev-parse" , " --short" , " HEAD" )
129+ }.standardOutput.asText.get().trim()
130+ properties[" git.commit.id.abbrev" ] = gitCommit
131+
132+ val gitBranch = providers.exec {
133+ commandLine(" git" , " rev-parse" , " --abbrev-ref" , " HEAD" )
134+ }.standardOutput.asText.get().trim()
135+ properties[" git.branch" ] = gitBranch
136+
137+ val gitCommitTime = providers.exec {
138+ commandLine(" git" , " log" , " -1" , " --format=%ct" )
139+ }.standardOutput.asText.get().trim()
140+ properties[" git.commit.time" ] = gitCommitTime
141+ } catch (e: Exception ) {
142+ println (" Warning: Could not retrieve git information: ${e.message} " )
143+ properties[" git.commit.id.abbrev" ] = " unknown"
144+ }
145+
146+ file.outputStream().use { properties.store(it, " Git Information" ) }
147+ }
148+ }
149+
150+ tasks.register<GenerateGitPropertiesTask >(" generateGitProperties" ) {
151+ outputFile.set(layout.buildDirectory.file(" resources/main/git.properties" ))
152+ notCompatibleWithConfigurationCache(" Executes git commands at runtime" )
153+ }
154+
155+ tasks.processResources {
156+ dependsOn(" generateGitProperties" )
88157}
0 commit comments