I have this setup currently:
Project A outputs a war file – has a configuration file (WEB-INF/web.xml). We’ve been delivering this with a commented out section of configuration which gets uncommented manually when the project is deployed in a particular environment.
Needs of the project have changed – and I need Project A to be built without that section of configuration entirely; and I need another project (Project B) to be built WITH that section of configuration (enabled, not commented out).
Rather than having the file exist in both projects (dual maintenance), I had hoped I could have Project B depend on Project A (via war overlay), and then use the maven-config-processor-plugin to add my special config to WEB-INF/web.xml, then re-package the war file.
This doesn’t seem to work – though – the config modification can work if the target already exists (i.e. after the previous run), but when I run everything together, the overlay and repackaging into the new war happens together – and I can’t figure out any way to make the config-processor plugin operate in the middle. Basically, the default order ends up being “config-processor” (which fails because the overlay hasn’t happened yet), then “war” (all as one unit). I can’t make the config-processor happen after the overlay but before the war is fully packaged.
Multiple people on the internets have asked over the last few years if there is a way to inject a plugin in between the “unpack the overlay” and “repack the war file” steps, but nobody has seemingly answered this definitively either way. Any ideas?
Since war overlays and war packaging all seems to happen as part of a single goal, I don’t think there’s a way to get in the middle of it. As a workaround, you could extract
web.xmlin an earlier phase and process it. The maven-dependency-plugin can be used in Project B to extractweb.xmlfrom Project A into a work directory, then run maven-config-processor-plugin onweb.xmland place the result somewhere else, then instruct maven-war-plugin to include that processedweb.xmlbefore overlays. In Project B’s POM:As far as I can tell, the war plugin includes
webResourcesfirst, followed bysrc/main/webapp, followed by overlays.I’m not familiar with maven-config-processor-plugin, so I apologize if my configuration there is not correct.