IntelliJ Run/Debug Configuration Portability Between Developer Workstations and CI Agents
0 reputation · 01 Aug 2021, 02:27 UTC
0 reputation · 01 Aug 2021, 02:27 UTC
Goal: ensure that a Run/Debug configuration that launches successfully on a developer’s workstation also executes without modification on a headless CI or production build agent.
The configuration stores absolute file‑system paths, local environment‑variable values and the IDE‑resolved Project SDK in .idea/workspace.xml or per‑run XML files. When these settings are not portable, the CI agent encounters missing directories, undefined variables or a JDK version mismatch, causing silent failures or class‑version errors.
Which subset of run‑configuration settings should be committed to version control to guarantee reproducibility? How can teams enforce that CI agents use the same JDK and working‑directory semantics as the developer IDE without duplicating configuration?
34775 reputation · 01 Aug 2021, 12:56 UTC
Commit only individual run-configuration files under .idea/runConfigurations/, and only after removing absolute paths and hard-coded JDK locations. Do not commit .idea/workspace.xml; it stores machine-specific absolute paths, local environment values, and window layout. Use IDE path macros such as $PROJECT_DIR$ or $MODULE_DIR$ for working directories and file references, and set the SDK to “Use project SDK” or a shared variable such as $JDK_HOME$ that CI resolves through JAVA_HOME.
A configuration that works on a workstation usually embeds absolute paths to the developer’s checkout, local environment variables, and an absolute JDK home. When the same XML is copied to a headless agent, those directories do not exist, variables are undefined, and the referenced JDK may be missing or a different major version. The result is a silent failure, a “directory not found” error, or a class-version mismatch.
.idea/workspace.xml is per-user and non-portable; add it to .gitignore..idea/runConfigurations/ are the subset meant for sharing./Library/Java/JavaVirtualMachines/....Assumes IntelliJ IDEA 2023.x or later with a Git repository. Older editions may store run configurations differently; inspect your .idea directory before generalizing.
$PROJECT_DIR$ or $MODULE_DIR$.JAVA_HOME on both workstation and CI; do not store an absolute JDK path.$PROJECT_DIR$..idea/runConfigurations/<name>.xml..idea/workspace.xml to .gitignore if it is not already ignored.On CI, export JAVA_HOME to the same JDK major version used by developers, then run java -version as a pipeline step. Because the configuration uses $PROJECT_DIR$, the agent resolves the working directory to the checked-out repository root automatically. Document the required JDK version and variable name in the repository README so workstations and agents converge without duplicating the run configuration.
git check-ignore .idea/workspace.xml grep -R -E "/Users|/home|C:" .idea/runConfigurations/ || echo "no absolute paths found" echo "$JAVA_HOME" java -version
If git check-ignore returns exit code 0, workspace.xml is ignored. If grep finds matches, remove those absolute paths before committing.
Does your CI agent execute the IntelliJ run-configuration XML directly, or does it invoke Maven, Gradle, or npm scripts? If CI uses build scripts, the committed XML should document the intended command, but the pipeline should call the build tool directly rather than launching the IDE configuration.
Use comments to ask for clarification. Post a solution as an answer.
34,775 reputation · 01 Aug 2021, 09:56 UTC
In recent IntelliJ versions, shared run configurations are stored as individual XML files under .idea/runConfigurations/, while workspace.xml retains user-specific absolute paths and should remain uncommitted. Teams can check in the runConfigurations directory and let CI resolve the Project SDK by name after setting JAVA_HOME. To verify portability, confirm the committed XML contains only $PROJECT_DIR$ or relative paths, then run java -version on the CI agent to ensure it matches the configured SDK before executing the configuration headless.