0

I have developed a custom sbt plugin that imports the sbt native packager, and a bunch of other plugins. This helps bootstrap a scala project easing the process of importing all plugins we use across the project.

I also have custom task for custom purposes, such a:

substituteTemplates

to do custom behaviour.

I'm also changing the behaviour of the plugin I'm importing to cope with my customizations, such as:

packageZipTarball in Universal <<= (packageZipTarball in Universal) dependsOn substituteTemplates.

Now, everything works but the user of my plugin has to do:

val example = (project in file(".")).enablePlugins(JavaAppPackaging).settings(...

if he does not do it the sbt will not compile, because sbt finds definitions of stuff (mappings in Universal and such... ) that do not exist. Here is how I tried to solve it.

TAKE 1

Now, I'd like to have the possibility to cope with the fact that some plugins need to be enabled. If I enable the plugins (for example JavaAppPackaging) then I do a bunch of other changes, otherwise I leave the settings untouched. At first I tried with a custom settings key, such as:

val enableJavaAppPackaging = SettingKey[Boolean]("enableJavaAppPackaging","")

then, I tried to use it:

object MyWrapperPlugin extends AutoPlugin {
    override def projectSettings: Seq[Setting[_]] = {
        if (enableJavaAppPackaging.value) {
          packageZipTarball in Universal <<= (packageZipTarball in Universal) dependsOn substituteTemplates,

        mappings in Universal <++= templates.map {
      _.keySet.map { k => file(s"target/templates/$k") -> k }.toList
    },

        // a lot of other stuff....
        }   

but this cannot work as sbt complains:

`value` can only be used within a task or setting macro, such as :=, +=, ++=, Def.task, or Def.setting

There is a way to do this kind of logic in a way that is OK also for sbt?

TAKE 2

If I cannot do this at least I'd like to turn the JavaApp PAckaging plugin by default, so not to do elsiffing at all.

object MyWrapperPlugin extends AutoPlugin {
   override def requires: Plugins = AssemblyPlugin && DependencyGraphPlugin && JavaAppPackaging

but this does not work too.

JayZee
  • 851
  • 1
  • 10
  • 17

0 Answers0