Search code examples
scalasbtsbt-plugin

How to 'embed' SBT plugin in my Scala project


Im currently using an SBT plugin that runs as part of the compile task but wish to amend it. Have contacted author but no responses.

Can anyone give me a high-level overview of steps to import the functionality into my project so I can customise it? Its a single Object.

  • If the object is 'hooking' into compile task then I assume it should still extend plugin?

  • Currently, I have a compile error on import sbt.Keys._

import sbt._ works

import sbt.Keys._ object Keys is not a member of package set.

Do I need SBT jar as an unmanaged dependency of my project?

build.properties contains sbt.version=0.13.5

BTW - I shall be keeping original authors details in the code to attribute the code to them.


Edit.

I am using sbt-cxf-wsdl2java plugin.

I mainly wish to upgrade the version of CXF being used by the plugin, since this is hardcoded not the plugin object code.

I could fork it, change code, create new plugin and push to a repo to then declare in my project but this seems a lot of effort for a relatively small change - hence my wish to 'embed' the plugin code in my application.

I guess I need to read the docs and figure out how plugins work in order to understand this - but if anyone can give me a few pointers to save me time then I would really appreciate it.

build.sbt (with the relevant plugin bits):

lazy val wsPackage = "com.myCompany"

seq(cxf.settings :_*)

cxf.wsdls := Seq(
    cxf.Wsdl((resourceDirectory in Compile).value / "My.wsdl", Seq("-p",  wsPackage), "modelOutputDir")
)

plugins.sbt

addSbtPlugin("com.ebiznext.sbt.plugins" % "sbt-cxf-wsdl2java" % "0.1.4")

Solution

  • In build.sbt, you can override configuration keys (which are located in com.ebiznext.sbt.plugins.CxfWsdl2JavaPlugin.Keys). For example:

    lazy val wsPackage = "com.myCompany"
    
    Seq(cxf.settings :_*)
    
    cxf.cxfVersion := "3.1.2" // override CXF version
    
    cxf.wsdls := Seq(
      cxf.Wsdl((resourceDirectory in Compile).value / "My.wsdl", Seq("-p",  wsPackage, "-impl", "-mark-generated"), "unique wsdl id")
    )