vscode-gradle
vscode-gradle copied to clipboard
Support relative paths
Fixes https://github.com/badsyntax/vscode-gradle/issues/245 Refs https://github.com/badsyntax/vscode-gradle/issues/243
This is still a POC.
What do we want?
We want vscode-gradle and vscode-java to support standard gradle builds with relative paths. There are real uses cases for it as reported by the linked issues.
Where are relative paths defined?
Relative paths can be set is various places, including:
- vscode settings
- eg
java.import.gradle.user.home
- eg
-
build.gradle
- eg
def buildNumber = new File("build.num").text.toInteger() + 1
)
- eg
-
gradle.properties
- eg
org.gradle.java.home=../../../../../Library/Java/JavaVirtualMachines/adoptopenjdk-8.jdk/Contents/Home
- eg
org.gradle.jvmargs=-Djavax.net.ssl.trustStore="../../../../modules/Common/security/cacerts" -Djavax.net.ssl.trustStorePassword=<trust-password>
- eg
How do we support relative paths?
In some cases we can normalise paths in the client (eg for vscode settings), but in the other cases we cannot.
The core of the problem is that, when running ./gradlew
from the root of the project, the cwd
that gradle uses is the root of the project, and relative paths work. When running gradle from a server, the cwd
is not the root of the project, and in the case of vscode, is usually an extension directory.
So the fix/workaround, is to start the server from the root of the project, as demonstrated by the POC code in this PR. Think cp.exec('/absolute/path/to/executable', { cwd: projectRoot })
The problem with this approach, is it doesn't support multi-root workspaces.
Kudos, SonarCloud Quality Gate passed!
0 Bugs
0 Vulnerabilities (and
0 Security Hotspots to review)
0 Code Smells
No Coverage information
0.0% Duplication
To support multi-root workspaces, it would be better to set the process cwd
in Java land, before running the gradle process. It looks like gradle reads from user.dir
system property, so try to set that instead.
I'm unable to change cwd
in java land, so I don't have a good fix for this. Will keep this PR open for reference.