{"id":15290813,"url":"https://github.com/evis/scalafix-maven-plugin","last_synced_at":"2025-04-15T16:58:25.620Z","repository":{"id":35455623,"uuid":"194401875","full_name":"evis/scalafix-maven-plugin","owner":"evis","description":"Enables automatic refactoring and linting of Maven projects written in Scala using Scalafix.","archived":false,"fork":false,"pushed_at":"2024-05-28T13:01:56.000Z","size":176,"stargazers_count":24,"open_issues_count":3,"forks_count":12,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-05-29T04:35:10.859Z","etag":null,"topics":["linter","maven","maven-plugin","refactoring","scala","scalafix"],"latest_commit_sha":null,"homepage":"","language":"Scala","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/evis.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-06-29T12:13:00.000Z","updated_at":"2024-06-02T03:22:45.294Z","dependencies_parsed_at":"2023-12-02T21:21:57.570Z","dependency_job_id":"1abec7ce-19c7-4794-8e6f-f5e094301b60","html_url":"https://github.com/evis/scalafix-maven-plugin","commit_stats":null,"previous_names":[],"tags_count":17,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/evis%2Fscalafix-maven-plugin","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/evis%2Fscalafix-maven-plugin/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/evis%2Fscalafix-maven-plugin/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/evis%2Fscalafix-maven-plugin/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/evis","download_url":"https://codeload.github.com/evis/scalafix-maven-plugin/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249116180,"owners_count":21215141,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["linter","maven","maven-plugin","refactoring","scala","scalafix"],"created_at":"2024-09-30T16:09:36.251Z","updated_at":"2025-04-15T16:58:25.607Z","avatar_url":"https://github.com/evis.png","language":"Scala","funding_links":[],"categories":[],"sub_categories":[],"readme":"# scalafix-maven-plugin\n\nscalafix-maven-plugin enables automatic refactoring and linting of Maven projects written in Scala using [Scalafix](https://scalacenter.github.io/scalafix/).\n\n## Installation\n\nAdd plugin into `plugins` node of `pom.xml`:\n\n```xml\n\u003cplugins\u003e\n    \u003cplugin\u003e\n        \u003cgroupId\u003eio.github.evis\u003c/groupId\u003e\n        \u003cartifactId\u003escalafix-maven-plugin_2.13\u003c/artifactId\u003e\n        \u003cversion\u003e0.1.10_0.14.2\u003c/version\u003e\n    \u003c/plugin\u003e\n\u003c/plugins\u003e\n```\n\nWhere `0.1.10` is version of the plugin itself, and `0.14.2` is version of Scalafix invoked by the plugin.\n\nNotes about Scala versions:\n1. It should be OK to use scalafix-maven-plugin_2.13 for Scala 3. Though, if you encounter any problems with such usage, create an issue.\n2. Use scalafix-maven-plugin_2.12 for Scala 2.12, if you need semantic rules.\n3. Scala 2.11 and older aren't supported.\n\nThen, 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](https://scalacenter.github.io/scalafix/docs/users/configuration.html).\n\nYou don't need to care about passing Scala version and Scalac options to this plugin specifically. Plugin finds them automatically from your build info.\n\n### Semantic rules with SemanticDB\n\nIn order to execute semantic rules (e.g., `RemoveUnused`), you need to enable SemanticDB.\n\n\u003cdetails\u003e\n\u003csummary\u003eFor Scala 2, you should add compiler plugin.\u003c/summary\u003e\n\n```xml\n\u003cplugin\u003e\n    \u003cgroupId\u003enet.alchim31.maven\u003c/groupId\u003e\n    \u003cartifactId\u003escala-maven-plugin_${scala.binary.version}\u003c/artifactId\u003e\n    \u003cversion\u003e${scala-maven-plugin.version}\u003c/version\u003e\n    \u003cexecutions\u003e\n        \u003cexecution\u003e\n            \u003cgoals\u003e\n                \u003cgoal\u003ecompile\u003c/goal\u003e\n                \u003cgoal\u003etestCompile\u003c/goal\u003e\n            \u003c/goals\u003e\n        \u003c/execution\u003e\n    \u003c/executions\u003e\n    \u003cconfiguration\u003e\n        \u003cargs\u003e\n            \u003carg\u003e-Ywarn-unused\u003c/arg\u003e \u003c!-- if you need exactly RemoveUnused --\u003e\n        \u003c/args\u003e\n        \u003ccompilerPlugins\u003e\n            \u003ccompilerPlugin\u003e\n                \u003cgroupId\u003eorg.scalameta\u003c/groupId\u003e\n                \u003cartifactId\u003esemanticdb-scalac_${scala.binary.version}\u003c/artifactId\u003e\n                \u003cversion\u003e${semanticdb.version}\u003c/version\u003e\n            \u003c/compilerPlugin\u003e\n        \u003c/compilerPlugins\u003e\n    \u003c/configuration\u003e\n\u003c/plugin\u003e\n```\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\u003csummary\u003eFor Scala 3, you just need to enable it with compiler flag.\u003c/summary\u003e\n\n```xml\n\u003cplugin\u003e\n    \u003cgroupId\u003enet.alchim31.maven\u003c/groupId\u003e\n    \u003cartifactId\u003escala-maven-plugin_${scala.binary.version}\u003c/artifactId\u003e\n    \u003cversion\u003e${scala-maven-plugin.version}\u003c/version\u003e\n    \u003cexecutions\u003e\n        \u003cexecution\u003e\n            \u003cgoals\u003e\n                \u003cgoal\u003ecompile\u003c/goal\u003e\n                \u003cgoal\u003etestCompile\u003c/goal\u003e\n            \u003c/goals\u003e\n        \u003c/execution\u003e\n    \u003c/executions\u003e\n    \u003cconfiguration\u003e\n        \u003cargs\u003e\n            \u003carg\u003e-Ywarn-unused\u003c/arg\u003e \u003c!-- if you need exactly RemoveUnused --\u003e\n            \u003carg\u003e-Ysemanticdb\u003c/arg\u003e\n        \u003c/args\u003e\n    \u003c/configuration\u003e\n\u003c/plugin\u003e\n```\n\u003c/details\u003e\n\n### Overriding sources location\n\nBy default, sources should be located inside `src/main/scala` directory. Though, you may change it using `sourceDirectory` build option, plugin respects this, e.g.:\n\n```xml\n\u003cbuild\u003e\n    \u003csourceDirectory\u003esrc/main/my-sources-dir\u003c/sourceDirectory\u003e\n    \u003c!-- another build settings... --\u003e\n\u003c/build\u003e\n```\n\nOr using `mainSourceDirectories` configuration option of the plugin, e.g.:\n\n```xml\n\u003cplugin\u003e\n    \u003cgroupId\u003eio.github.evis\u003c/groupId\u003e\n    \u003cartifactId\u003escalafix-maven-plugin_2.13\u003c/artifactId\u003e\n    \u003cversion\u003e0.1.10_0.14.2\u003c/version\u003e\n    \u003cconfiguration\u003e\n        \u003cmainSourceDirectories\u003e\n            \u003cdirectory\u003esrc/main/my-sources-dir\u003c/directory\u003e\n            \u003cdirectory\u003esrc/main/my-another-dir\u003c/directory\u003e\n            \u003c!-- and so on, you can list several directories here... --\u003e\n        \u003c/mainSourceDirectories\u003e\n    \u003c/configuration\u003e\n\u003c/plugin\u003e\n```\n\n## Usage\n\nThere is one Maven goal in this plugin called `scalafix:scalafix`. It executes Scalafix with given config on your sources.\n\nFirst of all, you can invoke it via CLI:\n\n```bash\nmvn scalafix:scalafix\n```\n\nIf there are some errors while running Scalafix, then the build will fail. Otherwise, it will succeed.\n\nIn order to execute semantic rules (e.g., `RemoveUnused`), you also need to compile sources beforehand, e.g.:\n\n```bash\nmvn compile test-compile scalafix:scalafix\n```\n\nYou can tweak plugin execution using some parameters, e.g.:\n\n```bash\nmvn scalafix:scalafix -Dscalafix.mode=CHECK -Dscalafix.skipTest=true\n```\n\nAlso, you can pass parameters via `pom.xml`:\n\n```xml\n\u003cplugins\u003e\n    \u003cplugin\u003e\n        \u003cgroupId\u003eio.github.evis\u003c/groupId\u003e\n        \u003cartifactId\u003escalafix-maven-plugin_2.13\u003c/artifactId\u003e\n        \u003cversion\u003e0.1.10_0.14.2\u003c/version\u003e\n        \u003cconfiguration\u003e\n            \u003cmode\u003eCHECK\u003c/mode\u003e\n            \u003cskipTest\u003etrue\u003c/skipTest\u003e\n        \u003c/configuration\u003e\n    \u003c/plugin\u003e\n\u003c/plugins\u003e\n```\n\nIf you want to use external rules, add jars containing rules to dependencies of the plugin:\n\n```xml\n\u003cplugin\u003e\n    \u003cgroupId\u003eio.github.evis\u003c/groupId\u003e\n    \u003cartifactId\u003escalafix-maven-plugin_2.13\u003c/artifactId\u003e\n    \u003cversion\u003e0.1.10_0.14.2\u003c/version\u003e\n    \u003cdependencies\u003e\n        \u003cdependency\u003e\n            \u003cgroupId\u003ecom.nequissimus\u003c/groupId\u003e\n            \u003cartifactId\u003esort-imports_2.13\u003c/artifactId\u003e\n            \u003cversion\u003e0.6.1\u003c/version\u003e\n        \u003c/dependency\u003e\n    \u003c/dependencies\u003e\n\u003c/plugin\u003e\n```\n\n### Plugin parameters\n\nCLI name | Maven configuration name | Maven type | Description\n--- | --- | --- | ---\n`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](https://static.javadoc.io/ch.epfl.scala/scalafix-interfaces/0.11.0/scalafix/interfaces/ScalafixMainMode.html).\n`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](https://scalacenter.github.io/scalafix/docs/users/installation.html#help).\n`scalafix.skip` | `skip` | `Boolean` (default: `false`) | Whether we should skip all formatting.\n`scalafix.skip.main` | `skipMain` | `Boolean` (default: `false`) | Whether we should skip formatting of application/library sources (by default located in `main/scala`).\n`scalafix.skip.test` | `skipTest` | `Boolean` (default: `false`) | Whether we should skip formatting of test sources (by default located in `/test/scala`).\n`scalafix.config` | `config` | `File` (default: `.scalafix.conf`) | Configuration with rules to invoke for Scalafix.\n`scalafix.mainSourceDirectories` | `mainSourceDirectories` | `List[File]` (default: see below) | Which main source directories to format.\n`scalafix.testSourceDirectories` | `testSourceDirectories` | `List[File]` (default: see below) | Which test source directories to format.\n\n\u003e The plugin determines code paths to process the same way the compiler would; by default, from\n\u003e `build.sourceDirectory` property, but could be added by another plugin \n\u003e (e.g., `build-helper-maven-plugin` and `scala-maven-plugin` have a way to define multiple paths).\n\u003e\n\u003e If a plugin defines those paths, be sure to invoke `mvn` with the phase in which that happens;\n\u003e for instance: `mvn initialize scalafix:scalafix`.\n\n### Tips and tricks\n\n1. `scalafix.mode=AUTO_SUPPRESS_LINTER_ERRORS` is useful on the first execution of Scalafix: it allows to effectively ignore warnings in existing large codebase.\n2. `scalafix.mode=CHECK` is convenient to use in continuous integration builds: e.g., to disallow merging code with identified problems.\n3. `scalafix.skip=true` is especially useful for Maven modules which don't contain Scala sources at all.\n4. `scalafix.command.line` is great for applying those Scalafix parameters which aren't directly supported by plugin yet.\n5. 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.:\n\n```xml\n\u003cprofiles\u003e\n    \u003cprofile\u003e\n        \u003cid\u003esemanticdb\u003c/id\u003e\n        \u003cbuild\u003e\n            \u003cpluginManagement\u003e\n                \u003cplugins\u003e\n                    \u003cplugin\u003e\n                        \u003cgroupId\u003enet.alchim31.maven\u003c/groupId\u003e\n                        \u003cartifactId\u003escala-maven-plugin_${scala.binary.version}\u003c/artifactId\u003e\n                        \u003cversion\u003e${scala-maven-plugin.version}\u003c/version\u003e\n                        \u003cconfiguration\u003e\n                            \u003ccompilerPlugins\u003e\n                                \u003ccompilerPlugin\u003e\n                                    \u003cgroupId\u003eorg.scalameta\u003c/groupId\u003e\n                                    \u003cartifactId\u003esemanticdb-scalac_${scala.binary.version}\u003c/artifactId\u003e\n                                    \u003cversion\u003e${semanticdb.version}\u003c/version\u003e\n                                \u003c/compilerPlugin\u003e\n                            \u003c/compilerPlugins\u003e\n                        \u003c/configuration\u003e\n                    \u003c/plugin\u003e\n                \u003c/plugins\u003e\n            \u003c/pluginManagement\u003e\n        \u003c/build\u003e\n    \u003c/profile\u003e\n\u003c/profiles\u003e\n```\n\nThen, run Scalafix like this:\n\n```bash\nmvn clean compile test-compile scalafix:scalafix -Psemanticdb\n```\n\nSo, when you run compilation with profile turned off, then SemanticDB compiler plugin doesn't affect compilation time at all.\n\n6. 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.:\n\n```bash\nmvn clean compile scalafix:scalafix # this invocation uses .scalafix.conf\nmvn test-compile scalafix:scalafix -Dscalafix.config=.scalafix.test.conf # means that rules for test code are located in file .scalafix.test.conf\n```\n\n7. If you need to run a rule from Github, add it to the list of rules inside `.scalafix.conf`:\n```hocon\nrules = [\n  \"github:zio/zio/Zio2Upgrade?sha=series/2.x\"\n]\n```\n\nAnd then just run `mvn scalafix:scalafix`.\n\nThis is equivalent to `sbt \"scalafixEnable; scalafixAll github:zio/zio/Zio2Upgrade?sha=series/2.x\"`.\n\n8. To use a third-party rule, you may need to add its dependencies if the compiler complains about missing classes or methods. For example, scala-rewrites requires scalafix-core and typelevel-scalafix:\n\n```xml\n\u003cplugin\u003e\n    \u003cgroupId\u003eio.github.evis\u003c/groupId\u003e\n    \u003cartifactId\u003escalafix-maven-plugin_${scala.version.short}\u003c/artifactId\u003e\n    \u003cversion\u003e0.1.10_${scalafix.version}\u003c/version\u003e\n    \u003cdependencies\u003e\n        \u003cdependency\u003e\n            \u003cgroupId\u003ech.epfl.scala\u003c/groupId\u003e\n            \u003cartifactId\u003escalafix-core_${scala.version.short}\u003c/artifactId\u003e\n            \u003cversion\u003e${scalafix.version}\u003c/version\u003e\n        \u003c/dependency\u003e\n        \u003cdependency\u003e\n            \u003cgroupId\u003eorg.scala-lang\u003c/groupId\u003e\n            \u003cartifactId\u003escala-rewrites_${scala.version.short}\u003c/artifactId\u003e\n            \u003cversion\u003e0.1.3\u003c/version\u003e\n        \u003c/dependency\u003e\n        \u003cdependency\u003e\n            \u003cgroupId\u003eorg.typelevel\u003c/groupId\u003e\n            \u003cartifactId\u003etypelevel-scalafix_${scala.version.short}\u003c/artifactId\u003e\n            \u003cversion\u003e0.1.4\u003c/version\u003e\n        \u003c/dependency\u003e\n    \u003c/dependencies\u003e\n\u003c/plugin\u003e\n```\n\n## Contributing\nPull requests are welcome. For major changes, please [open an issue](https://github.com/evis/scalafix-maven-plugin/issues/new) first to discuss what you would like to change.\nIf you need some help with your PR at any time, please feel free to mention [`@evis`](https://github.com/evis).\n\n## Support\nThe best way to get help is to [open an issue](https://github.com/evis/scalafix-maven-plugin/issues/new). You can do it for things like asking questions about the project or requesting technical help.\n\n## License\n[BSD-3-Clause](https://opensource.org/licenses/BSD-3-Clause)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fevis%2Fscalafix-maven-plugin","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fevis%2Fscalafix-maven-plugin","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fevis%2Fscalafix-maven-plugin/lists"}