| name | cui-java-cdi |
| description | CDI and Quarkus development standards for CUI projects, including CDI aspects, container configuration, testing, and native optimization |
| allowed-tools | Read, Edit, Write, Bash, Grep, Glob |
CUI Java CDI Skill
Standards and patterns for CDI and Quarkus development in CUI projects. This skill provides comprehensive guidance on CDI dependency injection, Quarkus container configuration, testing practices, and native image optimization.
Workflow
Step 1: Load Foundational Java Patterns
CRITICAL: Load foundational Java development patterns first.
Skill: cui-java-core
The cui-java-core skill provides essential foundational patterns that CDI builds upon, including constructor injection, dependency management, null safety, immutability, exception handling, and modern Java features. These core Java patterns are prerequisites for CDI-specific development.
Step 2: Load Applicable CDI Standards
CRITICAL: Load current CDI standards to use as enforcement criteria.
Always load foundational CDI standards:
Read: standards/cdi-aspects.md Read: standards/cdi-container.mdThese provide core CDI patterns and container configuration always needed for development.
Conditional loading based on context:
If writing CDI tests or integration tests:
Read: standards/cdi-testing.mdIf working with Quarkus native compilation:
Read: standards/quarkus-native.md
Extract key requirements from all loaded standards
Store in working memory for use during task execution
Step 3: Analyze Existing CDI Code
When to Execute: After loading standards
What to Analyze:
Dependency Injection Patterns:
- Verify constructor injection usage (field injection is prohibited)
- Check for proper
@Injectannotation usage - Validate CDI bean scopes (
@ApplicationScoped,@RequestScoped, etc.) - Review producer methods and their scope configurations
CDI Component Structure:
- Identify CDI beans and their dependencies
- Check for circular dependencies
- Verify proper use of
Instance<T>for optional dependencies - Review qualifier usage and ambiguous dependency resolution
Container Configuration (if applicable):
- Review Dockerfile and base image selection
- Verify security hardening (OWASP compliance)
- Check certificate management approach (PEM vs PKCS12)
- Validate health check implementation
Testing Configuration (if testing context):
- Review
@QuarkusTestvs@QuarkusIntegrationTestusage - Check JaCoCo coverage configuration
- Verify test profiles and configuration overrides
- Validate test resource configuration
- Review
Native Optimization (if native context):
- Analyze reflection registration patterns
- Review
@RegisterForReflectionannotations - Check deployment processor configurations
- Identify optimization opportunities
Step 4: Apply CDI Standards to Development Task
When to Execute: During implementation or code review
What to Apply:
Constructor Injection Standard:
- Convert any field injection to constructor injection
- Make injected fields
final - Remove unnecessary
@Injectfor single-constructor beans - Add
@Injectto correct constructor when multiple exist
CDI Scope Selection:
- Apply
@ApplicationScopedfor stateless services - Use
@RequestScopedfor request-specific data - Avoid
@Singletonunless eager initialization required - Validate scope matches lifecycle requirements
- Apply
Producer Method Patterns:
- Use
@Dependentscope for producers that may return null - Ensure normal-scoped producers never return null
- Prefer
Instance<T>overOptional<T>in producers - Implement Null Object pattern when appropriate
- Use
Container Security (if container context):
- Use distroless base image for production
- Implement internal health checks (no curl/wget)
- Configure OWASP security hardening
- Set up PEM certificates with proper permissions
Testing Practices (if testing context):
- Configure JaCoCo for Quarkus correctly
- Use
@QuarkusTestfor CDI injection tests - Use
@QuarkusIntegrationTestfor packaged app tests - Ensure
@{argLine}in Surefire configuration
Native Optimization (if native context):
- Minimize reflection scope to actual needs
- Split deployment processor by reflection requirements
- Use type-safe class references (not strings)
- Remove duplicate annotations after deployment processor registration
Step 5: Verify Implementation Quality
When to Execute: After applying standards
Quality Checks:
CDI Pattern Verification:
- All dependencies use constructor injection
- All injected fields are
final - Proper CDI scopes applied
- No field or setter injection present
- Producer methods follow scope rules
Testing Verification (if testing context):
- JaCoCo properly configured
- Test coverage collected successfully
- Test profiles configured correctly
- All CDI components tested
Container Verification (if container context):
- Distroless base image used
- Security hardening applied
- Health checks implemented correctly
- Certificates configured with proper permissions
Native Optimization Verification (if native context):
- Reflection registration optimized
- Native compilation succeeds
- Tests pass in native mode
- Performance metrics maintained or improved
Compilation and Build:
# Compile the module Task: subagent_type: maven-builder description: Compile module prompt: | Compile module to verify changes. Parameters: - command: clean compile - module: [module-name] CRITICAL: Wait for completion. Fix any compilation errors. # Run tests Task: subagent_type: maven-builder description: Run tests prompt: | Run module tests. Parameters: - command: clean test - module: [module-name] CRITICAL: Wait for completion. Fix any test failures. # Quality verification Task: subagent_type: maven-builder description: Quality verification prompt: | Run pre-commit quality checks. Parameters: - command: -Ppre-commit clean verify -DskipTests - module: [module-name] CRITICAL: Wait for completion. Fix all quality issues. # Final verification Task: subagent_type: maven-builder description: Final verification prompt: | Run final build and install. Parameters: - command: clean install - module: [module-name] CRITICAL: Wait for completion. Ensure all tests and quality checks pass.Native Build (if native context):
# Native compilation Task: subagent_type: maven-builder description: Native build prompt: | Build native executable. Parameters: - command: clean package -Dnative - module: [module-name] CRITICAL: Wait for completion (may take several minutes). Record build time and executable size.
Step 5: Document Changes and Commit
When to Execute: After verification passes
Documentation Updates:
- Update module README if CDI architecture changed
- Document any special configuration requirements
- Note any deviations from standards with rationale
- Include performance metrics if applicable
Commit Standards:
- Follow standard commit message format
- Reference related issues or tasks
- Include "Zero information loss verified" if migrating code
- Add co-authored-by line for Claude Code
Common Patterns and Error Prevention
For detailed CDI patterns and troubleshooting, see the loaded standards files:
- CDI Patterns: Constructor injection, optional dependencies, producer methods - see
standards/cdi-aspects.md - Common Issues: Resolution exceptions, testing problems, native compilation - see
standards/cdi-aspects.mdandstandards/cdi-testing.md - Container Configuration: DevUI, health checks - see
standards/cdi-container.md - Native Optimization: Reflection configuration, build settings - see
standards/quarkus-native.md
Quality Verification
All changes must pass:
- Constructor injection used exclusively
- All injected fields are
final - Proper CDI scopes applied
- Producer methods follow scope rules
- Tests pass with coverage collected
- Quality checks pass (
-Ppre-commit) - Native compilation succeeds (if applicable)
References
- CDI 2.0 Specification: https://docs.oracle.com/javaee/7/tutorial/cdi-basic.htm
- Quarkus CDI Guide: https://quarkus.io/guides/cdi
- Quarkus Testing Guide: https://quarkus.io/guides/getting-started-testing
- Docker Security Best Practices: https://docs.docker.com/develop/security-best-practices/
- Quarkus Native Guide: https://quarkus.io/guides/writing-native-applications-tips