Where to put maven generated webapp artifacts?

948 Views Asked by At

I'm using the swagger maven plugin to generate my swagger.json file. I want this to be available as a static resource in the webapp (src/main/webapp).

In the example on the github page they configure it like this.

<swaggerDirectory>generated/swagger-ui</swaggerDirectory>

I can't see how this would be useful as it's not in the webapp folder. I guess you'd have to manually copy it somewhere useful but what's the point in maven if it's not automated.

I've configured it like this in my project.

<swaggerDirectory>${basedir}/src/main/webapp/swagger</swaggerDirectory>

This allows me to access the file both during development (as an eclipse project) and when deployed (as a built war file).

The question is whether it's ok to pop generated artifacts in the usual src/main folder?

I have generated code from jaxb but that goes into a generated-sources folder in the target folder. This is then added as a source folder in eclipse and maven knows to add these classes to the build.

I basically just want to check I haven't comitted a maven faux pas by dumping my generated code in src/main/webapp. I know I'll have to gitignore this file.

2

There are 2 best solutions below

3
On

I would advise against putting generated code into src/main - which would be committed to source control. Besides, in your case the file itself is getting generated by a maven plugin - which will run when you build your project.

Rather use the resources, war, assembly... plugins to copy the file into your built war.

0
On

You could place the generated files in a directory such as target/generated-webapp. Then use the resource plugin to copy all the other files from src/main/webbpp to target/generated-webapp. And finally point the war plugin to target/generated-webapp as it's warSourceDirectory