Skip to content

Commit b66483f

Browse files
authored
Merge pull request #67 from modelix/lib-resolution-without-deployment-descriptor
Support jar resolution without deployment descriptor
2 parents 9d90f2e + 329ff4b commit b66483f

File tree

5 files changed

+32
-10
lines changed

5 files changed

+32
-10
lines changed

build-tools-lib/src/main/kotlin/org/modelix/buildtools/FoundModule.kt

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -112,14 +112,31 @@ class FoundModule(
112112
if (modulePath.isFile) modulePath = modulePath.parentFile
113113
val moduleMacro = "module" to modulePath.toPath()
114114
val marcosWithModule = macros.with(moduleMacro)
115-
result += moduleDescriptor.resolveJavaLibs(marcosWithModule)
116-
.map { it.normalize().toFile() }.filter {
117-
val exists = it.exists()
118-
if (!exists && it.name != "classes" && deploymentDescriptor == null) {
119-
println("File not found: $it, usedBy: $name")
115+
result += moduleDescriptor.javaLibPaths.mapNotNull { javaLibPath ->
116+
val resolvedPath = marcosWithModule.resolve(javaLibPath).normalize()
117+
if (resolvedPath.toFile().exists()) return@mapNotNull resolvedPath.toFile()
118+
119+
if (deploymentDescriptor == null) {
120+
// If the module is packaged inside a jar without a deployment descriptor then the paths may not be
121+
// correct. Try to fix the path.
122+
if (javaLibPath.startsWith("\${module}/")) {
123+
val tail = javaLibPath.substringAfter("\${module}/").replace("../", "").trimStart('/')
124+
var currentParent: File? = modulePath
125+
while (currentParent != null) {
126+
val candidate = currentParent.resolve(tail)
127+
if (candidate.exists()) {
128+
return@mapNotNull candidate
129+
}
130+
currentParent = currentParent.parentFile.takeIf { it != currentParent }
131+
}
132+
}
133+
if (!javaLibPath.endsWith("classes")) {
134+
println("File not found: $javaLibPath, usedBy: $name, modulePath: $modulePath")
120135
}
121-
exists
122136
}
137+
138+
null
139+
}
123140
}
124141
val deploymentDescriptor = deploymentDescriptor
125142
if (deploymentDescriptor != null) {
@@ -130,7 +147,7 @@ class FoundModule(
130147
.map { it.normalize().toFile() }.filter {
131148
val exists = it.exists()
132149
if (!exists) {
133-
println("File not found: $it, usedBy: $name")
150+
println("File not found: $it, usedBy: $name, modulePath: $moduleHome")
134151
}
135152
exists
136153
}

gradle/wrapper/gradle-wrapper.jar

42 Bytes
Binary file not shown.

gradle/wrapper/gradle-wrapper.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
distributionBase=GRADLE_USER_HOME
22
distributionPath=wrapper/dists
3-
distributionUrl=https\://services.gradle.org/distributions/gradle-8.9-bin.zip
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-8.10.2-bin.zip
44
networkTimeout=10000
55
validateDistributionUrl=true
66
zipStoreBase=GRADLE_USER_HOME

gradlew

Lines changed: 5 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

gradlew.bat

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)