This is the analysis component of DependaCharta that analyzes source code and generates dependency graphs.
With mise (recommended): Run mise install from the repository root to get the correct Java version automatically.
Manual: Java 17 or higher (check with java -version)
- Clone the repository
- Download the gradle dependencies of the
analysisproject - Run
./gradlew fatJarin theanalysisproject - Run
java -jar analysis/build/libs/dependacharta.jar
- Navigate to
analysis/bin - On Windows, run the
dependacharta.batscript - On Mac/Linux, run the
dependacharta.shscript
For users who prefer containerized execution:
# From the analysis directory
docker build -t dependacharta-analysis .
# For multi-platform support (ARM64/AMD64)
docker buildx build --platform linux/amd64,linux/arm64 -t dependacharta-analysis .# Basic usage - analyze a project
docker run --rm -v /path/to/your/project:/workspace dependacharta-analysis -d /workspace
# With custom output directory
docker run --rm -v /path/to/your/project:/workspace -v /path/to/output:/output dependacharta-analysis -d /workspace -o /output
# View help
docker run --rm dependacharta-analysis --helpThe Docker image includes all necessary dependencies and Tree-sitter parsers, making it ideal for CI/CD pipelines or environments where Java installation is not desired.
-dor--directory: The path to the project you want to analyze
-oor--outputDirectory: The path to the output directory, relative to the current directory (default:output)-for--filename: The output filename without the file extension.cg.json(default:analysis)-cor--clean: Deletes the temporary directory before starting the analysis, forcing a new analysis (default:false)-hor--help: Shows the help message-vor--version: Shows the version of the tool-lor--logLevel: Define the log level for STDOUT. Possible values are debug, info, warn, error, fatal. Independent of this setting the log file will always contain all levels.-sor--max-file-size: Skip files larger than this size in KB (default:1024). Set to0to disable the limit.-tor--file-timeout: Per-file analysis timeout in seconds (default:60). Set to0to disable the timeout.-xor--exclude-dir: Additional directory names to exclude (comma-separated), added to defaults.-Xor--exclude-suffix: Additional file suffixes to exclude (comma-separated), added to defaults.--no-default-excludes: Disable all default directory and suffix exclusions.
- The analysis can take a long time for large projects. If an analysis is stopped midway, you can continue it by running the same command again.
- During the analysis, a directory named
dependacharta_tempis created in the current directory. This directory is used to store temporary files and will be deleted after the analysis is finished. Do not delete it during a running analysis! - If a previous analysis was interrupted, you can clean up temporary files with
mise run clean-tempfrom the repository root.
- The result is a
.cg.jsonfile that can be used in the visualization tool - Important: The output file is always named
[filename].cg.json(note the.cg.jsonextension, not just.json) - It is located in
[outputDirectory]/[filename].cg.json - Example:
-f my-analysis -o outputcreatesoutput/my-analysis.cg.json
cd analysis
./gradlew build # Build and test
./gradlew build -x test # Build without tests
./gradlew ktlintFormat # Auto-format codeThe build creates two JAR files in build/libs/:
dependacharta.jar- Fat JAR (includes all dependencies, ~15MB)dependacharta-analysis.jar- Thin JAR (no dependencies, ~600KB)
Always use the fat JAR (dependacharta.jar) for distribution and running the tool. The thin JAR won't work standalone because it's missing the required libraries.
After making code changes, copy the fat JAR to bin/:
cd analysis
./gradlew clean build -x test
cp build/libs/dependacharta.jar bin/dependacharta.jarAfter modifying the output format, regenerate the example .cg.json files:
# Java example (used by visualization tests)
java -jar analysis/bin/dependacharta.jar \
-d analysis/src/test/resources/analysis/contract/examples/java \
-f java-example \
-o visualization/public/resources \
-c
# Go example
java -jar analysis/bin/dependacharta.jar \
-d exampleProjects/GoExample \
-f go-example \
-o visualization/public/resources \
-c
# Test expectations file
java -jar analysis/bin/dependacharta.jar \
-d analysis/src/test/resources/analysis/contract/examples/java \
-f java-example \
-o analysis/src/test/resources/pipeline/projectreport \
-cNote: The -c flag clears the temporary analysis cache, forcing a fresh analysis.
When adding a new field to the .cg.json output:
- Update data model in
ProjectReportDto.kt - Configure JSON serialization in
ExportService.kt:private val json = Json { prettyPrint = true encodeDefaults = true // Required for fields with default values }
- Update calculation logic where edges/nodes are created
- Update tests and regenerate test expectations
- Rebuild JAR and regenerate example files (see above)
- Ensure
encodeDefaults = trueinExportService.kt - Check that fields don't have default values matching the type's default
./gradlew ktlintFormat # Auto-fix formatting- You're using the thin JAR (
dependacharta-analysis.jar) which doesn't include dependencies - Use the fat JAR (
dependacharta.jar) instead
The programming language of your project is not yet supported but you would still like to analyze it?
You can try adding your own language parser, we documented how to do that here
See ADR Log
- Resolve dependencies between the single files of the project
- Find cycles (see Cycle Detection Algorithm)
- Levelize the dependency graph according to the Levelized Structure Map (see Levelization Algorithm)
- Generate the final
cg.jsonoutput file