SBT how to use classes from Build.sbt inside plugin Task execution

后端 未结 1 1044
北海茫月
北海茫月 2021-02-09 04:09

Any classes defined in project/*.scala files are made available for use by SBT inside the build definition code.

I would like those classes to be available

相关标签:
1条回答
  • 2021-02-09 04:58

    I don't think it is possible, as documented in the SBT documentation

    Note: At runtime, all plugins for all builds are loaded in a separate, parent class loader of the class loaders for builds. This means that plugins will not see classes or resources from build definitions.

    Edited

    Based on the comments, I think maybe this solution may work. In the project/ create extra project called scala-style-defs. There place your rules. In the same project create build.sbt with the build definition e.g.

    libraryDependencies += "org.scalastyle" %% "scalastyle" % "0.4.0"
    
    resolvers += "sonatype-releases" at "https://oss.sonatype.org/content/repositories/releases/"
    

    Then in the project/ create build.sbt with following content

    lazy val root = project.in(file(".")) dependsOn(scalastyleDefs)
    
    lazy val scalastyleDefs = Project(id="scalastyleDefs", base=file("scala-style-defs"))
    

    and of course plugins.sbt with

    addSbtPlugin("org.scalastyle" %% "scalastyle-sbt-plugin" % "0.4.0")
    
    resolvers += "sonatype-releases" at "https://oss.sonatype.org/content/repositories/releases/"
    

    Now in your main project create build.sbt and there include scalastyle settings

    org.scalastyle.sbt.ScalastylePlugin.Settings
    
    0 讨论(0)
提交回复
热议问题