You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

190 lines
3.5 KiB
Markdown

---
name: analyze-dependencies
description: Analyze Java class dependencies, JAR requirements, and import relationships. Use when user needs to map dependencies, find missing libraries, or understand code relationships.
version: 1.0.0
---
# Dependency Analysis
This skill analyzes Java project dependencies and relationships.
## When to Use
- User needs to find required JAR files
- User wants to understand class relationships
- User needs to identify missing dependencies
- User wants to map import dependencies
## Analysis Types
### 1. Import Analysis
Extract and analyze imports:
```bash
# Get all imports
find <dir> -name "*.java" -exec grep "^import" {} \; | \
sed 's/import //' | \
sed 's/;.*//' | \
sort -u
# Count imports per file
find <dir> -name "*.java" -exec sh -c 'echo "$(grep -c "^import" "$1") $1"' _ {} \; | \
sort -rn
```
### 2. External Dependency Detection
Identify required libraries:
```bash
# Find external imports (non-project)
find <dir> -name "*.java" -exec grep "^import" {} \; | \
sed 's/import //' | \
sed 's/;.*//' | \
grep -v "^com\.hst\." | \
sort -u
```
### 3. JAR Dependency Mapping
Map imports to JAR files:
| Import Pattern | Likely JAR |
|----------------|------------|
| `org.springframework.*` | spring-*.jar |
| `org.apache.struts.*` | struts2-core.jar |
| `com.ibatis.*` | ibatis-sqlmap.jar |
| `org.apache.axis.*` | axis.jar |
| `javax.servlet.*` | servlet-api.jar |
| `org.apache.log4j.*` | log4j.jar |
| `java.sql.*` | JDK (built-in) |
### 4. Class Relationship Analysis
Find related classes:
```bash
# Find classes that extend/implement
grep -r "extends\|implements" <dir> | \
sed 's/:.*extends/: extends/' | \
sed 's/:.*implements/: implements/'
# Find interface implementations
grep -r "implements" <dir> | \
sed 's/.*implements //' | \
sed 's/{.*//' | \
sort -u
```
## Dependency Report
Generate comprehensive report:
```bash
bash C:/Users/K/.claude/plugins/cache/claude-plugins-official/plugin-dev/9eae436aa296/scripts/analyze-deps.sh <classes_dir>
```
## Resolving Dependencies
### Step 1: Identify Missing JARs
```bash
# List required external packages
find <dir> -name "*.java" -exec grep "^import" {} \; | \
sed 's/import //' | \
sed 's/;.*//' | \
cut -d. -f1-3 | \
sort -u
```
### Step 2: Find JAR Sources
Common sources:
- Maven Central: https://search.maven.org/
- MVN Repository: https://mvnrepository.com/
- Project lib/ directory
### Step 3: Add to Build
For Maven, add to pom.xml:
```xml
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>3.2.18.RELEASE</version>
</dependency>
```
### Step 4: Verify Dependencies
```bash
# Check if JARs are available
mvn dependency:tree
# Download dependencies
mvn dependency:resolve
```
## Common Dependency Groups
### Spring Framework
```
spring-context
spring-web
spring-jdbc
spring-beans
spring-core
```
### Struts 2
```
struts2-core
struts2-spring-plugin
xwork-core
ognl
freemarker
```
### Database
```
ojdbc14 (Oracle)
mysql-connector-java (MySQL)
postgresql (PostgreSQL)
commons-dbcp (Connection pooling)
```
### Web Services
```
axis
jaxrpc-api
wsdl4j
commons-discovery
```
## Dependency Graph
Visualize dependencies:
```
[Action Layer]
[Service Layer]
[DAO Layer]
[Domain Layer]
[External Libraries]
```
## Integration
After dependency analysis:
1. Update pom.xml with missing dependencies
2. Run `mvn dependency:resolve` to download
3. Run `mvn compile` to verify
4. Fix any remaining dependency issues