Add Maven plugin integration for ExpandWildcardImportsStep with reactor dependency support#5
Add Maven plugin integration for ExpandWildcardImportsStep with reactor dependency support#5
Conversation
Co-authored-by: shitikanth <544054+shitikanth@users.noreply.github.com>
Co-authored-by: shitikanth <544054+shitikanth@users.noreply.github.com>
…le directories Co-authored-by: shitikanth <544054+shitikanth@users.noreply.github.com>
Co-authored-by: shitikanth <544054+shitikanth@users.noreply.github.com>
Co-authored-by: shitikanth <544054+shitikanth@users.noreply.github.com>
…github.com/shitikanth/spotless into copilot/update-test-for-spotless-feature
|
@copilot yes just do that for now |
The test now validates the desired behavior (spotless:apply without mvn install) but is disabled until the implementation supports reactor dependencies via target/classes directories. Co-authored-by: shitikanth <544054+shitikanth@users.noreply.github.com>
Done in ec8ba9a. The multi-module test now removes the Warning Firewall rules blocked me from connecting to one or more addresses (expand for details)I tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
|
|
@copilot Use maven's DependencyResolver api to find the jars/folders to add to classpath for the dependencies |
- Added RepositorySystem and RepositorySystemSession to FormatterStepConfig - Updated configuration chain to pass these through FormatterConfig - Modified ExpandWildcardImports to use resolveDependencies() API - WorkspaceReader in session resolves reactor modules to target/classes - Fallback to project.getArtifacts() if resolution fails - Re-enabled multi-module test Co-authored-by: shitikanth <544054+shitikanth@users.noreply.github.com>
Implemented in 10120ed. Now using Maven's
Warning Firewall rules blocked me from connecting to one or more addresses (expand for details)I tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
|
- Use project.getArtifacts() instead of getDependencies() to include transitives - Add warning message when falling back to non-reactor-aware resolution - Better error handling for dependency resolution failures Co-authored-by: shitikanth <544054+shitikanth@users.noreply.github.com>
- Created getFallbackArtifacts() method to reduce code duplication - Added clarifying comment about System.err usage in FormatterStepFactory Co-authored-by: shitikanth <544054+shitikanth@users.noreply.github.com>
Implements Maven plugin support for
ExpandWildcardImportsStep, already available in lib and Gradle plugin. Transforms wildcard imports (e.g.,import java.util.*) into explicit imports based on actual usage.Implementation
Configuration chain extended to pass Maven APIs:
MavenProject,RepositorySystem, andRepositorySystemSessionfields toFormatterConfigandFormatterStepConfigFormatterFactoryandAbstractSpotlessMojoto propagate these referencesExpandWildcardImportsFormatterStepFactory:getCompileSourceRoots()andgetTestCompileSourceRoots()RepositorySystem.resolveDependencies()API to properly resolve dependenciesWorkspaceReaderinRepositorySystemSessionto resolve reactor modules to theirtarget/classesdirectoriesproject.getArtifacts()with warning message if resolution failstypeSolverClasspathand delegates to existingExpandWildcardImportsStep.create()Integration:
addExpandWildcardImports()method toJavaformatterTesting
Single module test: Verifies wildcard import expansion within a single Maven project ✅
Multi-module test: Validates reactor builds where
appmodule depends oncommonmodule. The test verifies thatspotless:applyworks without requiringmvn installon dependency modules first ✅Technical Details
The implementation leverages Maven's
WorkspaceReaderwhich is automatically configured in theRepositorySystemSessionduring reactor builds. WhenresolveDependencies()is called with the project's already-resolved artifacts (including transitives), the workspace reader maps reactor modules to their output directories (target/classes) instead of looking for JAR files. This enables spotless:apply to work seamlessly in multi-module projects without requiring intermediatemvn installsteps.Usage
Original prompt
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.