All Projects → evis → scalafix-maven-plugin

evis / scalafix-maven-plugin

Licence: BSD-3-Clause License
Enables automatic refactoring and linting of Maven projects written in Scala using Scalafix.

Programming Languages

scala
5932 projects
shell
77523 projects

Projects that are alternatives of or similar to scalafix-maven-plugin

cyclonedx-maven-plugin
Creates CycloneDX Software Bill of Materials (SBOM) from Maven projects
Stars: ✭ 103 (+586.67%)
Mutual labels:  maven, maven-plugin
build-helper-maven-plugin
Build Helper Maven Plugin
Stars: ✭ 77 (+413.33%)
Mutual labels:  maven, maven-plugin
webstart
www.mojohaus.org/webstart/
Stars: ✭ 27 (+80%)
Mutual labels:  maven, maven-plugin
restdocs-spec
A maven plugin for generating Open API and Postman Collection specifications using Spring Restdocs.
Stars: ✭ 43 (+186.67%)
Mutual labels:  maven, maven-plugin
maven-wrapper-plugin
Apache Maven Wrapper Plugin
Stars: ✭ 14 (-6.67%)
Mutual labels:  maven, maven-plugin
jaxws-maven-plugin
www.mojohaus.org/jaxws-maven-plugin/
Stars: ✭ 18 (+20%)
Mutual labels:  maven, maven-plugin
kobby
Kobby is a codegen plugin of Kotlin DSL Client by GraphQL schema. The generated DSL supports execution of complex GraphQL queries, mutation and subscriptions in Kotlin with syntax similar to native GraphQL syntax.
Stars: ✭ 52 (+246.67%)
Mutual labels:  maven, maven-plugin
jcabi-mysql-maven-plugin
MySQL Maven Plugin: starts MySQL server on pre-integration phase and shuts it down on post-integration phase
Stars: ✭ 34 (+126.67%)
Mutual labels:  maven, maven-plugin
wagon-maven-plugin
www.mojohaus.org/wagon-maven-plugin/
Stars: ✭ 23 (+53.33%)
Mutual labels:  maven, maven-plugin
gradle-git-versioning-plugin
This extension will set project version, based on current Git branch or tag.
Stars: ✭ 44 (+193.33%)
Mutual labels:  maven, maven-plugin
impsort-maven-plugin
Java import sorter plugin. Sort your imps!
Stars: ✭ 31 (+106.67%)
Mutual labels:  maven, maven-plugin
xml-maven-plugin
XML Maven Plugin
Stars: ✭ 18 (+20%)
Mutual labels:  maven, maven-plugin
buildnumber-maven-plugin
BuildNumber Maven Plugin
Stars: ✭ 53 (+253.33%)
Mutual labels:  maven, maven-plugin
light-jpf
Lightweight Java Plugin Framework
Stars: ✭ 19 (+26.67%)
Mutual labels:  maven, maven-plugin
mosec-maven-plugin
用于检测maven项目的第三方依赖组件是否存在安全漏洞。
Stars: ✭ 85 (+466.67%)
Mutual labels:  maven, maven-plugin
RapidMavenPushPlugin
A Gradle plugin : Upload Artifacts to Multi Maven Repository
Stars: ✭ 21 (+40%)
Mutual labels:  maven, maven-plugin
dependency-update-maven-plugin
A Maven plugin that creates merge requests for dependency updates.
Stars: ✭ 23 (+53.33%)
Mutual labels:  maven, maven-plugin
ktlint-maven-plugin
Maven plugin for ktlint the Kotlin linter
Stars: ✭ 42 (+180%)
Mutual labels:  maven, maven-plugin
keep-changelog-maven-plugin
Maven plugin to help creating CHANGELOG by keeping one format and solving merge request conflicts problem by extraction of new CHANGELOG entries to seperate files.
Stars: ✭ 22 (+46.67%)
Mutual labels:  maven, maven-plugin
native-build-tools
Native-image plugins for various build tools
Stars: ✭ 168 (+1020%)
Mutual labels:  maven, maven-plugin

scalafix-maven-plugin

scalafix-maven-plugin enables automatic refactoring and linting of Maven projects written in Scala using Scalafix.

Installation

Add plugin into plugins node of pom.xml:

<plugins>
    <plugin>
        <groupId>io.github.evis</groupId>
        <artifactId>scalafix-maven-plugin_2.13</artifactId>
        <version>0.1.6_0.9.33</version>
    </plugin>
</plugins>

Where 0.1.6 is version of the plugin itself, and 0.9.33 is version of Scalafix invoked by the plugin.

Then, you need to setup a file .scalafix.conf in the root directory of your Maven project (note the dot at the start of filename). You can find .scalafix.conf guide here.

In order to execute semantic rules (e.g., RemoveUnused), you need to enable SemanticDB compiler plugin too:

<plugin>
    <groupId>net.alchim31.maven</groupId>
    <artifactId>scala-maven-plugin_${scala.binary.version}</artifactId>
    <version>${scala-maven-plugin.version}</version>
    <executions>
        <execution>
            <goals>
                <goal>compile</goal>
                <goal>testCompile</goal>
            </goals>
        </execution>
    </executions>
    <configuration>
        <args>
            <arg>-Ywarn-unused</arg> <!-- if you need exactly RemoveUnused -->
        </args>
        <compilerPlugins>
            <compilerPlugin>
                <groupId>org.scalameta</groupId>
                <artifactId>semanticdb-scalac_${scala.binary.version}</artifactId>
                <version>${semanticdb.version}</version>
            </compilerPlugin>
        </compilerPlugins>
    </configuration>
</plugin>

