-
Notifications
You must be signed in to change notification settings - Fork 237
Description
Description
When working with Gradle-based projects in IntelliJ IDEA, the IDE allows users to define a Project SDK (and a specific Gradle JVM). While IntelliJ's native Gradle integration respects these settings, the NX Console plugin currently does not.
When attempting to run a Gradle task via NX Console (e.g., nx run backend:build), the execution fails if JAVA_HOME is not explicitly set in the system environment or a .env file, even if a valid SDK is configured within IntelliJ.
Steps to reproduce:
- Open an NX workspace with a Gradle-based backend in IntelliJ.
- Set the Project SDK in
File | Project Structure | Project. - Ensure
JAVA_HOMEis not set in your global OS environment. - Run a build task via NX Console.
Observed Behavior:
The execution fails because the environment does not inherit the IDE's SDK setting:
> nx run backend:build
Executing command: gradlew.bat build
ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation.
Expected Behavior:
NX Console should detect the IntelliJ Project SDK (or the configured Gradle JVM) and use it to execute the command, ensuring consistency with the native IntelliJ Gradle runner.
Motivation
- Developer Experience: Significantly speeds up the setup for new employees by reducing the need for manual environment configuration.
- SDK Management: Allows developers to easily switch between different SDKs per project without depending on or polluting global system variables.
- Consistency: Ensures that NX Console behaves as expected within the IntelliJ ecosystem.
Suggested Implementation
The plugin should programmatically retrieve the SDK path from IntelliJ and inject it into the process environment:
- Access the
ProjectRootManagerto identify the current project's SDK. - Preferably, also check the Gradle JVM setting under
Settings | Build, Execution, Deployment | Build Tools | Gradle. - Set the
JAVA_HOMEenvironment variable for the spawned process to the path of the detected JDK.
Alternate Implementations
- Manual Override: Add a setting in NX Console to manually point to a JDK path if the automatic detection fails.
- Environment Sync: A feature to automatically sync the IntelliJ SDK path to a local
.envfile used by NX.