dependency-analyzer
Analyze Maven dependencies in Java projects to find unused, duplicate, or outdated dependencies. Use when user says "analyze dependencies", "find unused deps", "clean pom.xml", "dependency audit", or
SKILL.mdskills/dependency-analyzer/skill.md
GitHubDependency Analyzer Skill
Analyzes Maven project dependencies to identify unused, potentially removable, or problematic dependencies.
When to Use
- "analyze dependencies" / "check dependencies"
- "find unused dependencies" / "clean pom.xml"
- "dependency audit" / "dependency review"
- Before major version upgrades or dependency cleanup
Analysis Strategy
Step 1: Extract all dependencies from pom.xml
Read the pom.xml and list every <dependency> with groupId, artifactId, version, and scope.
Step 2: Classify each dependency
For each dependency, determine its type:
| Type | How to detect | Can be safely removed? |
|---|---|---|
| Directly imported | Has matching import statements in src/main/java or src/test/java |
No - actively used |
| Runtime/Provider | No imports but required at runtime (JDBC drivers, security providers, logging backends, annotation processors) | No - needed at runtime |
| Transitive duplicate | Already pulled in by another dependency | Maybe - verify with mvn dependency:tree |
| Unused | No imports, not a runtime dependency, not referenced anywhere | Yes - candidate for removal |
| Test-only | Only imported in src/test/java but scoped as compile |
Should change scope to test |
Step 3: Search for usage
For each dependency, search for its common packages in the source code:
Search method:
- Identify the base package of the dependency (e.g.,
org.apache.poifor Apache POI) - Search for
import <base-package>in all Java files undersrc/main/javaandsrc/test/java - Also search for annotations, class references, and Spring configuration references
- Check
application*.ymlandapplication*.propertiesfor configuration keys tied to the dependency
Known runtime dependencies that won't have direct imports:
postgresql/ JDBC drivers → used viaspring.datasource.urlconfigspring-boot-starter-*→ pull in auto-configuration, no direct imports neededhibernate-jpamodelgen→ annotation processor, generates code at compile timelombok→ annotation processorbcprov-*/ BouncyCastle → registered as security provider injava.securitylogback-*/slf4j-*→ logging backends, used via SLF4J facadespring-boot-devtools→ development toolingmicrometer-*→ metrics, auto-configured by Spring Boot actuatorjackson-*→ often used transitively via Spring Boot for JSON serialization
Step 4: Generate report
Output a structured report:
## Dependency Analysis Report
### ✅ Actively Used (N dependencies)
- groupId:artifactId — used in X files, example: `com.example.MyClass`
### ⚠️ Scope Mismatch (N dependencies)
- groupId:artifactId — only used in tests but scoped as compile → change to `<scope>test</scope>`
### 🔍 Runtime/Provider (N dependencies)
- groupId:artifactId — no direct imports but required because: [reason]
### ❌ Potentially Unused (N dependencies)
- groupId:artifactId — no imports found, no runtime requirement identified
→ Recommendation: remove and verify compilation + tests pass
### 📦 Managed by BOM/Parent (N dependencies)
- groupId:artifactId — version managed by spring-boot-starter-parent
Step 5: Verification recommendations
For each potentially unused dependency, suggest:
- Remove from pom.xml
- Run
mvn clean compile -DskipTeststo verify compilation - Run
mvn testto verify tests pass - If either fails, the dependency is needed (possibly transitively)
Important Notes
- Never auto-remove dependencies — always present findings and let the user decide
- Spring Boot starters are meta-dependencies that pull in many transitive deps — they rarely have direct imports themselves but are essential
- BOM-managed versions (via
<dependencyManagement>) should be noted but are not candidates for removal from the BOM - Provided scope dependencies (like
servlet-api) are compile-time only and won't be in the final JAR - A dependency with 0 imports is NOT automatically unused — always check runtime requirements
- When in doubt, recommend keeping the dependency and flagging for manual review