You don't need to care about passing Scala version and Scalac options to this plugin specifically. Plugin finds them automatically from your build info.

By default, sources should be located inside src/main/scala directory. Though, you may change it using sourceDirectory configuration option, e.g.:

<plugin>
    <groupId>io.github.evis</groupId>
    <artifactId>scalafix-maven-plugin_2.13</artifactId>
    <version>0.1.6_0.9.33</version>
    <configuration>
        <sourceDirectory>src/main/my-sources-dir</sourceDirectory>
    </configuration>
</plugin>

Usage

There is one Maven goal in this plugin called scalafix:scalafix. It executes Scalafix with given config on your sources.

First of all, you can invoke it via CLI:

mvn scalafix:scalafix

If there are some errors while running Scalafix, then the build will fail. Otherwise, it will succeed.

In order to execute semantic rules (e.g., RemoveUnused), you also need to compile sources beforehand, e.g.:

mvn compile test-compile scalafix:scalafix

You can tweak plugin execution using some parameters, e.g.:

mvn scalafix:scalafix -Dscalafix.mode=CHECK -Dscalafix.skipTest=true

Also, you can pass parameters via pom.xml:

<plugins>
    <plugin>
        <groupId>io.github.evis</groupId>
        <artifactId>scalafix-maven-plugin_2.13</artifactId>
        <version>0.1.6_0.9.33</version>
        <configuration>
            <mode>CHECK</mode>
            <skipTest>true</skipTest>
        </configuration>
    </plugin>
</plugins>

If you want to use external rules, add jars containing rules to dependencies of the plugin:

<plugin>
    <groupId>io.github.evis</groupId>
    <artifactId>scalafix-maven-plugin_2.13</artifactId>
    <version>0.1.6_0.9.33</version>
    <dependencies>
        <dependency>
            <groupId>com.nequissimus</groupId>
            <artifactId>sort-imports_2.13</artifactId>
            <version>0.6.1</version>
        </dependency>
    </dependencies>
</plugin>

Plugin parameters

CLI name Maven configuration name Maven type Description
scalafix.mode mode ScalafixMainMode: either IN_PLACE, CHECK, STDOUT or AUTO_SUPPRESS_LINTER_ERRORS (default: IN_PLACE) Describes mode in which Scalafix runs. Description of different parameter values can be found in Scalafix javadoc.
scalafix.command.line.args commandLineArgs List[String] (default: empty) Custom CLI arguments to pass into Scalafix. Description of available arguments can be found in Scalafix CLI documentation.
scalafix.skip skip Boolean (default: false) Whether we should skip all formatting.
scalafix.skip.main skipMain Boolean (default: false) Whether we should skip formatting of application/library sources (by default located in main/scala).
scalafix.skip.test skipTest Boolean (default: false) Whether we should skip formatting of test sources (by default located in /test/scala).
scalafix.config config File (default: .scalafix.conf) Configuration with rules to invoke for Scalafix.
scalafix.mainSourceDirectories mainSourceDirectories List[File] (default: see below) Which main source directories to format.
scalafix.testSourceDirectories testSourceDirectories List[File] (default: see below) Which test source directories to format.

The plugin determines code paths to process the same way the compiler would; by default, from build.sourceDirectory property, but could be added by another plugin (e.g., build-helper-maven-plugin and scala-maven-plugin have a way to define multiple paths).

If a plugin defines those paths, be sure to invoke mvn with the phase in which that happens; for instance: mvn initialize scalafix:scalafix.

Tips and tricks

  1. scalafix.mode=AUTO_SUPPRESS_LINTER_ERRORS is useful on the first execution of Scalafix: it allows to effectively ignore warnings in existing large codebase.
  2. scalafix.mode=CHECK is convenient to use in continuous integration builds: e.g., to disallow merging code with identified problems.
  3. scalafix.skip=true is especially useful for Maven modules which don't contain Scala sources at all.
  4. scalafix.command.line is great for applying those Scalafix parameters which aren't directly supported by plugin yet.
  5. SemanticDB compiler plugin may slow down compilation a little bit. If you want to use it only for Scalafix, you can make separate Maven profile, e.g.:
<profiles>
    <profile>
        <id>semanticdb</id>
        <build>
            <pluginManagement>
                <plugins>
                    <plugin>
                        <groupId>net.alchim31.maven</groupId>
                        <artifactId>scala-maven-plugin_${scala.binary.version}</artifactId>
                        <version>${scala-maven-plugin.version}</version>
                        <configuration>
                            <compilerPlugins>
                                <compilerPlugin>
                                    <groupId>org.scalameta</groupId>
                                    <artifactId>semanticdb-scalac_${scala.binary.version}</artifactId>
                                    <version>${semanticdb.version}</version>
                                </compilerPlugin>
                            </compilerPlugins>
                        </configuration>
                    </plugin>
                </plugins>
            </pluginManagement>
        </build>
    </profile>
</profiles>

Then, run Scalafix like this:

mvn clean compile test-compile scalafix:scalafix -Psemanticdb

So, when you run compilation with profile turned off, then SemanticDB compiler plugin doesn't affect compilation time at all.

  1. Sometimes it makes sense to make different requirements about main and test code quality. To achieve it you can make separate test config, and invoke plugin twice, e.g.:
mvn clean compile scalafix:scalafix # this invocation uses .scalafix.conf
mvn test-compile scalafix:scalafix -Dscalafix.config=.scalafix.test.conf # means that rules for test code are located in file .scalafix.test.conf

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change. If you need some help with your PR at any time, please feel free to mention @evis.

Support

The best way to get help is to open an issue. You can do it for things like asking questions about the project or requesting technical help.

License

BSD-3-Clause

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].