The Autofix plugin leverages LLM tools to fix code violations in your Java projects running within automated CI/CD pipelines, based on a generated analysis report. Jtest identifies violations, uses LLM integration to propose fixes for those violations, and verifies each proposed fix to ensure that all issues are fully resolved and no new problems are introduced. Successful fixes result in automatically created commits in the working branch of your project source control repository, enabling manual review and approval before merging.
The Jtest Autofix Python script is located in <INSTALL_DIR>/integration/aider.
The following are required to use this functionality:
This feature depends on LLMs, which may produce inaccurate information |
We strongly recommend running the JtestAutoFix.py script inside a Python virtual environment to isolate it from your system-wide Python installation and prevent dependency conflicts.
Follow these steps to set up your virtual environment:
Windows
python -m venv venv |
CALL venv\Scripts\activate.bat |
python -m pip install --upgrade pip pip install -r requirements.txt |
Linux/Unix
python -m venv venv |
source venv/bin/activate |
python -m pip install --upgrade pip pip install -r requirements.txt |
The JtestAutoFix.py script can be configured using environment variables or command-line arguments. Command-line arguments take precedence over environment variables when both are specified.
Below is the complete reference for all available configuration options:
| Option | Required | CLI Argument | Environment Variable | Default Value | Description |
|---|---|---|---|---|---|
| LLM API Key | Yes | N/A | %PROVIDER%_API_KEY=<KEY> | - | Your secret LLM provider API key required by Aider. Replace %PROVIDER% with the provider of your choice. Learn more about providers and variables. |
| Data file | Yes | --data DATA_FILE_PATH | N/A | - | Path to the Jtest .data.json file. It must match the project used for the baseline analysis report. |
| Baseline Report | Yes | --report XML_REPORT_PATH | REPORT=<XML_REPORT_PATH> | - | Path to the Jtest XML report containing violations to be fixed. |
| Tool Home | No | --tool-home JTEST_HOME | TOOL_HOME=<JTEST_HOME> | Jtest directory | Path to the Jtest installation directory. By default, it is set to the "../.." directory where the script is located. |
| Fix Limit | No | --fix-limit COUNT | FIX_LIMIT=<COUNT> | 0 (no limit) | Maximum number of violation fix attempts per run. |
| Max Attempts | No | --max-attempts MAX_ATTEMPTS | N/A | 3 | Maximum retry attempts per violation before stopping. |
| Model Name | No | N/A | MODEL_NAME=MODEL | gpt-4o-mini | AI model for fixing violations (e.g., gpt-4, gpt-4o, claude-3-sonnet). Use aider --list-models <fragment> to see the available models. |
| Weak Model Name | No | N/A | WEAK_MODEL_NAME=MODEL | - | Lightweight model for auxiliary tasks, such as commit message generation. When not specified, it defaults to the specified model name (MODEL_NAME). |
| Verification Command | No | --verification-command COMMAND | N/A | - | Command to verify code integrity after each fix (e.g., "mvn compile" or "./gradlew assemble"). Success is determined by exit code (0 = success). |
| No Source Control | No | --allow-no-source-control | N/A | Disabled | Bypass source control warnings. Use with caution - changes will be made without version control and cannot be reverted. |
| Help | No | -h or --help | N/A | N/A | Display help information for the JtestAutoFix.py script. |
You can use the provided .env.template file as a starting point to create your own .env file with the necessary environment variables.
Before running the Autofix script, we recommend creating a dedicated branch for the automated fixes. This allows you to review and test all changes before merging them into your main branch. |
Windows
SET OPENAI_API_KEY=your_secret_open_ai_key |
python JtestAutoFix.py --report "<PROJECT_PATH>/build/jtest/report.xml" --max-attempts 3 --data "<PROJECT_PATH>/build/jtest/jtest.data.json" --tool-home "C:\Program Files\Parasoft\Jtest\2025.2" |
Linux/Unix
export OPENAI_API_KEY=your_secret_open_ai_key |
python3 JtestAutoFix.py --report "<PROJECT_PATH>/build/jtest/report.xml" --max-attempts 3 --data "<PROJECT_PATH>/build/jtest/jtest.data.json" --tool-home "/opt/parasoft/jtest/2025.2" |
Windows with the Verification Command
SET OPENAI_API_KEY=your_secret_open_ai_key SET MODEL_NAME=gpt-4.1 SET WEAK_MODEL_NAME=gpt-4o-mini |
python JtestAutoFix.py --report "C:\projects\myapp\build\jtest\report.xml" --data "C:\projects\myapp\build\jtest\jtest.data.json" --tool-home "C:\Program Files\Parasoft\Jtest\2025.2" --verification-command "gradle build" --fix-limit 10 --max-attempts 2 |
Linux/Unix with the Verification Command
export OPENAI_API_KEY=your_secret_open_ai_key export MODEL_NAME=gpt-4.1 export WEAK_MODEL_NAME=gpt-4o-mini |
python JtestAutoFix.py --report "/home/user/projects/myapp/build/jtest/report.xml" --data "/home/user/projects/myapp/build/jtest/jtest.data.json" --tool-home "/opt/parasoft/jtest/2025.2" --verification-command "./gradlew build" --fix-limit 10 --max-attempts 2 |
To ensure accurate results and efficient use of the Autofix plugin, follow these best practices: Generate a new baseline after each Autofix session: Code changes made during the autofix process can alter file line numbers and structure, making the violation locations in your original report.xml obsolete. Regenerate your baseline report to ensure it accurately reflects your updated codebase. Fix history tracking: The script creates data files in the Preserve history: To avoid re-attempting the same violations:
|
After each successful fix, the Autofix script creates a commit in your repository. Since AI-generated code may contain errors or suboptimal solutions, it is crucial to review all changes carefully.
Follow these best practices when reviewing AI-generated fixes:
If you encounter any issues while running the script, ensure that:
python3 or python commands.