A wrapper that allows the use of the Scalafmt formatter in Maven.
Add the following snippet to your pom, and it will be invoked as part of your build during the
selected lifecycle phase (default validate).
Note: version.scala.binary refers to the major Scala release — currently only 2.13 is supported.
You can also invoke the plugin directly via mvn scalafmt:format.
This plugin follows the following versioning convention:
mvn_scalafmt_(scalaversion)-(major).(minor).(commitepoch).(commithash)
The latest release should be visible at the top of this readme.
<plugin>
<groupId>org.antipathy</groupId>
<artifactId>mvn-scalafmt_${version.scala.binary}</artifactId>
<!-- Version is in the form: (major).(minor).(commitepoch).(commithash)
The Scala version is OMITTED from this value. Find releases at:
https://github.com/simonjpegg/mvn_scalafmt/releases
e.g. <version>1.0.1589620826.41b214a</version>
-->
<version>__DESIRED_MVN_SCALAFMT_VERSION__</version>
<configuration>
<configLocation>${project.basedir}/.scalafmt.conf</configLocation> <!-- path to config -->
</configuration>
<executions>
<execution>
<phase>validate</phase>
<goals>
<goal>format</goal>
</goals>
</execution>
</executions>
</plugin><plugin>
<groupId>org.antipathy</groupId>
<artifactId>mvn-scalafmt_${version.scala.binary}</artifactId>
<!-- Version is in the form: (major).(minor).(commitepoch).(commithash)
The Scala version is OMITTED from this value. Find releases at:
https://github.com/simonjpegg/mvn_scalafmt/releases
e.g. <version>1.0.1589620826.41b214a</version>
-->
<version>__DESIRED_MVN_SCALAFMT_VERSION__</version>
<configuration>
<configLocation>${project.basedir}/.scalafmt.conf</configLocation> <!-- path to config -->
<skipTestSources>false</skipTestSources> <!-- (Optional) skip formatting test sources -->
<skipSources>false</skipSources> <!-- (Optional) skip formatting main sources -->
<sourceDirectories> <!-- (Optional) Paths to source-directories. Overrides ${project.build.sourceDirectory} -->
<param>${project.basedir}/src/main/scala</param>
</sourceDirectories>
<testSourceDirectories> <!-- (Optional) Paths to test-source-directories. Overrides ${project.build.testSourceDirectory} -->
<param>${project.basedir}/src/test/scala</param>
</testSourceDirectories>
<validateOnly>false</validateOnly> <!-- check formatting without changing files -->
<onlyChangedFiles>true</onlyChangedFiles> <!-- only format (staged) files that have been changed from the specified git branch -->
<showReformattedOnly>false</showReformattedOnly> <!-- log only modified files -->
<!-- The git branch to check against.
If branch.startsWith(": "), the value is treated as a command to run
and the output is used as the actual branch name. -->
<branch>: git rev-parse --abbrev-ref HEAD</branch> <!-- the current branch -->
<!-- <branch>master</branch> -->
<useSpecifiedRepositories>false</useSpecifiedRepositories> <!-- use project repositories configuration for scalafmt dynamic loading -->
</configuration>
<executions>
<execution>
<phase>validate</phase> <!-- default -->
<goals>
<goal>format</goal>
</goals>
</execution>
</executions>
</plugin>configLocation can either be a local path (e.g. ${project.basedir}/.scalafmt.conf) or an HTTP URL (e.g. https://raw.githubusercontent.com/jozic/scalafmt-config/master/.scalafmt.conf)
Make sure you have set a version in your .scalafmt.conf:
version = "3.9.6"