Skip to content

Commit 0a092d7

Browse files
committed
use installed gradle instead of gradlew if available as workaround
1 parent ed36c70 commit 0a092d7

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

Plugins/JExtractSwiftPlugin/JExtractSwiftPlugin.swift

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,10 +187,15 @@ struct JExtractSwiftBuildToolPlugin: SwiftJavaPluginProtocol, BuildToolPlugin {
187187
var gradlewEnvironment = ProcessInfo.processInfo.environment
188188
gradlewEnvironment[GradleUserHome] = gradleUserHomePath
189189
log("Forward environment: \(gradlewEnvironment)")
190+
191+
let gradleExecutable = findExecutable(name: "gradle") ?? // try using installed 'gradle' if available in PATH
192+
swiftJavaDirectory.appending(path: "gradlew") // fallback to calling ./gradlew if gradle is not installed
193+
log("Detected 'gradle' executable (or gradlew fallback): \(gradleExecutable)")
194+
190195
commands += [
191196
.buildCommand(
192197
displayName: "Build SwiftKitCore using Gradle (Java)",
193-
executable: swiftJavaDirectory.appending(path: "gradlew"),
198+
executable: gradleExecutable,
194199
arguments: [
195200
":SwiftKitCore:build",
196201
"-p", swiftJavaDirectory.path(percentEncoded: false),
@@ -349,3 +354,19 @@ struct JExtractSwiftBuildToolPlugin: SwiftJavaPluginProtocol, BuildToolPlugin {
349354
}
350355
}
351356

357+
func findExecutable(name: String) -> URL? {
358+
let fileManager = FileManager.default
359+
360+
guard let path = ProcessInfo.processInfo.environment["PATH"] else {
361+
return nil
362+
}
363+
364+
for path in path.split(separator: ":") {
365+
let fullURL = URL(fileURLWithPath: String(path)).appendingPathComponent(name)
366+
if fileManager.isExecutableFile(atPath: fullURL.path) {
367+
return fullURL
368+
}
369+
}
370+
371+
return nil
372+
}

0 commit comments

Comments
 (0)