简体   繁体   中英

How to use sbt-assembly in sbt-plugin?

I am writing an sbt-plugin to abstract away some boilerplate. Let's call it sbt-redux

then there is one more plugin sbt-assembly .

In this quest, my plugin(sbt-redux) needs to know about where the project ( Project which is using sbt-redux ) will create Uber jar using sbt-assembly and what will be the name of jar. I tried adding sbt-assembly in plugins of sbt-redux, but for the obvious reasons it will not add dependencies in my src folder as it has limitations only in build.sbt.

I tried using .dependsOn(assembly) but still no luck.

So, How can I use other plugins into src?

PS Please let me know if the question is not clear.

There I found a solution and it is working for me. If you want to read assembly's settings, you have to make sure your plugins depend on it. In your build.sbt file, you can add:

addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "0.14.7").

And then in your AutoPlugin implementation, you should override requires this way:

override def requires = super.requires && sbtassembly.AssemblyPlugin

After that, you'll have access to assembly settings and tasks.

Thanks to gpoirier.

To expand on the correct answer from @arglee, when you have a multi-module project, the addSbtPlugin line needs to be part of the .settings entries for the module that needs the dependency, like:

lazy val mod = (project in file("mod"))
  .settings(
    ...,
    addSbtPlugin( ... ),
    libraryDependencies ++= Seq( ... ),
    ...
  )

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM