I am using Maven to build an HTML webapp. I have one profile for debug and another profile for release. In the debug profile I’d like to have un-compressed Javascript used in the HTML page but in the release profile I concatenate all of the Javascript files and then compress them using Googles Closure compiler.
So basically I have 2 lists of Javascript files that I need to write out as <script> tags into the HTML page based on which profile is selected.
Is there a Maven plugin that I could configure with different lists for different profiles that could generate the HTML file as necessary?
After much investigation I determined the best options was to write my own maven plugin. I have a simple .html template which contains directives on where to insert CSS and JS tags into the HTML:
I then have a Maven plugin that runs in the “generate-sources” phase of the Maven lifecycle which takes the template and replaces the
$cssIncludes$and$jsIncludes$with the appropriate list of<script>and<link>tags. (Note: I am using the antlr stringtemplate Java library as a dependency for my plugin).I can’t post the actual plugin since it is a proprietary project but it is a single Java class that extends from AbstractMojo
@parameterproperties to read the<configuratioon>from the POMorg.antlr.stringtemplate.StringTemplatefrom the html templateorg.antlr.stringtemplate.language.DefaultTemplateLexer.<script>and<link>tags as stringstemplate.setAttributeto bind the built string to $cssIncludes$ and $jsIncludes$It works quite nicely. I simply send a different list of JS and CSS files to the plugin based on the current Maven profile.