Troubleshooting Guide
Common issues and solutions when using the Kotlin Multimodule Template.
🔧 Build Issues
Dependency Lock State Errors
Error: Could not resolve all files... not part of dependency lock state
Cause: Dependency locks are out of sync with current dependencies
Solution:
# Regenerate all lock files
./gradlew resolveAndLockAll --write-locks
# Clean and rebuild
./gradlew clean build
Kotlin Compilation Errors
Error: Unresolved reference
or Type mismatch
Common Causes & Solutions:
- Package name mismatch:
- Check package declarations match directory structure
- Verify import statements are correct
- Missing allopen plugin:
- Ensure
kotlin.gradle
includes allopen plugin - Check Spring annotations are in allopen configuration
- Ensure
- Version conflicts:
- Use consistent versions in
gradle.properties
- Check for transitive dependency conflicts
- Use consistent versions in
Spring Boot Issues
Error: No qualifying bean of type
or BeanCreationException
Solutions:
- Component scanning:
@SpringBootApplication(
scanBasePackages = [
"your.package.service",
"your.package.controller"
]
)
- Missing annotations:
@Service // Ensure service classes are annotated
@RestController // Ensure controllers are annotated
- Circular dependencies:
// Use @Lazy annotation to break cycles
@Service
class ServiceA(@Lazy private val serviceB: ServiceB)
🏃 Runtime Issues
Application Won’t Start
Error: Port 8080 was already in use
Solution:
# Change port
export SERVER_PORT=8081
./gradlew :springboot-application:bootRun
# Or in application.yml
server:
port: 8081
Error: Failed to configure a DataSource
Solution:
# For testing with H2
spring:
datasource:
url: jdbc:h2:mem:testdb
driver-class-name: org.h2.Driver
h2:
console:
enabled: true
Transaction Issues
Error: @Transactional
not working
Cause: Kotlin classes are final, Spring can’t create proxies
Solution: Template already includes allopen plugin, but verify:
// In kotlin.gradle
allOpen {
annotations("org.springframework.transaction.annotation.Transactional")
}
🧪 Testing Issues
Test Discovery Problems
Error: Tests not found or not running
Solutions:
- Check test location:
src/test/kotlin/ ← Correct location
src/test/java/ ← Wrong for Kotlin
- TestNG configuration:
// Ensure test classes use TestNG
import org.testng.annotations.Test
@Test
class YourTest {
// Test methods
}
- Test naming:
# Run specific test patterns
./gradlew test --tests "*Test"
./gradlew test --tests "*Integration*"
MockK Issues
Error: MockK
mocks not working
Solution:
@BeforeEach
fun setup() {
MockKAnnotations.init(this) // Initialize mocks
}
// Or use programmatic approach
val mockService = mockk<YourService>()
Spring Test Context Issues
Error: Failed to load ApplicationContext
Solutions:
- Test configuration:
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@TestPropertySource(properties = ["spring.jpa.hibernate.ddl-auto=create-drop"])
class IntegrationTest
- Test profiles:
@ActiveProfiles("test")
class ServiceTest
📦 GitHub Template Issues
Customization Script Failures
Error: Script can’t find files or permissions denied
Solutions:
- Linux/Mac permissions:
chmod +x customize.sh
./customize.sh
- Windows PowerShell execution policy:
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser
./customize.ps1
- Manual customization: If scripts fail, follow the manual steps in Template Setup Guide
GitHub Actions Issues
Error: Workflow failures in forked repositories
Solutions:
- Update repository references:
# In .github/workflows/*.yml
- name: Publish to GitHub Packages
env:
GITHUB_TOKEN: $
- Enable GitHub Packages:
- Go to repository Settings → Actions → General
- Enable “Read and write permissions”
🔍 Debugging Tips
Enable Debug Logging
# In application.yml
logging:
level:
your.package: DEBUG
org.springframework: DEBUG
org.hibernate.SQL: DEBUG
Gradle Debug Information
# Verbose Gradle output
./gradlew build --info --stacktrace
# Debug dependency resolution
./gradlew dependencies --configuration runtimeClasspath
# Check for duplicate classes
./gradlew buildEnvironment
Spring Boot Debugging
# Enable debug mode
./gradlew :springboot-application:bootRun --args='--debug'
# Enable actuator endpoints
# Add to application.yml:
management:
endpoints:
web:
exposure:
include: health,info,beans,env
📊 Performance Issues
Slow Build Times
Solutions:
- Enable Gradle daemon and parallel builds (already configured):
# In gradle.properties
org.gradle.parallel=true
org.gradle.caching=true
org.gradle.configureondemand=true
- Increase memory:
org.gradle.jvmargs=-Xmx4g -XX:MaxMetaspaceSize=512m
Slow Test Execution
Solutions:
- Run test groups separately:
./gradlew test --tests "**/unit/small/**" # Fast tests first
- Parallel test execution:
test {
maxParallelForks = Runtime.runtime.availableProcessors()
}