Eclipse formatters on 2.43.0 does not use correctly maven local repository

Open
#2,329 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
56/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Quiet
Tech stack
java
Domain
build-system

Research direction

Start with plugin-maven/src/main/java/com/diffplug/spotless/maven/java/Eclipse.java at the cacheDirectory reference and AbstractSpotlessMojo.java at the RepositorySystemSession reference. Reproduce with Maven 3.9.9, a settings.xml using a non-default localRepository, and the provided Eclipse formatter configuration. Done means the Eclipse formatter uses the configured repository path rather than the default .m2/repository.

Written by the indexing model from the issue text.

Description

bug

The <eclipse /> step is not respecting localRepository settings in Maven: if you have a <localRepository /> different than Maven default (%USERPROFILE%/.m2/repository on Windows or ${HOME}/.m2/repository on Linux), it tries to create file under the default.

As a technique to avoid having files in .m2/repository, I had created a file in place of a directory in .m2/repository:

# move actual repository
mv ~/.m2/repository ~/.m2/repository_old
# create a file
touch ~/.m2/repository

And then changed the Maven settings.

With this in place, you can see errors because Spotless tries to create a directory .m2/repository/dev which can't work because .m2/repository point to a file (see trace below).

I am under the impression that the problem lies here:

I could create a NTFS junction or a symlink, but on Windows, it is rather inconvenient as I am required to be admin.

Note: to print out the local repository, you can use ./mvnw help:evaluate -Dexpression='session.localRepository.basedir' -N


Settings:

<?xml version="1.0" encoding="UTF-8"?>
<settings xmlns="http://maven.apache.org/SETTINGS/1.2.0"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.2.0 https://maven.apache.org/xsd/settings-1.2.0.xsd">
  <localRepository>E:\some\path\local</localRepository>
  ...
</settings>

Plugin configuration:

        <plugin> <groupId>com.diffplug.spotless</groupId> <artifactId>spotless-maven-plugin</artifactId> <version>2.43.0</version>
          <configuration>
            <java>
              <toggleOffOn />
              <eclipse>
                <!-- <file>${spotless.local.root}/java-formatter.xml</file> -->
              </eclipse>
              <removeUnusedImports />
              <importOrder>
                <order>javax,java,org,com,\#</order>
              </importOrder>
              <formatAnnotations />
            </java>

Error:

java.nio.file.NoSuchFileException: C:\Users\someuser\.m2\repository\dev
    at sun.nio.fs.WindowsException.translateToIOException (WindowsException.java:85)
    at sun.nio.fs.WindowsException.rethrowAsIOException (WindowsException.java:103)
    at sun.nio.fs.WindowsException.rethrowAsIOException (WindowsException.java:108)
    at sun.nio.fs.WindowsFileSystemProvider.createDirectory (WindowsFileSystemProvider.java:527)
    at java.nio.file.Files.createDirectory (Files.java:699)
    at java.nio.file.Files.createAndCheckIsDirectory (Files.java:807)
    at java.nio.file.Files.createDirectories (Files.java:793)
    at dev.equo.solstice.p2.FileMisc.lambda$mkdirs$2 (FileMisc.java:84)
    at dev.equo.solstice.p2.FileMisc.retry (FileMisc.java:101)
    at dev.equo.solstice.p2.FileMisc.retry (FileMisc.java:93)
    at dev.equo.solstice.p2.FileMisc.mkdirs (FileMisc.java:84)
    at dev.equo.solstice.p2.QueryCacheOnDisk.<init> (QueryCacheOnDisk.java:33)
    at dev.equo.solstice.p2.P2Model.query (P2Model.java:129)
    at com.diffplug.spotless.extra.EquoBasedStepBuilder.get (EquoBasedStepBuilder.java:114)
    at com.diffplug.spotless.FormatterStepImpl.calculateState (FormatterStepImpl.java:58)
    at com.diffplug.spotless.LazyForwardingEquality.state (LazyForwardingEquality.java:56)
    at com.diffplug.spotless.LazyForwardingEquality.toBytes (LazyForwardingEquality.java:85)
    at com.diffplug.spotless.LazyForwardingEquality.hashCode (LazyForwardingEquality.java:102)
    at java.util.ArrayList.hashCodeRange (ArrayList.java:677)
    at java.util.ArrayList.hashCode (ArrayList.java:664)
    at com.diffplug.spotless.Formatter.hashCode (Formatter.java:276)
    at java.util.HashMap.hash (HashMap.java:338)
    at java.util.HashMap.put (HashMap.java:618)
    at com.diffplug.spotless.maven.FormattersHolder.create (FormattersHolder.java:43)
    at com.diffplug.spotless.maven.AbstractSpotlessMojo.execute (AbstractSpotlessMojo.java:232)
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo (DefaultBuildPluginManager.java:126)
    at org.apache.maven.lifecycle.internal.MojoExecutor.doExecute2 (MojoExecutor.java:328)
    at org.apache.maven.lifecycle.internal.MojoExecutor.doExecute (MojoExecutor.java:316)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:212)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:174)
    at org.apache.maven.lifecycle.internal.MojoExecutor.access$000 (MojoExecutor.java:75)
    at org.apache.maven.lifecycle.internal.MojoExecutor$1.run (MojoExecutor.java:162)
    at org.apache.maven.plugin.DefaultMojosExecutionStrategy.execute (DefaultMojosExecutionStrategy.java:39)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:159)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:105)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:73)
    at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:53)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:118)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:261)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:173)
    at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:101)
    at org.apache.maven.cli.MavenCli.execute (MavenCli.java:906)
    at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:283)
    at org.apache.maven.cli.MavenCli.main (MavenCli.java:206)
    at jdk.internal.reflect.DirectMethodHandleAccessor.invoke (DirectMethodHandleAccessor.java:103)
    at java.lang.reflect.Method.invoke (Method.java:580)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:255)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:201)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:361)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:314)

Versions:

  • Maven 3.9.9
  • Java 21.0.5 on Windows 10 x64
  • spotless-maven-plugin 2.43.0
Dominant language
Java
Stars
5.7k
Forks
560
Avg merge
1d 13h
Merged PRs (30d)
43

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from diffplug/spotless

All issues in diffplug/spotless

Similar issues

More Java issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.