spotless icon indicating copy to clipboard operation
spotless copied to clipboard

Maven Groovy importOrder prevents greclipse from checking and applying

Open Slooz opened this issue 3 years ago • 6 comments

  • [x] Maven Groovy importOrder prevents greclipse from checking and applying
  • [x] maven version: 3.8.1
  • [x] spotless version: 2.12.2
  • [x] operating system and version: macOS Catalina v10.15.7
  • [x] copy-paste your full Spotless configuration block(s):
<plugin>
  <groupId>com.diffplug.spotless</groupId>
  <artifactId>spotless-maven-plugin</artifactId>
  <version>2.12.2</version>
  <executions>
    <execution>
      <goals>
        <goal>check</goal>
      </goals>
    </execution>
  </executions>
  <configuration>
    <java>
      <googleJavaFormat />
    </java>
    <groovy>
      <importOrder />
      <greclipse />
    </groovy>
  </configuration>
</plugin>

Slooz avatar Jul 27 '21 16:07 Slooz

Did you try switching the order? <greclipse /> then <importOrder />?

nedtwigg avatar Jul 27 '21 16:07 nedtwigg

@nedtwigg yes, it only worked after removing <importOrder />

Slooz avatar Jul 27 '21 16:07 Slooz

I'm using gradle, and am encountering quite a few of the following which appear only when using importOrder()

Skipping '/path/to/foo.groovy' because it does not converge However with gradle, the greclipse() reformatting still occurs.

Are you seeing similar warnings caused by <importOrder />? If yes, and you remove those problematic files, does the problem with <greclipse /> disappear?

jayvdb avatar Aug 02 '21 02:08 jayvdb

There were no warnings displayed. This issue didn't seem limited to a few files, but to all of them.

We only use Groovy for our unit tests with Spock, where we use a wildcard import for Spock. Perhaps it sees the wildcard and skips the formatting of the file.

Slooz avatar Aug 02 '21 02:08 Slooz

If you havent already, perhaps try with a basic build.gradle to see if the gradle plugin is emitting warnings caused by importOrder. That will help confirm it is a problem specific to the Maven plugin, and allow confirmation that it is all files or a subset.

plugins {
    id 'com.diffplug.spotless' version '5.14.2'
}

apply plugin: 'groovy'

repositories {
    mavenCentral()
}

sourceSets {
    main {
        groovy {
            srcDir '<your src>'
        }
    }
}

spotless {
    groovy {
        greclipse()
        importOrder()
    }
}

jayvdb avatar Aug 02 '21 02:08 jayvdb

Upon further playing around, I believe this also affects the gradle plugin. It looks like it stops processing greclipse() on the first time it encounters a problem in importOrder(). We are also using wildcard imports.

jayvdb avatar Aug 02 '21 02:08 jayvdb