0
votes

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.

1
Which version of xsbt-web-plugin are you using? - earldouglas
I'm using xsbt-web-plugin 2.0.3. - kilo
Are you using enablePlugins() on each module, or just the webapp? - earldouglas
@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
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

1 Answers

2
votes

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/