{"record":{"id":"eae4764f07ba9e4f","repo":"gradle/gradle","slug":"debug-mode-is-not-allowed-when-environment-variabl","errorCode":null,"errorMessage":"Debug mode is not allowed when environment variables are specified. Debug mode runs 'in process' but we need to fork a separate process to pass environment variables. To run with debug mode, please remove environment variables.","messagePattern":"Debug mode is not allowed when environment variables are specified\\. Debug mode runs 'in process' but we need to fork a separate process to pass environment variables\\. To run with debug mode, please remove environment variables\\.","errorType":"exception","errorClass":"InvalidRunnerConfigurationException","httpStatus":null,"severity":"error","filePath":"platforms/extensibility/test-kit/src/main/java/org/gradle/testkit/runner/internal/DefaultGradleRunner.java","lineNumber":328,"sourceCode":"\n        if (output != null && !output.isEmpty()) {\n            message.append(lineBreak);\n            message.append(lineBreak);\n            message.append(\"Output:\");\n            message.append(lineBreak);\n            message.append(output);\n        }\n\n        return message.toString();\n    }\n\n    private BuildResult run(Action<GradleExecutionResult> resultVerification) {\n        if (projectDirectory == null) {\n            throw new InvalidRunnerConfigurationException(\"Please specify a project directory before executing the build\");\n        }\n\n        if (environment != null && debug) {\n            throw new InvalidRunnerConfigurationException(\"Debug mode is not allowed when environment variables are specified. \" +\n                \"Debug mode runs 'in process' but we need to fork a separate process to pass environment variables. \" +\n                \"To run with debug mode, please remove environment variables.\");\n        }\n\n        File testKitDir = createTestKitDir(testKitDirProvider);\n\n        GradleProvider effectiveDistribution = gradleProvider == null ? findGradleInstallFromGradleRunner() : gradleProvider;\n\n        List<String> effectiveArguments = new ArrayList<>();\n        Map<String, String> effectiveEnvironment = new HashMap<>();\n\n        if (OperatingSystem.current().isWindows()) {\n            // When using file system watching in Windows tests it becomes harder to delete the project directory,\n            // since file system watching on Windows adds a lock on the watched directory, which is currently the project directory.\n            // After deleting the contents of the watched directory, Gradle will stop watching the directory and release the file lock.\n            // That may require a retry to delete the watched directory.\n            // To avoid those problems for TestKit tests on Windows, we disable file system watching there.\n            effectiveArguments.add(\"-D\" + StartParameterBuildOptions.WatchFileSystemOption.GRADLE_PROPERTY + \"=false\");","sourceCodeStart":310,"sourceCodeEnd":346,"githubUrl":"https://github.com/gradle/gradle/blob/534f27719b66953f95cc907aae7f2c1b12f5482d/platforms/extensibility/test-kit/src/main/java/org/gradle/testkit/runner/internal/DefaultGradleRunner.java#L310-L346","documentation":"Error \"Debug mode is not allowed when environment variables are specified. Debug mode runs 'in process' but we need to fork a separate process to pass environment variables. To run with debug mode, please remove environment variables.\" thrown in gradle/gradle.","triggerScenarios":"Thrown at platforms/extensibility/test-kit/src/main/java/org/gradle/testkit/runner/internal/DefaultGradleRunner.java:328 when the library encounters an invalid state.","commonSituations":"Triggered when withDebug(true) is combined with withEnvironment(...) on GradleRunner. Debug runs the build in-process and cannot propagate custom environment variables; remove the environment variables or disable debug mode.","solutions":["Either remove the environment variables passed via withEnvironment(...) or disable debug mode via withDebug(false); debug mode runs in-process and cannot pass environment variables to a forked process."],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"534f27719b66953f95cc907aae7f2c1b12f5482d","analyzedAt":"2026-08-22T08:09:12.375Z","schemaVersion":2},"datasetVersion":"2026-08-22T09:17:25.309Z"}