vscode-gradle icon indicating copy to clipboard operation
vscode-gradle copied to clipboard

Support relative paths

Open badsyntax opened this issue 4 years ago • 3 comments

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
  • build.gradle
    • eg def buildNumber = new File("build.num").text.toInteger() + 1)
  • 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>

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.

badsyntax avatar May 05 '20 19:05 badsyntax

Kudos, SonarCloud Quality Gate passed!

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities (and Security Hotspot 0 Security Hotspots to review)
Code Smell A 0 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

sonarcloud[bot] avatar May 05 '20 20:05 sonarcloud[bot]

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.

badsyntax avatar May 06 '20 06:05 badsyntax

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.

badsyntax avatar May 07 '20 06:05 badsyntax