microsoft / vscode-gradle

Manage Gradle Projects, run Gradle tasks and provide better Gradle file authoring experience in VS Code
https://marketplace.visualstudio.com/items?itemName=vscjava.vscode-gradle
MIT License
126 stars 51 forks source link

Working Directory for Gradle Configure is the extension, not the project folder #1616

Open mattjhussey opened 2 days ago

mattjhussey commented 2 days ago

Extension Name: vscode-gradle Extension Version: 3.16.4 (but tested back to 3.7.0) OS Version: Windows 11 VSCode version: 1.93.1

Describe the bug The working directory when configuring a gradle build is incorrect and set to: "c:\Users\.vscode\extensions\vscjava.vscode-gradle-3.16.4\lib. This means that having script that accesses files for capturing versions or running git in the repo fail.

To Reproduce Add a file like this to the root:


plugins {
    alias(libs.plugins.android.application)
    alias(libs.plugins.jetbrains.kotlin.android)
}

android {
    namespace = "things"
    compileSdk = 34

    defaultConfig {
        applicationId = "things"
        minSdk = 21
        targetSdk = 34

        println("Current working directory: ${System.getProperty("user.dir")}")

        versionName = "1.0"
        versionCode = 1
    }

    buildTypes {
        release {
            isMinifyEnabled = false
            proguardFiles(
                getDefaultProguardFile("proguard-android-optimize.txt"),
                "proguard-rules.pro"
            )
        }
    }
    compileOptions {
        sourceCompatibility = JavaVersion.VERSION_1_8
        targetCompatibility = JavaVersion.VERSION_1_8
    }
    kotlinOptions {
        jvmTarget = "1.8"
    }
    buildFeatures {
        viewBinding = true
    }
}

dependencies {

    implementation(libs.androidx.core.ktx)
    implementation(libs.androidx.appcompat)
    implementation(libs.material)
    implementation(libs.androidx.constraintlayout)
    implementation(libs.androidx.navigation.fragment.ktx)
    implementation(libs.androidx.navigation.ui.ktx)
    testImplementation(libs.junit)
    androidTestImplementation(libs.androidx.junit)
    androidTestImplementation(libs.androidx.espresso.core)
}

Expected behavior The working directory should be the working directory of the project. I have tested and this is the behaviour of intellij and the CLI when running the same gradle project.

Screenshots If applicable, add screenshots to help explain your problem.

Output from "Gradle for Java" You can find this by clicking on the "Output" panel, then selecting the "Gradle for Java" channel from the dropdown.

[error] Error getting build for c:\Users\<user>\Documents\workspace\thing: The supplied build action failed with an exception.
[info] Found 0 tasks
[error] [gradle-server] The supplied build action failed with an exception.
[info] Build file changed: c:\Users\<user>\Documents\workspace\thing\app\build.gradle.kts
[debug] Refreshing tasks
[info] Java Home: C:\Program Files\Java\jdk-17.0.5
[info] JVM Args: --add-opens=java.base/java.util=ALL-UNNAMED,--add-opens=java.base/java.lang=ALL-UNNAMED,--add-opens=java.base/java.lang.invoke=ALL-UNNAMED,--add-opens=java.prefs/java.util.prefs=ALL-UNNAMED,--add-exports=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED,--add-exports=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED,--add-opens=java.base/java.nio.charset=ALL-UNNAMED,--add-opens=java.base/java.net=ALL-UNNAMED,--add-opens=java.base/java.util.concurrent.atomic=ALL-UNNAMED,-Xmx2048m,-Dfile.encoding=UTF-8,-Duser.country=GB,-Duser.language=en,-Duser.variant
[info] Gradle User Home: C:\Users\<user>\.gradle
[info] Gradle Version: 8.9
[info] > Configure project :app
Current working directory: c:\Users\<user>\.vscode\extensions\vscjava.vscode-gradle-3.16.4\lib

Does the bug still exist if you disable all other extensions? Yes

Additional context Does not match the standard behaviour of a gradle build.

jdneo commented 1 day ago

Looks like the same issue as https://github.com/microsoft/vscode-gradle/issues/1572