Fixed dependency detection for external tools

This commit is contained in:
OLEGSHA 2022-01-10 21:19:31 +03:00
parent b18eac44b8
commit 57a86b544e
Signed by: OLEGSHA
GPG Key ID: E57A4B08D64AFF7A
2 changed files with 58 additions and 34 deletions

View File

@ -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 * Configure JAR manifest
*/ */
@ -219,11 +242,16 @@ task configureManifest {
jar.dependsOn configureManifest jar.dependsOn configureManifest
dependsOn resolveVersion dependsOn resolveVersion
dependsOn lwjgl_addNativesToRuntimeOnly
doFirst { doFirst {
def classPath = project.lwjgl.replaceNativesIn(configurations.runtimeClasspath)
exportLibs.from classPath
jar.manifest.attributes( jar.manifest.attributes(
'Main-Class': 'ru.windcorp.progressia.client.ProgressiaClientMain', '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', '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 * Packaging working directory configuration
*/ */

View File

@ -13,7 +13,7 @@ lwjgl.version = '3.3.0'
* This is filled in by the request* tasks. This is referenced by the addLwjglNatives task. * This is filled in by the request* tasks. This is referenced by the addLwjglNatives task.
* When empty, current platform is assumed. * When empty, current platform is assumed.
*/ */
lwjgl.targets = new HashSet<>() lwjgl.targets = new HashSet<String>()
// LWJGL components. To include org.lwjgl:lwjgl-foobar, add 'foobar' to this list. // LWJGL components. To include org.lwjgl:lwjgl-foobar, add 'foobar' to this list.
lwjgl.libraries = [ lwjgl.libraries = [
@ -43,27 +43,36 @@ switch (OperatingSystem.current()) {
break break
} }
configurations {
create 'lwjglNatives'
}
// Declare pure-Java dependencies // Declare pure-Java dependencies
dependencies { dependencies {
// BOM // BOM
implementation platform("org.lwjgl:lwjgl-bom:${lwjgl.version}")
def bom = platform("org.lwjgl:lwjgl-bom:${lwjgl.version}")
implementation bom
lwjglNatives bom
// Core // Core
implementation 'org.lwjgl:lwjgl' implementation 'org.lwjgl:lwjgl'
// Local natives for core
runtimeOnly "org.lwjgl:lwjgl::natives-${lwjgl.localArch}"
// Components // 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 { task lwjgl_addNativesToRuntimeOnly {
// Make sure runtimeOnly has not been resolved
compileJava.dependsOn lwjgl_addNativesToRuntimeOnly
configureManifest.dependsOn lwjgl_addNativesToRuntimeOnly
exportLibs.dependsOn lwjgl_addNativesToRuntimeOnly
doFirst { doFirst {
if (project.hasProperty('forceTargets')) { if (project.hasProperty('forceTargets')) {
try { try {
@ -87,15 +96,24 @@ task lwjgl_addNativesToRuntimeOnly {
dependencies { dependencies {
lwjgl.targets.each { target -> lwjgl.targets.each { target ->
runtimeOnly "org.lwjgl:lwjgl::natives-$target" lwjglNatives "org.lwjgl:lwjgl::natives-$target"
lwjgl.libraries.each { lib -> 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<File>().tap {
addAll config
removeIf { it.name ==~ /.*lwjgl.*natives.*/ }
addAll project.configurations.lwjglNatives
}
}
task requestCrossPlatformDependencies { task requestCrossPlatformDependencies {
description 'Adds LWJGL natives for all available platforms.' description 'Adds LWJGL natives for all available platforms.'