Skip to content

Add Maven plugin integration for ExpandWildcardImportsStep with reactor dependency support#5

Draft
Copilot wants to merge 12 commits intomainfrom
copilot/update-test-for-spotless-feature
Draft

Add Maven plugin integration for ExpandWildcardImportsStep with reactor dependency support#5
Copilot wants to merge 12 commits intomainfrom
copilot/update-test-for-spotless-feature

Conversation

Copy link

Copilot AI commented Jan 27, 2026

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:

  • Added MavenProject, RepositorySystem, and RepositorySystemSession fields to FormatterConfig and FormatterStepConfig
  • Updated FormatterFactory and AbstractSpotlessMojo to propagate these references

ExpandWildcardImports FormatterStepFactory:

  • Collects compile and test source roots via getCompileSourceRoots() and getTestCompileSourceRoots()
  • Uses Maven's RepositorySystem.resolveDependencies() API to properly resolve dependencies
  • Leverages WorkspaceReader in RepositorySystemSession to resolve reactor modules to their target/classes directories
  • Includes graceful fallback to project.getArtifacts() with warning message if resolution fails
  • Constructs typeSolverClasspath and delegates to existing ExpandWildcardImportsStep.create()

Integration:

  • Added addExpandWildcardImports() method to Java formatter
  • Documented usage in Maven plugin README

Testing

Single module test: Verifies wildcard import expansion within a single Maven project ✅

Multi-module test: Validates reactor builds where app module depends on common module. The test verifies that spotless:apply works without requiring mvn install on dependency modules first ✅

Technical Details

The implementation leverages Maven's WorkspaceReader which is automatically configured in the RepositorySystemSession during reactor builds. When resolveDependencies() 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 intermediate mvn install steps.

Usage

<java>
  <expandWildcardImports/>
</java>
Original prompt

Continue working on #3

  • progress so far
    • we already first version of the feature
    • we were writing a test to validate the feature on multi-module maven project
    • we wanted to ensure that "spotless:apply" goal works without needing to do a "maven install" first

✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI and others added 7 commits January 24, 2026 03:56
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>
Copilot AI changed the title [WIP] Continue writing tests for multi-module maven project Add Maven plugin integration for ExpandWildcardImportsStep with multi-module test Jan 27, 2026
Copilot AI requested a review from shitikanth January 27, 2026 06:33
@shitikanth
Copy link
Owner

@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>
Copy link
Author

Copilot AI commented Jan 27, 2026

@copilot yes just do that for now

Done in ec8ba9a. The multi-module test now removes the mvn install step and is marked with @Disabled with a detailed explanation of the limitation. The test structure remains in place to validate the desired behavior once reactor dependency support is implemented.

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:

  • archive.eclipse.org
    • Triggering command: /usr/lib/jvm/temurin-17-jdk-amd64/bin/java /usr/lib/jvm/temurin-17-jdk-amd64/bin/java --add-opens=java.base/java.lang=ALL-UNNAMED --add-opens=java.base/java.lang.invoke=ALL-UNNAMED --add-opens=java.base/java.util=ALL-UNNAMED --add-opens=java.prefs/java.util.prefs=ALL-UNNAMED --add-exports=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED --add-exports=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED --add-opens=java.base/java.util=ALL-UNNAMED --add-opens=java.prefs/java.util.prefs=ALL-UNNAMED --add-opens=java.base/java.nio.charset=ALL-UNNAMED --add-opens=java.base/java.net=ALL-UNNAMED --add-opens=java.base/java.util.concurrent=ALL-UNNAMED --add-opens=java.base/java.util.concurrent.atomic=ALL-UNNAMED --add-opens=java.xml/javax.xml.namespace=ALL-UNNAMED --add-opens=java.base/java.time=ALL-UNNAMED -XX:MaxMetaspaceSize=1024m -Xmx4g -Dfile.encoding=UTF-8 -Duser.country -Duser.language=en (dns block)
  • scans-in.gradle.com
    • Triggering command: /usr/lib/jvm/temurin-17-jdk-amd64/bin/java /usr/lib/jvm/temurin-17-jdk-amd64/bin/java --add-opens=java.base/java.lang=ALL-UNNAMED --add-opens=java.base/java.lang.invoke=ALL-UNNAMED --add-opens=java.base/java.util=ALL-UNNAMED --add-opens=java.prefs/java.util.prefs=ALL-UNNAMED --add-exports=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED --add-exports=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED --add-opens=java.base/java.util=ALL-UNNAMED --add-opens=java.prefs/java.util.prefs=ALL-UNNAMED --add-opens=java.base/java.nio.charset=ALL-UNNAMED --add-opens=java.base/java.net=ALL-UNNAMED --add-opens=java.base/java.util.concurrent=ALL-UNNAMED --add-opens=java.base/java.util.concurrent.atomic=ALL-UNNAMED --add-opens=java.xml/javax.xml.namespace=ALL-UNNAMED --add-opens=java.base/java.time=ALL-UNNAMED -XX:MaxMetaspaceSize=1024m -Xmx4g -Dfile.encoding=UTF-8 -Duser.country -Duser.language=en (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

@shitikanth
Copy link
Owner

@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>
Copy link
Author

Copilot AI commented Jan 27, 2026

@copilot Use maven's DependencyResolver api to find the jars/folders to add to classpath for the dependencies

Implemented in 10120ed. Now using Maven's RepositorySystem.resolveDependencies() API which leverages the WorkspaceReader in the RepositorySystemSession to properly resolve reactor module dependencies to their target/classes directories. The implementation includes:

  • Pass RepositorySystem and RepositorySystemSession through the configuration chain
  • Use resolveDependencies() to resolve all project dependencies
  • WorkspaceReader automatically handles reactor modules by returning their output directories
  • Graceful fallback to project.getArtifacts() if resolution fails
  • Re-enabled the multi-module test to validate the behavior

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:

  • archive.eclipse.org
    • Triggering command: /usr/lib/jvm/temurin-17-jdk-amd64/bin/java /usr/lib/jvm/temurin-17-jdk-amd64/bin/java --add-opens=java.base/java.lang=ALL-UNNAMED --add-opens=java.base/java.lang.invoke=ALL-UNNAMED --add-opens=java.base/java.util=ALL-UNNAMED --add-opens=java.prefs/java.util.prefs=ALL-UNNAMED --add-exports=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED --add-exports=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED --add-opens=java.base/java.util=ALL-UNNAMED --add-opens=java.prefs/java.util.prefs=ALL-UNNAMED --add-opens=java.base/java.nio.charset=ALL-UNNAMED --add-opens=java.base/java.net=ALL-UNNAMED --add-opens=java.base/java.util.concurrent=ALL-UNNAMED --add-opens=java.base/java.util.concurrent.atomic=ALL-UNNAMED --add-opens=java.xml/javax.xml.namespace=ALL-UNNAMED --add-opens=java.base/java.time=ALL-UNNAMED -XX:MaxMetaspaceSize=1024m -Xmx4g -Dfile.encoding=UTF-8 -Duser.country -Duser.language=en (dns block)
  • java.sun.com
    • Triggering command: /opt/hostedtoolcache/CodeQL/2.23.9/x64/codeql/tools/linux64/java/bin/java /opt/hostedtoolcache/CodeQL/2.23.9/x64/codeql/tools/linux64/java/bin/java -jar /opt/hostedtoolcache/CodeQL/2.23.9/x64/codeql/xml/tools/xml-extractor.jar --fileList=/home/REDACTED/work/spotless/.codeql-scratch/dbs/java/working/files-to-index729369761720349362.list --sourceArchiveDir=/home/REDACTED/work/spotless/.codeql-scratch/dbs/java/src --outputDir=/home/REDACTED/work/spotless/.codeql-scratch/dbs/java/trap/java git ndor/bin/echo stem iome.java p/bin/grep ls -alF�� /var/lib/waagent grep /usr/bin/grep radle al/FileIndexConf21.0.8&#43;9-LTS cal/bin/grep grep (dns block)
  • scans-in.gradle.com
    • Triggering command: /usr/lib/jvm/temurin-17-jdk-amd64/bin/java /usr/lib/jvm/temurin-17-jdk-amd64/bin/java --add-opens=java.base/java.lang=ALL-UNNAMED --add-opens=java.base/java.lang.invoke=ALL-UNNAMED --add-opens=java.base/java.util=ALL-UNNAMED --add-opens=java.prefs/java.util.prefs=ALL-UNNAMED --add-exports=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED --add-exports=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED --add-opens=java.base/java.util=ALL-UNNAMED --add-opens=java.prefs/java.util.prefs=ALL-UNNAMED --add-opens=java.base/java.nio.charset=ALL-UNNAMED --add-opens=java.base/java.net=ALL-UNNAMED --add-opens=java.base/java.util.concurrent=ALL-UNNAMED --add-opens=java.base/java.util.concurrent.atomic=ALL-UNNAMED --add-opens=java.xml/javax.xml.namespace=ALL-UNNAMED --add-opens=java.base/java.time=ALL-UNNAMED -XX:MaxMetaspaceSize=1024m -Xmx4g -Dfile.encoding=UTF-8 -Duser.country -Duser.language=en (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Copilot AI and others added 2 commits January 27, 2026 08:31
- 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>
Copilot AI changed the title Add Maven plugin integration for ExpandWildcardImportsStep with multi-module test Add Maven plugin integration for ExpandWildcardImportsStep with reactor dependency support Jan 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants