Trying to run swiftlint through Java subprocess fails (works normally through command line)

88 Views Asked by At

I have a java program to run different kinds of linters, calling the linters as a process using ProcessBuilder. So far, other linters have worked for the most part but with swiftlint, i'm facing a strange issue

When I run it normally from the command line, with

swiftlint --enable-all-rules

It works perfectly, but executing the same through my Java subprocess utility

ProcessBuilder processBuilder = new ProcessBuilder("swfitlint", "--enable-all-rules");
Process process = processBuilder.start();

It fails with the following error message

SourceKittenFramework/library_wrapper.swift:31: Fatal error: Loading libsourcekitdInProc.so failed

At first glance it seems like for some reason certain libraries are not available to the java program which are available to when firing a command through bash, but just to be sure, I tried running the following command through my subprocess util

swiftlint --version

swift --version

Both of which worked, meaning Java does have access to swift binaries installed on my machine. Any help would be appreciated.

1

There are 1 best solutions below

0
On

I'm not still not entirely sure why this happens but i believe it's due to some kind of environment issue on my machine itself. I tried running the same code inside of a docker container that uses the image built from the following base images

FROM openjdk:17-slim as java_base
FROM ghcr.io/realm/swiftlint:latest 
COPY --from=java_base /usr/local/openjdk-17 /usr/local/openjdk-17

and it just worked