@@ -478,7 +478,8 @@ Next we update the rule to have an instance of the configuration
478
478
479
479
> It's important to keep an empty constructor ` def this() = ... ` so that
480
480
> Scalafix can load the rule. If we forget the empty constructor we get an error
481
- > like this: "Provider fix.NoLiteralArguments could not be instantiated"
481
+ > like this: "java.lang.NoSuchMethodException: Provider fix.NoLiteralArguments
482
+ > could not be instantiated"
482
483
483
484
Next, we create a companion object with decoders to read ` .scalafix.conf `
484
485
configuration into ` NoLiteralArgumentsConfig ` .
@@ -640,16 +641,77 @@ The expansion rules for `github:org/repo` are the following:
640
641
641
642
## Publish the rule to Maven Central
642
643
643
- The most robust way to share a custom rule is to publish it as a library to
644
- Maven Central. The
645
- [ ` build.sbt ` ] ( https://github.com/olafurpg/named-literal-arguments/blob/master/scalafix/build.sbt )
646
- shows the necessary changes to build.sbt to populate publishing information. The
647
- [ sbt-ci-release] ( https://github.com/olafurpg/sbt-ci-release ) readme documents
648
- the further steps to configure gpg and Sonatype.
644
+ Run the following sbt command to publish a rule locally.
649
645
650
- Once you have your rule, users can depend on it in the sbt plugin by updating
651
- ` scalafixDependencies `
652
- (` scalafix.sbt.ScalafixPlugin.autoImport.scalafixDependencies ` )
646
+ ``` sh
647
+ > rules/publishLocal
648
+ ```
649
+
650
+ To publish a rule online you need additional steps. First, add the settings
651
+ below to your ` build.sbt ` (replacing ` ch.epfl.scala ` , ` scalacenter/scalafix ` and
652
+ ` olafurpg ` with your own organization and project name)
653
+
654
+ ``` scala
655
+ // build.sbt
656
+ inThisBuild(List (
657
+ organization := " ch.epfl.scala" ,
658
+ homepage := Some (url(" https://github.com/scalacenter/scalafix" )),
659
+ licenses := List (" Apache-2.0" -> url(" http://www.apache.org/licenses/LICENSE-2.0" )),
660
+ developers := List (
661
+ Developer (
662
+ " olafurpg" ,
663
+ " Ólafur Páll Geirsson" ,
664
+
665
+ url(" https://geirsson.com" )
666
+ )
667
+ )
668
+ ))
669
+ ```
670
+
671
+ Next, add the ` sbt-ci-release ` plugin to ` project/plugins.sbt `
672
+
673
+ ``` scala
674
+ // project/plugins.sbt
675
+ addSbtPlugin(" com.geirsson" % " sbt-ci-release" % " 1.2.2" )
676
+ ```
677
+
678
+ If you have not setup GPG on your machine, run the following command
679
+
680
+ ``` sh
681
+ gpg --gen-key
682
+ ```
683
+
684
+ Finally, create a Sonatype account if you have never published to Sonatype
685
+ before. Follow the instructions
686
+ [ here] ( https://central.sonatype.org/pages/ossrh-guide.html ) . If you don't have a
687
+ domain name, you can use ` com.github.@username ` . Here is a template you can use
688
+ to write the Sonatype issue:
689
+
690
+ ``` text
691
+ Title:
692
+ Publish rights for com.github.olafurpg
693
+ Description:
694
+ Hi, I would like to publish under the groupId: com.github.olafurpg.
695
+ It's my GitHub account https://github.com/olafurpg/
696
+ ```
697
+
698
+ Once Sonatype and GPG are setup, run the following command to publish the rule
699
+ online.
700
+
701
+ ``` sh
702
+ > rules/publishSigned
703
+ > sonatypeRelease
704
+ ```
705
+
706
+ Once published, users can run your rule with the following sbt command.
707
+
708
+ ``` sh
709
+ // sbt shell
710
+ > scalafix dependency:
[email protected] :named-literal-arguments:VERSION
711
+ ```
712
+
713
+ To permanently install the rule for a build, users can add the dependency to
714
+ ` build.sbt ` by updating ` scalafixDependencies in ThisBuild ` .
653
715
654
716
``` scala
655
717
// build.sbt
@@ -659,6 +721,12 @@ scalafixDependencies in ThisBuild +=
659
721
> scalafix NamedLiteralArguments
660
722
```
661
723
724
+ For builds using ` project/*.scala ` files, add the following auto import
725
+
726
+ ``` scala
727
+ import scalafix .sbt .ScalafixPlugin .autoImport ._
728
+ ```
729
+
662
730
Users of the Scalafix command-line interface can use the ` --tool-classpath ` flag
663
731
664
732
```
@@ -672,11 +740,31 @@ scalafix \
672
740
Note that for syntactic rules like ` NoLiteralArguments ` , the ` --classpath `
673
741
argument is not required.
674
742
675
- Don't be intimidated by publishing to Maven Central, it gets easier once you've
676
- done it the first time. A guide on how to publish libraries can be found
677
- [ here ] ( https://github.com/olafurpg/sbt-ci-release ) . The benefits of publishing a
678
- rule to Maven Central are many .
743
+ ### Adding custom resolver
744
+
745
+ Update the ` scalafixResolvers ` setting to resolve rules that are published to a
746
+ custom repository like Bintray or a private Nexus .
679
747
680
- - Dependencies, you can use custom library dependency to implement your rule
681
- - Fast to run, no need to re-compile the rule on every Scalafix invocation
682
- - Tab completion in sbt, users can tab-complete your rule when using sbt plugin
748
+ ``` scala
749
+ // build.sbt
750
+ import com .geirsson .coursiersmall .{Repository => R }
751
+ scalafixResolvers.in(ThisBuild ) ++= List (
752
+ R .SonatypeSnapshots ,
753
+ R .bintrayRepo(" scalacenter" , " releases" ),
754
+ R .bintrayIvyRepo(" sbt" , " sbt-plugin-releases" ),
755
+ new R .Maven (" https://oss.sonatype.org/content/repositories/snapshots/" ),
756
+ new R .Ivy (s " https://dl.bintray.com/sbt/sbt-plugin-releases/ " )
757
+ )
758
+ ```
759
+
760
+ ### Conclusion
761
+
762
+ Don't be intimidated by publishing to Maven Central, it gets easier once you've
763
+ done it the first time. A more detailed guide on how to publish libraries can be
764
+ found [ here] ( https://github.com/olafurpg/sbt-ci-release ) . The benefits of
765
+ publishing a rule to Maven Central are many.
766
+
767
+ - Bring your own dependencies, you can use custom library dependency to
768
+ implement a published rule.
769
+ - Fast to run, no need to re-compile the rule on every Scalafix invocation.
770
+ - Tab completion in sbt, users can tab-complete your rule when using sbt plugin.
0 commit comments