Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 23 additions & 8 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
plugins {
java
`maven-publish`
}

Expand All @@ -12,19 +11,34 @@ allprojects {
}
}

java {
withSourcesJar()
withJavadocJar()
}

publishing {
publications {
create<MavenPublication>("maven") {
from(components["java"])
// publish the module that actually contains the Java classes
from(project(":libdeflate-java-core").components["java"])

groupId = "org.powernukkitx"
artifactId = "libdeflate-java"
version = "0.0.3.PNX-SNAPSHOT"
version = project.version.toString()

pom {
name.set("libdeflate-java")
description.set("Java bindings for libdeflate used by PowerNukkitX")
url.set("https://github.com/PowerNukkitX/libdeflate-java")

licenses {
license {
name.set("MIT License")
url.set("https://opensource.org/licenses/MIT")
}
}

scm {
connection.set("scm:git:git://github.com/PowerNukkitX/libdeflate-java.git")
developerConnection.set("scm:git:ssh://github.com/PowerNukkitX/libdeflate-java.git")
url.set("https://github.com/PowerNukkitX/libdeflate-java")
}
}
}
}

Expand All @@ -37,6 +51,7 @@ publishing {
username = providers.gradleProperty("pnxUsername")
.orElse(providers.environmentVariable("PNX_REPO_USERNAME"))
.orNull

password = providers.gradleProperty("pnxPassword")
.orElse(providers.environmentVariable("PNX_REPO_PASSWORD"))
.orNull
Expand Down
50 changes: 26 additions & 24 deletions libdeflate-java-core/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,21 @@ plugins {
`java-library`
}

group = "org.powernukkitx"
version = "0.0.3-PNX"

java {
withSourcesJar()
withJavadocJar()
}

dependencies {
testImplementation("org.junit.jupiter:junit-jupiter-api:5.7.0")
testImplementation("org.junit.jupiter:junit-jupiter-params:5.7.0\"")
testImplementation("org.junit.jupiter:junit-jupiter-params:5.7.0")
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:5.7.0")
}

task("compileNatives") {
// Note: we should prefer compilation with GCC
tasks.register("compileNatives") {
val jniTempPath = Paths.get(project.rootDir.toString(), "tmp")

doLast {
Expand All @@ -25,7 +30,6 @@ task("compileNatives") {

when {
Os.isFamily(Os.FAMILY_MAC) -> {
// macOS is just a Unix like the rest.
if (System.getenv("CC") == null) {
env["CC"] = "clang"
}
Expand All @@ -45,16 +49,18 @@ task("compileNatives") {

exec {
executable = "make"
args = arrayListOf("clean", "all")
environment = env.toMap()
args = listOf("clean", "all")
environment = env
}
}

Os.isFamily(Os.FAMILY_UNIX) -> {
// Cover most Unices. It's 2020, so hopefully you're compiling on a modern open-source BSD or Linux distribution...
if (System.getenv("CC") == null) {
env["CC"] = "gcc"
}
val osName = System.getProperty("os.name").toLowerCase(Locale.ENGLISH)

val osName = System.getProperty("os.name").lowercase(Locale.ENGLISH)

env["DYLIB_SUFFIX"] = "so"
env["JNI_PLATFORM"] = osName
env["LIB_DIR"] = Paths.get(jniTempPath.toString(), "compiled", osName, System.getProperty("os.arch")).toString()
Expand All @@ -63,26 +69,22 @@ task("compileNatives") {

exec {
executable = "make"
args = arrayListOf("clean", "all")
environment = env.toMap()
args = listOf("clean", "all")
environment = env
}
}

Os.isFamily(Os.FAMILY_WINDOWS) -> {
if (System.getenv("MSVC") != null) {
// Windows is a very, very special case... we compile with Microsoft Visual Studio, which is a mess.
// There is the `vswhere` utility, which brings a tiny bit of sanity, but alas... it is probably better
// to invoke the build from a batch script.
//
// We'll need `vswhere` (you can install it via Chocolatey).
exec {
executable = "cmd"
args = arrayListOf("/C", "windows_build.bat")
args = listOf("/C", "windows_build.bat")
}
} else {
// Attempt to build using an MSYS2 environment.
if (System.getenv("CC") == null) {
env["CC"] = "gcc"
}

env["DYLIB_SUFFIX"] = "dll"
env["JNI_PLATFORM"] = "win32"
env["LIB_DIR"] = Paths.get(jniTempPath.toString(), "compiled", "windows", System.getProperty("os.arch")).toString()
Expand All @@ -91,12 +93,12 @@ task("compileNatives") {

exec {
executable = "make"
args = arrayListOf("clean", "all")
environment = env.toMap()
args = listOf("clean", "all")
environment = env
}
}

}

else -> {
throw RuntimeException("Your OS isn't supported. We'll take a PR!")
}
Expand All @@ -113,14 +115,14 @@ sourceSets {
}

tasks.named<ProcessResources>("processResources") {
dependsOn(tasks.get("compileNatives"))
dependsOn("compileNatives")
}

tasks.named<Test>("test") {
dependsOn(tasks.get("compileNatives"))
dependsOn("compileNatives")
useJUnitPlatform()
}

tasks.jar {
dependsOn(tasks.get("compileNatives"))
}
dependsOn("compileNatives")
}
Loading