A Spring Boot starter that provides runtime analysis of starter usage in your application. It helps you identify:
- Used starters: Starters with auto-configurations that are actively contributing beans
- Unused starters: Starters included in your dependencies but not contributing any beans
- Indeterminate starters: Starters whose usage status cannot be definitively determined
This is invaluable for optimizing your application's dependencies and reducing bloat.
/actuator/bootusage- Actuator endpoint for runtime usage analysis- Starter Detection - Automatically discovers Spring Boot starters on the classpath
- Auto-Configuration Analysis - Tracks which auto-configurations are active and contributing beans
- Bean Origin Tracking - Identifies which starters contributed which beans
- Usage Policies - Define custom policies to enforce starter usage rules (SPI)
- Multiple Output Formats - JSON endpoint response or Markdown summary files
- Caching - Configurable result caching for performance
<dependency>
<groupId>io.github.dhruv1503</groupId>
<artifactId>boot-usage-spring-boot-starter</artifactId>
<version>1.0.3</version>
</dependency>implementation 'io.github.dhruv1503:boot-usage-spring-boot-starter:1.0.3'Once added to your project, the starter automatically registers an actuator endpoint.
# Get usage analysis
curl http://localhost:8080/actuator/bootusage
# Force cache refresh
curl http://localhost:8080/actuator/bootusage?force=true{
"usedStarters": [
{
"name": "spring-boot-starter-web",
"groupId": "org.springframework.boot",
"artifactId": "spring-boot-starter-web",
"version": "3.3.5",
"status": "USED",
"category": "web"
}
],
"unusedStarters": [
{
"name": "spring-boot-starter-data-redis",
"groupId": "org.springframework.boot",
"artifactId": "spring-boot-starter-data-redis",
"version": "3.3.5",
"status": "UNUSED",
"category": "data"
}
],
"indeterminateStarters": [],
"matchedAutoConfigCount": 45,
"excludedAutoConfigCount": 12
}| Property | Type | Default | Description |
|---|---|---|---|
management.endpoint.bootusage.enabled |
boolean | true |
Enable/disable the bootusage endpoint |
spring.boot.usage.enabled |
boolean | true |
Enable/disable usage analysis |
spring.boot.usage.cache-ttl |
long | 60000 |
Cache TTL in milliseconds |
spring.boot.usage.include-origins |
boolean | false |
Include bean origin information |
spring.boot.usage.include-confidence |
boolean | false |
Include confidence scores |
spring.boot.usage.detect-unused-jars |
boolean | false |
Detect unused JAR files |
spring.boot.usage.markdown-summary |
boolean | false |
Generate Markdown summary file |
spring.boot.usage.output-dir |
String | null |
Directory for output files |
spring.boot.usage.policies-fail-on-violation |
boolean | false |
Fail startup on policy violations |
management:
endpoint:
bootusage:
enabled: true
spring:
boot:
usage:
enabled: true
cache-ttl: 120000
include-origins: true
detect-unused-jars: true
policies-fail-on-violation: falseYou can define custom policies to enforce starter usage rules. Implement the UsagePolicy interface:
import io.github.dhruv1503.bootusage.autoconfigure.UsagePolicy;
import io.github.dhruv1503.bootusage.autoconfigure.StarterUsageAnalyzer.StarterAnalysisResult;
public class NoUnusedStartersPolicy implements UsagePolicy {
@Override
public String getName() {
return "no-unused-starters";
}
@Override
public String getDescription() {
return "Ensures no unused starters are present in the application";
}
@Override
public PolicyResult evaluate(StarterAnalysisResult result) {
if (result.unusedStarters().isEmpty()) {
return PolicyResult.passed("No unused starters detected");
}
return PolicyResult.failed("Found " + result.unusedStarters().size() +
" unused starters: " + result.unusedStarters());
}
}Register your policy via Spring's META-INF/spring.factories or as a bean:
@Bean
public UsagePolicy noUnusedStartersPolicy() {
return new NoUnusedStartersPolicy();
}When spring.boot.usage.policies-fail-on-violation=true, any policy violation will cause application startup to fail.
- Java 17 or later
- Spring Boot 3.2.0 or later
./gradlew clean buildContributions are welcome! Please feel free to submit a Pull Request.
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
This project is licensed under the Apache License 2.0 - see the LICENSE file for details.
This project was inspired by discussions in Spring Boot PR #47023.
- Dhruv Rastogi - dhruv-15-03