diff --git a/build.gradle b/build.gradle index 84f2755..f788224 100644 --- a/build.gradle +++ b/build.gradle @@ -210,6 +210,29 @@ task resolveVersion { +/* + * Apply LWJGL logic + */ +apply from: 'build_logic/lwjgl.gradle' + + + +/* + * Copy libraries into build/libs/lib directory, next to Progressia.jar + */ + +task exportLibs(type: Sync) { + description 'Copies runtime libraries into a subdirectory next to the output JAR.' + + jar.dependsOn exportLibs + dependsOn lwjgl_addNativesToRuntimeOnly + + // from defined in configureManifest + into 'build/libs/lib' +} + + + /* * Configure JAR manifest */ @@ -219,11 +242,16 @@ task configureManifest { jar.dependsOn configureManifest dependsOn resolveVersion + dependsOn lwjgl_addNativesToRuntimeOnly doFirst { + def classPath = project.lwjgl.replaceNativesIn(configurations.runtimeClasspath) + + exportLibs.from classPath + jar.manifest.attributes( 'Main-Class': 'ru.windcorp.progressia.client.ProgressiaClientMain', - 'Class-Path': configurations.runtimeClasspath.collect { "lib/${it.name}" } .join(' '), + 'Class-Path': classPath.collect { "lib/${java.net.URLEncoder.encode it.name}" } .join(' '), 'Specification-Title': 'Progressia', @@ -238,28 +266,6 @@ task configureManifest { -/* - * Copy libraries into buil/libs/lib directory, next to Progressia.jar - */ - -task exportLibs(type: Sync) { - description 'Copies runtime libraries into a subdirectory next to the output JAR.' - - jar.dependsOn exportLibs - - from configurations.runtimeClasspath - into 'build/libs/lib' -} - - - -/* - * Apply LWJGL logic - */ -apply from: 'build_logic/lwjgl.gradle' - - - /* * Packaging working directory configuration */ diff --git a/build_logic/lwjgl.gradle b/build_logic/lwjgl.gradle index 06dcc29..e2d84c9 100644 --- a/build_logic/lwjgl.gradle +++ b/build_logic/lwjgl.gradle @@ -13,7 +13,7 @@ lwjgl.version = '3.3.0' * This is filled in by the request* tasks. This is referenced by the addLwjglNatives task. * When empty, current platform is assumed. */ -lwjgl.targets = new HashSet<>() +lwjgl.targets = new HashSet() // LWJGL components. To include org.lwjgl:lwjgl-foobar, add 'foobar' to this list. lwjgl.libraries = [ @@ -43,27 +43,36 @@ switch (OperatingSystem.current()) { break } +configurations { + create 'lwjglNatives' +} + // Declare pure-Java dependencies dependencies { // BOM - implementation platform("org.lwjgl:lwjgl-bom:${lwjgl.version}") + + def bom = platform("org.lwjgl:lwjgl-bom:${lwjgl.version}") + implementation bom + lwjglNatives bom // Core implementation 'org.lwjgl:lwjgl' + // Local natives for core + runtimeOnly "org.lwjgl:lwjgl::natives-${lwjgl.localArch}" // Components - lwjgl.libraries.each { implementation "org.lwjgl:lwjgl-$it" } + lwjgl.libraries.each { lib -> + implementation "org.lwjgl:lwjgl-$lib" + // Local natives for component + runtimeOnly "org.lwjgl:lwjgl-$lib::natives-${lwjgl.localArch}" + } + } /* - * Adds LWJGL native libraries to runtimeOnly configuration + * Adds LWJGL native libraries to lwjglNatives configuration */ task lwjgl_addNativesToRuntimeOnly { - // Make sure runtimeOnly has not been resolved - compileJava.dependsOn lwjgl_addNativesToRuntimeOnly - configureManifest.dependsOn lwjgl_addNativesToRuntimeOnly - exportLibs.dependsOn lwjgl_addNativesToRuntimeOnly - doFirst { if (project.hasProperty('forceTargets')) { try { @@ -87,15 +96,24 @@ task lwjgl_addNativesToRuntimeOnly { dependencies { lwjgl.targets.each { target -> - runtimeOnly "org.lwjgl:lwjgl::natives-$target" + lwjglNatives "org.lwjgl:lwjgl::natives-$target" lwjgl.libraries.each { lib -> - runtimeOnly "org.lwjgl:lwjgl-$lib::natives-$target" + lwjglNatives "org.lwjgl:lwjgl-$lib::natives-$target" } } } } } +// Replaces LWJGL natives in the given configuration with the requested ones +lwjgl.replaceNativesIn = { config -> + new ArrayList().tap { + addAll config + removeIf { it.name ==~ /.*lwjgl.*natives.*/ } + addAll project.configurations.lwjglNatives + } +} + task requestCrossPlatformDependencies { description 'Adds LWJGL natives for all available platforms.'