The answer would lie in wro4j library. For a more precise setup see:
Javascript and CSS files combining in Maven build WITHOUT compression, minification etc
Question
I would like to aggregate / assemble multiple js files into one without minifying or obfuscating them using a maven plugin. I am already using a yui plugin to obfuscate some js files into one:
<plugin>
<groupId>net.alchim31.maven</groupId>
<artifactId>yuicompressor-maven-plugin</artifactId>
<version>1.2</version>
<executions>
<execution>
<id>obfuscate</id>
<phase>process-resources</phase>
<goals>
<goal>compress</goal>
</goals>
<configuration>
<nosuffix>true</nosuffix>
<linebreakpos>-1</linebreakpos>
<aggregations>
<aggregation>
<removeIncluded>true</removeIncluded>
<insertNewLine>false</insertNewLine>
<output>${project.build.directory}/${project.build.finalName}/all.js</output>
<includes>
<include>**/*.js</include>
</includes>
<excludes>
<exclude>**/include/*.js</exclude>
</excludes>
</aggregation>
</aggregations>
</configuration>
</execution>
</executions>
</plugin>
Now I want the same js files aggregated without minification or obfuscation in a file allForDev.js . The goal is to have one file for development and one for production. Its going to be useful to see the whole scripts when debugging in developer tools. If I don't find a way to do this I'll be forced to place a lot of script tags to load all those scirpts (which is not the end of the world :) but I would like to do it in a cleaner way).
I can see that the assemble plugin has the following formats:
zip tar.gz tar.bz2 jar dir war and any other format that the ArchiveManager has been configured for
Is there a way I can use the assemble maven plugin to do this? As much as I looked there were a bunch of examples to create zips jars and wars, but none to match what I want to do. Or did I miss something?
Is there another plugin I could use?
As a side note, I tried using a second execution of the yui plugin to create a second js file, but I had no luck in creating 2 files. I also tried providing 2 yui plugins, with no luck again. I think that's not possible either.
Cheers,
Despot
Solution
The answer would lie in wro4j library. For a more precise setup see:
Javascript and CSS files combining in Maven build WITHOUT compression, minification etc
OTHER TIPS
If you do not want to hassle with the wro4j plugin as me (from @despot's answer) and want to prototype quickly, you can actualy use the old maven-antrun-plugin
with similar configuration as the following one:
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.8</version>
<executions>
<execution>
<phase>generate-sources</phase>
<configuration>
<target>
<property name="root" location=""/>
<property name="jsRoot" location="${root}/src/main/webapp/js"/>
<property name="jsAggregated" location="${root}/src/main/webapp/all.js"/>
<echo message="Aggregating js files from ${jsRoot} into ${jsAggregated}"/>
<concat destfile="${jsAggregated}" encoding="UTF-8" >
<fileset dir="${jsRoot}" includes="*.*"/>
<filelist dir="${jsRoot}/.." files="client.js"/>
</concat>
</target>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
This one concatenates all files in folder <module>/src/main/webapp/js/*.*
(but not files from sub folders). Then it adds client.js
to the end to make sure all stuff is available for it (AFAIK <fileset>
has undefined order).
The resulting concatenated file then resides at <module>/src/main/webapp/all.js
.
I know the maven phase, paths and other stuff may not be "correct" - this is just a quick example to show the alternative non-invasive way to do it.