Skip to content

Intellij - use SDK Support #3030

@TZanke

Description

@TZanke

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.

IntelliJ Project SDK Setting

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:

  1. Open an NX workspace with a Gradle-based backend in IntelliJ.
  2. Set the Project SDK in File | Project Structure | Project.
  3. Ensure JAVA_HOME is not set in your global OS environment.
  4. 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:

  1. Access the ProjectRootManager to identify the current project's SDK.
  2. Preferably, also check the Gradle JVM setting under Settings | Build, Execution, Deployment | Build Tools | Gradle.
  3. Set the JAVA_HOME environment 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 .env file used by NX.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions