import static org.apache.tools.ant.taskdefs.condition.Os.* import static groovy.lang.Tuple.tuple plugins { id 'java' id 'maven-publish' id 'signing' } group = 'net.fokinatorr.sparkle' version = '0.1-beta' description = """The core module of SPJF (code name Sparkle). Sparkle is a framework for creating graphical applications, with an API similar to the functionality MIT Scratch offers. There are also a lot more features and flexibility. To run Sparkle, you only need this module; if you want additional functionality, see other modules with group ID '$group'.""" repositories { add(mavenCentral()) add(mavenLocal()) } java { sourceCompatibility = 25 targetCompatibility = 25 } def lombokVersion = "1.18.44" def lwjglVersion = "3.4.1" def lwjglNativesAll = [ 'windows': tuple('nativesWindows', 'Windows x64', '*.dll'), 'linux': tuple('nativesLinux', 'Linux x64', '*.so'), 'macos-arm64': tuple('nativesMacOSArm64', 'macOS arm64', '*.dylib'), 'macos': tuple('nativesMacOS', 'macOS x86_64', '*.dylib'), ] def lwjglNativesCurrent = findLWJGLNatives() def lwjglNativeLibsCurrent = [ "org.lwjgl:lwjgl:$lwjglVersion:$lwjglNativesCurrent", "org.lwjgl:lwjgl-glfw:$lwjglVersion:$lwjglNativesCurrent", "org.lwjgl:lwjgl-nanovg:$lwjglVersion:$lwjglNativesCurrent", "org.lwjgl:lwjgl-openal:$lwjglVersion:$lwjglNativesCurrent", "org.lwjgl:lwjgl-opengl:$lwjglVersion:$lwjglNativesCurrent", "org.lwjgl:lwjgl-stb:$lwjglVersion:$lwjglNativesCurrent" ] List lwjglNativeLibsAll = [] lwjglNativesAll.each { sourceSets.register(it.value.v1) def classifier = "natives-$it.key" lwjglNativeLibsAll.addAll([ "org.lwjgl:lwjgl:$lwjglVersion:$classifier", "org.lwjgl:lwjgl-glfw:$lwjglVersion:$classifier", "org.lwjgl:lwjgl-nanovg:$lwjglVersion:$classifier", "org.lwjgl:lwjgl-openal:$lwjglVersion:$classifier", "org.lwjgl:lwjgl-opengl:$lwjglVersion:$classifier", "org.lwjgl:lwjgl-stb:$lwjglVersion:$classifier" ]) } dependencies { implementation 'it.unimi.dsi:fastutil:8.5.15' implementation 'org.slf4j:slf4j-api:2.0.16' implementation 'org.joml:joml:1.10.8' implementation 'net.fokinatorr:poly2tri:0.7.0' implementation 'net.fokinatorr:lwjgl-exceptions:1.0-SNAPSHOT' implementation "org.lwjgl:lwjgl:$lwjglVersion" implementation "org.lwjgl:lwjgl-glfw:$lwjglVersion" implementation "org.lwjgl:lwjgl-nanovg:$lwjglVersion" implementation "org.lwjgl:lwjgl-openal:$lwjglVersion" implementation "org.lwjgl:lwjgl-opengl:$lwjglVersion" implementation "org.lwjgl:lwjgl-stb:$lwjglVersion" runtimeOnly 'ch.qos.logback:logback-classic:1.5.18' // SLF4J implementation lwjglNativeLibsAll.forEach {lib -> compileOnly lib } compileOnly "org.projectlombok:lombok:$lombokVersion" annotationProcessor "org.projectlombok:lombok:$lombokVersion" testImplementation 'io.github.hakky54:logcaptor:2.12.6' testImplementation 'org.junit.jupiter:junit-jupiter:5.11.4' testRuntimeOnly 'ch.qos.logback:logback-classic:1.5.18' // SLF4J implementation testRuntimeOnly 'org.junit.platform:junit-platform-launcher:6.1.0' lwjglNativeLibsCurrent.forEach {lib -> testRuntimeOnly lib } testCompileOnly "org.projectlombok:lombok:$lombokVersion" testAnnotationProcessor "org.projectlombok:lombok:$lombokVersion" } test { useJUnitPlatform() } processResources { doLast { copy { from file('./LICENSE') into destinationDir } } } processTestResources { dependsOn processResources doLast { copy { from processResources.destinationDir into destinationDir } copy { from destinationDir into compileTestJava.destinationDirectory.get().asFile } } } tasks.register('generateNativesModules') { doLast { lwjglNativesAll.each { entry -> def nativesNameLower = entry.key def sourceSetName = entry.value.v1 def nativesNameFriendly = entry.value.v2 def sourcesDir = new File(temporaryDir, "$sourceSetName/java") def resourcesDir = new File(temporaryDir, "$sourceSetName/resources") copy { from new File(projectDir, '/src/nativeTemplate/java') into sourcesDir filter { String line -> line .replace('NATIVES_NAME_LOWER_NODASH', nativesNameLower.replace('-', '.')) .replace('NATIVES_NAME_LOWER', nativesNameLower) .replace('NATIVES_NAME_FRIENDLY', nativesNameFriendly) } include '**/*.java' } sourceSets.named(sourceSetName).get().java.srcDir sourcesDir def nativesDir = new File(resourcesDir, "natives/$nativesNameLower") sourceSets.main.compileClasspath.files.each { jar -> if (jar.name.contains("natives-$nativesNameLower")) { copy { from zipTree(jar).files // flatten include '*.dll', '*.so', '*.dylib' into nativesDir } } } sourceSets.named(sourceSetName).get().resources.srcDir resourcesDir } } } jar { dependsOn compileJava, processResources from compileJava.destinationDirectory.get().asFile, processResources.destinationDir } tasks.register('jarSources', Jar) { archiveClassifier = 'sources' from sourceSets.main.java.asFileTree } lwjglNativesAll.each { entry -> def sourceSetName = entry.value.v1 def sourceSetNameUpper = sourceSetName.substring(0, 1).toUpperCase(Locale.ENGLISH) + sourceSetName.substring(1) def compile = tasks.named("compile${sourceSetNameUpper}Java") { dependsOn generateNativesModules, jar doFirst { def coreJar = files(jar.archiveFile.get().asFile) classpath += coreJar } }.get() as JavaCompile def resources = tasks.named("process${sourceSetNameUpper}Resources") { dependsOn generateNativesModules }.get() as ProcessResources tasks.register("jar${sourceSetNameUpper}", Jar) { dependsOn compile, resources archiveClassifier = "natives-$entry.key" from compile.destinationDirectory.get().asFile, resources.destinationDir } } tasks.register('jarNativesAll') { lwjglNativesAll.each { entry -> def sourceSetName = entry.value.v1 def sourceSetNameUpper = sourceSetName.substring(0, 1).toUpperCase(Locale.ENGLISH) + sourceSetName.substring(1) dependsOn "jar$sourceSetNameUpper" } } assemble { dependsOn jar, jarSources, jarNativesAll } def project = project // prevent 'cannot resolve' warnings publishing { repositories { maven { name = 'Central' url = 'https://oss.sonatype.org/service/local/staging/deploy/maven2' credentials { username = project.findProperty('ossrh.username') ?: System.getenv('OSSRH_USERNAME') password = project.findProperty('ossrh.password') ?: System.getenv('OSSRH_PASSWORD') } } } publications { register('maven', MavenPublication) { // publish once pom { name = 'Sparkle Core Module' description = project.description url = 'https://sparkle.fokinatorr.net/core' licenses { license { name = 'MIT License' url = 'https://opensource.org/license/mit' } } developers { developer { name = 'Fokinatorr_' url = 'https://fokinatorr.net' } } scm { connection = 'scm:git:git://github.com/SparkleJ-Framework/sparkle-core.git' developerConnection = 'scm:git:ssh://github.com/SparkleJ-Framework/sparkle-core.git' url = 'https://github.com/SparkleJ-Framework/sparkle-core' } } from project.components.java artifact(jarSources) { classifier = 'sources' } lwjglNativesAll.each { entry -> def sourceSetName = entry.value.v1 def sourceSetNameUpper = sourceSetName.substring(0, 1).toUpperCase(Locale.ENGLISH) + sourceSetName.substring(1) artifact(project.tasks.named("jar$sourceSetNameUpper").get()) { classifier = "natives-$entry.key" } } } } } def key = project.findProperty('signingKey').toString() ?: System.getenv('SIGNING_KEY') def password = project.findProperty('signingPassword').toString() ?: System.getenv('SIGNING_PASSWORD') if (key != "null" && password != "null") { signing { useInMemoryPgpKeys(key, password) sign publishing.publications } } else { logger.log(LogLevel.WARN, 'Signing disabled: no key or password specified') } static String findLWJGLNatives() { String lwjglNatives = null if (isArch("amd64")) { if (isFamily("unix") && isName("linux")) { lwjglNatives = "natives-linux" } else if (isFamily("windows")) { lwjglNatives = "natives-windows" } } else if (isFamily("mac")) { if (isArch("aarch64")) { lwjglNatives = "natives-macos-arm64" } else if (isArch("x86_64")) { // maybe remove this in the future lwjglNatives = "natives-macos" } // Add MoltenVK here when Vulkan gets added } if (!lwjglNatives) { throw new IllegalStateException("Unsupported OS") } return lwjglNatives }