π¦ SmartPub - Flutter Dependency Analyzer
The smart way to manage Flutter dependencies.
SmartPub is a CLI tool for Flutter & Dart projects that helps you identify unused dependencies and organize your pubspec.yaml in a clean, predictable way.
Over time, Flutter projects often accumulate unused or poorly organized packages. SmartPub makes it easy to preview, clean, and categorize dependencies without risking accidental changes.
π€ Why SmartPub?
In real Flutter projects:
- Unused packages increase build time and maintenance cost
pubspec.yamlbecomes hard to read as dependencies grow- Developers hesitate to clean dependencies due to fear of breaking the app
SmartPub solves this by:
- Detecting unused dependencies safely
- Providing preview-first workflows
- Offering interactive modes before making changes
- Keeping actions explicit and predictable
No magic. No hidden behavior.
β¨ What SmartPub Does
SmartPub focuses on three core features:
1οΈβ£ Unused, Misplaced & Missing Dependency Detection
- Scans your project source code (
lib/,test/,bin/,tool/) - Detects unused dependencies declared in
pubspec.yaml - Identifies misplaced dependencies:
- Over-promoted: Packages only used in tests/tools but declared under
dependencies. - Under-promoted: Packages used in core library files but declared under
dev_dependencies(which can break downstream consumers).
- Over-promoted: Packages only used in tests/tools but declared under
- Identifies missing dependencies: Packages used in code but not declared in
pubspec.yaml. - Allows preview before removal or relocation (missing dependency reporting is read-only)
- Supports interactive confirmation for cleanups
2οΈβ£ Dependency Categorization (beta)
Powered by FlutterGems
- Groups dependencies into logical categories
- Uses known ecosystem data
- Supports preview, auto-apply, and interactive overrides
3οΈβ£ Persistent Configuration (smartpub.yaml)
- Exclude specific directories/files from scanning (using globs like
lib/generated/**) - Ignore specific packages from analysis (e.g. code generators like
build_runner) - Fine-tune active checking parameters (toggling unused or promotions checks)
π Installation & Setup
1. Install Globally
Activate SmartPub globally using Dart's pub tool:
dart pub global activate smartpub
Make sure Dartβs global bin is added to your system's PATH.
2. Initialize Configuration
Initialize the configuration file smartpub.yaml in your project root directory:
smartpub init
This generates a starter configuration template with detailed comments to customize rules for your project (ignored packages, path exclusions, etc.).
3. Run Analysis
Run SmartPub to preview dependency violations:
smartpub check
(Or simply run smartpub as a shortcut).
π§ Usage Overview
smartpub [command] [options]
If no command is provided, SmartPub runs in preview mode (equivalent to smartpub check).
π Commands
check (default)
Preview unused dependencies (read-only).
smartpub
smartpub check
β No files are modified.
clean
Remove unused dependencies.
smartpub clean
Interactive cleanup
Review each removal before applying changes.
smartpub clean --interactive
A backup of pubspec.yaml is created automatically.
group
Preview dependency categorization.
smartpub group
Apply categorization automatically
smartpub group --apply
Interactive categorization
Override suggested categories interactively.
smartpub group --interactive
This is useful when you want full control over how packages are grouped.
init
Initialize a default, fully documented smartpub.yaml configuration file.
smartpub init
- Prevents overwriting if
smartpub.yamlalready exists.
restore
Restore pubspec.yaml from the last backup.
smartpub restore
update
Update SmartPub to the latest version.
smartpub update
βοΈ Options
--apply Apply changes automatically
--interactive Review and confirm changes interactively
--no-fail-on-violations Exit 0 even when violations are found (warn-only mode)
--no-color Disable colored output (CI-friendly)
--config <path> Path to custom config file (default: smartpub.yaml)
-h, --help Show help information
-v, --version Show version information
ποΈ CI Integration & Exit Codes
SmartPub returns standard exit codes so you can use it as a blocking gate in your pipelines (GitHub Actions, GitLab CI, Bitrise).
| Exit Code | Meaning |
|---|---|
0 |
Success: No violations found (or they were successfully cleaned). |
1 |
Violations Detected: Unused or misplaced dependencies found. |
2 |
Tool Error: Missing pubspec.yaml, no backup exists, or parse error. |
3 |
Invalid Arguments: Unknown flags or incompatible options passed. |
Example GitHub Action (Fail on violations)
- name: Check for unused dependencies
run: dart run smartpub check
Example CI Migration (Warn-only mode)
If you want to integrate SmartPub into CI but aren't ready to fail the build yet, use:
smartpub check --no-fail-on-violations
This will print all violations but safely exit 0.
π§ͺ Typical Workflow
A safe and recommended workflow:
smartpub # preview unused dependencies
smartpub clean # remove unused dependencies
smartpub group # preview categorization
smartpub group --interactive
This keeps changes intentional and reviewable.
π‘οΈ Safety Guarantees
- SmartPub never modifies files without intent
- Preview is the default behavior
- Backups are created before changes
- Interactive mode is available for sensitive operations
π¦ Project Scope (Important)
SmartPub intentionally does not:
- Modify versions automatically
- Upgrade or downgrade dependencies
- Guess architectural intent
Its goal is clarity and cleanliness, not automation overload.
π Support
- π GitHub
- π Report Issues
- π‘ Feature Requests
Made with β€οΈ by Vatsal Jaganwala
Libraries
- categorization/categorization
- SmartPub Categorization
- categorization/gems_integration
- Package Categorization Integration
- categorization/grouping_service
- Package Grouping Service
- categorization/models/grouped_dependencies
- Grouped dependencies model
- categorization/models/package_category
- Package category model
- categorization/models/package_suggestion
- Package suggestion model
- categorization/services/api_service
- API service for package categories from SmartPub Worker
- categorization/services/cache_service
- Local cache service for package categories
- categorization/services/package_categorizer
- Simple package categorization service
- categorization/suggestion_service
- Package Suggestion Service
- core/analyzer
- SmartPub Dependency Analyzer
- core/config
- SmartPub Configuration
- core/core
- Core SmartPub functionality
- core/models/dependency_info
- Dependency Information Model
- core/models/smartpub_config
- core/strings
- String Constants
- services/apply_service
- Apply Service
- services/backup_service
- Safety Backup Service
- services/pubspec_manager
- Pubspec Manager
- services/services
- SmartPub Services
- services/update_checker
- Update Checker Service
- smartpub
- SmartPub - Flutter Dependency Analyzer
- telemetry/telemetry
- SmartPub Telemetry
- telemetry/telemetry_service
- Telemetry Service
- ui/cli_output
- CLI Output Formatter
- ui/interactive_grouping_service
- Interactive Grouping Service
- ui/interactive_service
- Interactive Service
- ui/loader
- ui/ui
- SmartPub User Interface