Skip to content

Commit a49d75a

Browse files
committed
Improve handling of lwjgl components
1 parent 1a00e96 commit a49d75a

File tree

2 files changed

+69
-44
lines changed

2 files changed

+69
-44
lines changed

build.gradle.kts

Lines changed: 66 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,30 @@ repositories {
3131
maven("https://maven.scijava.org/content/groups/public")
3232
}
3333

34+
// Configuration for lwjgl natives with lenient resolution
35+
val lwjglNativesConfig by configurations.creating {
36+
isCanBeConsumed = false
37+
isCanBeResolved = true
38+
}
39+
40+
// Centralized list of lwjgl modules to avoid duplication
41+
val lwjglModules = listOf(
42+
"", // base lwjgl
43+
"-glfw",
44+
"-jemalloc",
45+
"-opengl",
46+
"-vulkan",
47+
"-openvr",
48+
"-xxhash",
49+
"-remotery",
50+
"-spvc",
51+
"-shaderc",
52+
"-lz4",
53+
"-tinyexr",
54+
"-zstd",
55+
"-jawt", // included for completeness
56+
)
57+
3458
dependencies {
3559
val scijavaParentPomVersion = project.properties["scijavaParentPOMVersion"]
3660
val ktVersion = project.properties["kotlinVersion"]
@@ -133,6 +157,29 @@ dependencies {
133157
implementation("ome:formats-gpl")
134158

135159
implementation("org.mastodon:mastodon:1.0.0-beta-34")
160+
161+
// Add lwjgl platform-specific natives as runtime dependencies
162+
// Using a custom configuration with lenient resolution to skip missing artifacts
163+
val lwjglVersion = "3.3.6"
164+
165+
lwjglNatives.forEach { nativePlatform ->
166+
lwjglModules.forEach { lwjglProject ->
167+
// Add to custom config; missing artifacts will be silently skipped
168+
lwjglNativesConfig(group = "org.lwjgl", name = "lwjgl$lwjglProject", version = lwjglVersion) {
169+
artifact {
170+
name = "lwjgl$lwjglProject"
171+
type = "jar"
172+
classifier = nativePlatform
173+
}
174+
isTransitive = false
175+
}
176+
}
177+
}
178+
179+
// Also add the successfully resolved lwjgl natives to runtimeClasspath
180+
configurations.named("runtimeClasspath") {
181+
extendsFrom(lwjglNativesConfig)
182+
}
136183
}
137184

138185
//kapt {
@@ -208,23 +255,7 @@ tasks {
208255

209256
// lwjgl natives
210257
lwjglNatives.forEach { nativePlatform ->
211-
listOf(
212-
"",
213-
"-glfw",
214-
"-jemalloc",
215-
"-opengl",
216-
"-vulkan",
217-
"-openvr",
218-
"-xxhash",
219-
"-remotery",
220-
"-spvc",
221-
"-shaderc",
222-
).forEach project@ { lwjglProject ->
223-
// Vulkan natives only exist for macOS
224-
if(lwjglProject.endsWith("vulkan") && nativePlatform != "macos") {
225-
return@project
226-
}
227-
258+
lwjglModules.forEach { lwjglProject ->
228259
val dependencyNode = dependenciesNode.appendNode("dependency")
229260
dependencyNode.appendNode("groupId", "org.lwjgl")
230261
dependencyNode.appendNode("artifactId", "lwjgl$lwjglProject")
@@ -252,32 +283,23 @@ tasks {
252283
// add bigvolumeviewer version
253284
propertiesNode.appendNode("bigvolumeviewer.version", "0.3.3")
254285

255-
val versionedArtifacts = listOf("scenery",
256-
"flatlaf",
257-
"kotlin-stdlib-common",
258-
"kotlin-stdlib",
259-
"kotlinx-coroutines-core",
260-
"pom-scijava",
261-
"lwjgl-bom",
262-
"imagej-mesh",
263-
"jackson-module-kotlin",
264-
"jackson-dataformat-yaml",
265-
"jackson-dataformat-msgpack",
266-
"jogl-all",
267-
"jna-platform",
268-
"kotlin-bom",
269-
"lwjgl",
270-
"lwjgl-glfw",
271-
"lwjgl-jemalloc",
272-
"lwjgl-vulkan",
273-
"lwjgl-opengl",
274-
"lwjgl-openvr",
275-
"lwjgl-xxhash",
276-
"lwjgl-remotery",
277-
"lwjgl-spvc",
278-
"lwjgl-shaderc",
279-
"lwjgl-jawt",
280-
"log4j-1.2-api")
286+
val versionedArtifacts = listOf(
287+
"scenery",
288+
"flatlaf",
289+
"kotlin-stdlib-common",
290+
"kotlin-stdlib",
291+
"kotlinx-coroutines-core",
292+
"pom-scijava",
293+
"lwjgl-bom",
294+
"imagej-mesh",
295+
"jackson-module-kotlin",
296+
"jackson-dataformat-yaml",
297+
"jackson-dataformat-msgpack",
298+
"jogl-all",
299+
"jna-platform",
300+
"kotlin-bom",
301+
"log4j-1.2-api"
302+
) + lwjglModules.map { "lwjgl$it" }
281303

282304
val toSkip = listOf("pom-scijava")
283305

@@ -479,4 +501,4 @@ java.withSourcesJar()
479501
//extensions.findByName("buildScan")?.withGroovyBuilder {
480502
// setProperty("termsOfServiceUrl", "https://gradle.com/terms-of-service")
481503
// setProperty("termsOfServiceAgree", "yes")
482-
//}
504+
//}

buildSrc/src/main/kotlin/sciview/fiji.gradle.kts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,10 @@ private fun populate() {
209209
val testLibraries = setOf("hamcrest-core", "junit", "kotlin-test-junit", "kotlin-test", "slf4j-simple")
210210
// Exclude 32-bit artifacts since Fiji no longer supports x86-32 platforms
211211
val exclude32Bit = setOf("i686", "i586", "x86-32")
212+
213+
// Use lenient resolution for runtimeClasspath to skip missing lwjgl natives
212214
val runtimeClasspath = configurations.named("runtimeClasspath").get()
215+
.resolvedConfiguration.lenientConfiguration.files
213216

214217
// Copy main artifact.
215218
val mainJar = project.tasks.getByName("jar").outputs.files.singleFile

0 commit comments

Comments
 (0)