Dependency Management
This template uses Gradle dependency locking to ensure reproducible builds across different environments and team members.
π¦ Dependency Locking Overview
Dependency locking prevents the βworks on my machineβ problem by:
- Locking exact versions of all transitive dependencies
- Ensuring reproducible builds across environments
- Preventing unexpected version changes during builds
- Providing security through consistent dependency versions
π§ How It Works
Lock Files
The template generates lock files for each module:
βββ gradle.lockfile # Root project locks
βββ service-module/
β βββ gradle.lockfile # Service module locks
βββ springboot-application/
βββ gradle.lockfile # Application module locks
Version Management
All dependency versions are centralized in gradle.properties
:
# Dependency versions
testng_version=7.7.0
mockk_version=1.13.10
h2_version=2.2.224
kotlin_coroutines_version=1.8.0
# Gradle plugin versions
kotlin_version=1.9.25
spring_boot_version=3.5.3
π οΈ Common Commands
Adding New Dependencies
- Add to gradle.properties (if new version):
new_library_version=1.2.3
- Add to module build.gradle:
dependencies {
implementation "com.example:new-library:$new_library_version"
}
- Update locks:
./gradlew resolveAndLockAll --write-locks
Updating Dependencies
# Check for available updates
./gradlew dependencyUpdates
# Update specific version in gradle.properties
# Then regenerate locks
./gradlew resolveAndLockAll --write-locks
Troubleshooting Lock Issues
# If you get "not part of dependency lock state" errors:
./gradlew resolveAndLockAll --write-locks
# To see dependency tree
./gradlew dependencies
# To see specific configuration dependencies
./gradlew :service-module:dependencies --configuration runtimeClasspath
π Dependency Analysis
Security Scanning
# Run OWASP dependency check
./gradlew dependencyCheckAnalyze
# View report at: build/reports/dependency-check-report.html
License Compliance
# Generate license report
./gradlew generateLicenseReport
# View report at: build/reports/dependency-license/
Version Analysis
# Check for outdated dependencies
./gradlew dependencyUpdates
# View report at: build/dependencyUpdates/report.html
π Best Practices
1. Version Management
- β
Use variables in
gradle.properties
for all versions - β Group related versions (e.g., all Spring Boot versions)
- β Document version choices for major dependencies
2. Lock File Management
- β Commit lock files to version control
- β Update locks after any dependency changes
- β Review lock changes in pull requests
3. Security
- β Run security scans regularly
- β Update dependencies promptly for security fixes
- β Monitor vulnerability reports
π¨ Common Issues
Lock State Errors
Problem: Could not resolve all files... not part of dependency lock state
Solution:
./gradlew resolveAndLockAll --write-locks
./gradlew clean build
Version Conflicts
Problem: Different modules requiring different versions
Solution:
- Use
gradle.properties
to enforce consistent versions - Add explicit dependency management in root
build.gradle
- Use
force
in resolution strategy if needed
Plugin Version Issues
Problem: Plugin versions causing conflicts
Solution:
- Update plugin versions in
gradle.properties
- Ensure plugin compatibility
- Check plugin documentation for version requirements
π Dependency Categories
Core Dependencies
// Kotlin essentials
implementation "org.jetbrains.kotlin:kotlin-reflect"
implementation "org.jetbrains.kotlin:kotlin-stdlib"
// Coroutines
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:$kotlin_coroutines_version"
Spring Dependencies
// Spring Boot starters
implementation "org.springframework.boot:spring-boot-starter-web"
implementation "org.springframework.boot:spring-boot-starter-data-jpa"
// Spring validation
implementation "org.springframework.boot:spring-boot-starter-validation"
Testing Dependencies
// Test frameworks
testImplementation "org.testng:testng:$testng_version"
testImplementation "io.mockk:mockk:$mockk_version"
testImplementation "org.springframework.boot:spring-boot-starter-test"
π― Template-Specific Configuration
Automatic Module Discovery
The template uses automatic module discovery in settings.gradle
:
// Auto-include all folders with build.gradle
file(".").listFiles()
.findAll { it.isDirectory() && new File(it, "build.gradle").exists() }
.each { include it.name }
Publishing Configuration
Ready for GitHub Packages publishing:
repositories {
maven {
name = "GitHubPackages"
url = uri("https://maven.pkg.github.com/your-org/your-repo")
credentials {
username = System.getenv("GITHUB_ACTOR")
password = System.getenv("GITHUB_TOKEN")
}
}
}
This ensures your template projects can easily publish to GitHub Packages with proper authentication.