0

I'm using sbt 0.13.8 and xsbt-web-plugin 2.0.3

I have a multi-module sbt project. When packaged, one of the modules should be in the form of a war file. All of the others in jar files.

When I add the xsbt-web plugin, packaging generates jars and wars for all modules. How can I tell the xsbt-web plugin to apply itself only to the module that should be packaged as a war?

I've already found one solution, which is to mutate the packagedArtifacts list for each non-war module:

packagedArtifacts <<= packagedArtifacts map { as => as.filter(_._1.`type` != "war") }

However, this is a non-local change which I would have to apply to each new non-war module that I (or a team member) might create.

I do not consider this a duplicate of the StackOverflow issue How to “package” some modules to jars and others to wars in multi-module build with single task? since I am not using assembly.

Note that the jars for the jar modules and the wars for the war modules, which are currently being generated, work splendidly. I'm only trying to avoid the situation where somebody tries to deploy a war that was meant to be a jar.

Community
  • 1
  • 1
kilo
  • 539
  • 4
  • 13
  • Which version of xsbt-web-plugin are you using? – earldouglas Jul 28 '15 at 20:51
  • I'm using xsbt-web-plugin 2.0.3. – kilo Jul 28 '15 at 20:56
  • Are you using `enablePlugins()` on each module, or just the webapp? – earldouglas Jul 28 '15 at 22:53
  • @James Now I'm not using it at all. I only need the function to package a war, not to run an embedded web server in sbt. Previously, I tried it only in the war project, and only in the root project -- in either case it didn't seem to make a difference. Without enablePlugins(JettyPlugin) I still get the war files. Only if I don't use addSbtPlugin does the package behavior stop generating war files. – kilo Jul 29 '15 at 07:56
  • Ah ha, you're right; this is a bug. The `AutoPlugin` for building *.war* files is getting triggered for all projects, not just the one with `enablePlugin()`. I will fix this in 2.0.4, and you will be able to use just the `*.war` file support via `enablePlugin(WarPlugin)`. Stand by for an update. – earldouglas Jul 29 '15 at 14:17

1 Answers1

2

This was a bug in version 2.0.3 -- thanks for discovering it! I've fixed it in 2.0.4.

To enable .war file publishing for a single module in a multi-module project:

  1. Add xsbt-web-plugin in project/plugins.sbt
  2. Enable the WarPlugin plugin in [webproject]/build.sbt

project/plugins.sbt:

addSbtPlugin("com.earldouglas" % "xsbt-web-plugin" % "2.0.4")

[webproject]/build.sbt:

enablePlugins(WarPlugin)

You can find a full example of this at https://earldouglas.com/ext/stackoverflow.com/questions/31683637/

earldouglas
  • 13,265
  • 5
  • 41
  • 50
  • Thank you @James! I thought I was just using it wrong. Version 2.0.4 does indeed create the war file only for the war module, and jars for all of the rest. For the benefit of other readers, I might add that enablePlugins is variadic. For example, to add the war and the jetty plugin, use enablePlugins(WarPlugin, JettyPlugin) – kilo Jul 29 '15 at 15:47
  • Cool, I didn't know that `enablePlugins()` is varadic. Note that if you enable `JettyPlugin`, you automatically get `WarPlugin`, since it is a dependency. – earldouglas Jul 29 '15 at 18:46