Skip to content

Docs (majorScalaVersion) and code (scalaMajorVersion) disagree on scalafmt option #1545

@chriswarbo

Description

@chriswarbo

I tried adding Spotless to my Scala Maven project, based on the following config from the README:

<scalafmt>
  <version>3.5.9</version>              <!-- optional -->
  <file>${project.basedir}/scalafmt.conf</file> <!-- optional -->
  <majorScalaVersion>2.13</majorScalaVersion> <!-- optional -->
</scalafmt>

However, this gives the following error:

> [ERROR] Failed to execute goal com.diffplug.spotless:spotless-maven-plugin:2.31.0:check (default) on project awsutils_2.12: Unable to parse configuration of mojo com.diffplug.spotless:spotless-maven-plugin:2.31.0:check for parameter majorScalaVersion: Cannot find 'majorScalaVersion' in class com.diffplug.spotless.maven.scala.Scalafmt -> [Help 1]

Looking at the sources it seems that option is actually called scalaMajorVersion instead.

Here's the config I eventually got to work:

        <plugin>
          <groupId>com.diffplug.spotless</groupId>
          <artifactId>spotless-maven-plugin</artifactId>
          <version>2.31.0</version>
          <dependencies>
            <dependency>
              <groupId>org.scalameta</groupId>
              <artifactId>scalafmt-core_${scala.compat.version}</artifactId>
              <version>${versions.scalafmt}</version>
            </dependency>
          </dependencies>
          <configuration>
            <scala>
              <scalafmt>
                <version>${versions.scalafmt}</version>
                <file>${scalafmt.conf}</file>
                <scalaMajorVersion>${scala.compat.version}</scalaMajorVersion>
              </scalafmt>
            </scala>
          </configuration>
          <executions>
            <execution>
              <!-- Check formatting; we do this in the package phase, to avoid
                   affecting anyone's edit/compile/test workflow -->
              <goals>
                <goal>check</goal>
              </goals>
              <phase>package</phase>
            </execution>
          </executions>
        </plugin>

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions