|
MavenPlugin
IntroductionThe main purpose of wro4j is to provide a runtime solution for optimizing web resource. Still, if you need a build time solution, the wro4j-maven-plugin can help you to achieve this goal. Eclipse IDE supportNot is possible to use the wro4j-maven-plugin with an eclipse plugin called m2e-wro4j. More details about how to use it can be found on this blog post. DetailsThere is almost no difference regarding project configuration. Thus, if you have configured your project for a runtime solution, there is almost nothing else to change. A standard folder structure, which is used by wro4j maven plugin as default looks like this:
All you have to do, is to add the following plugin dependency to the pom.xml of your web project: <plugins>
<plugin>
<groupId>ro.isdc.wro4j</groupId>
<artifactId>wro4j-maven-plugin</artifactId>
<version>${wro4j.version}</version>
</plugin>
</plugins>This is the minimum necessary to get started. At this point, you can already start using it by running the following in command line: mvn wro4j:run -Dminimize=true -DtargetGroups=all This command will generate a minimized version of all resources contained in 'all' group, for both type of resource: js & css. You can configure all the properties in pom.xml in order to avoid specifying parameters in command line. In this case, your plugin configuration would look like this: <plugins>
<plugin>
<groupId>ro.isdc.wro4j</groupId>
<artifactId>wro4j-maven-plugin</artifactId>
<version>${wro4j.version}</version>
<executions>
<execution>
<phase>compile</phase>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
<configuration>
<targetGroups>all</targetGroups>
<destinationFolder>${basedir}/src/main/webapp/wro/</destinationFolder>
<contextFolder>${basedir}/src/main/webapp/</contextFolder>
</configuration>
</plugin>
</plugins>This is the smallest configuration with most of the parameters using default values. Eventually, you'll want to have a more advanced control over configuration. Below, you can see an example of configuration with all possible parameters set: <plugins>
<plugin>
<groupId>ro.isdc.wro4j</groupId>
<artifactId>wro4j-maven-plugin</artifactId>
<version>${wro4j.version}</version>
<executions>
<execution>
<phase>compile</phase>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
<configuration>
<targetGroups>all</targetGroups>
<minimize>true</minimize>
<destinationFolder>${basedir}/src/main/webapp/wro/</destinationFolder>
<cssDestinationFolder>d:/static/css/</cssDestinationFolder>
<jsDestinationFolder>d:/static/js/</jsDestinationFolder>
<contextFolder>${basedir}/src/main/webapp/</contextFolder>
<wroFile>${basedir}/src/main/webapp/WEB-INF/wro.xml</wroFile>
<wroManagerFactory>com.mycompany.MyCustomWroManagerFactory</wroManagerFactory>
<ignoreMissingResources>false</ignoreMissingResources>
</configuration>
</plugin>
</plugins>Plugin ParametersBelow is the description of parameters you can provide for the plugin:
A common practice is to have a single group (called 'all') which contains all other existing group. Still, if you want to build a file containing merged resources for other groups, you can do it like this:-DtargetGroups=group1,group2,group3
Since 1.3.0 version, wro4j provides two new manager factories: Since 1.4.0 version, the following manager is available: ${basedir}/src/main/webapp/WEB-INF/wro.properties. The processors can be configured by adding the following to wro.properties file: preProcessors=cssImport,jsMin,cssMin postProcessors=lessCss,coffeeScript You can notice that the pre processors are provided using preProcessors key and the value is a comma separated list of processors aliases. The same applies to post processors, the only difference is the key, which is postProcessors in this case. There are also few more other parameters which can be specified inside plugin configuration in pom.xml only:
The parameters: destinationFolder, cssDestinationFolder, jsDestinationFolder are optional. When providing one of the following cssDestinationFolder or jsDestinationFolder, you have a more granular control over where to put the merged resources (useful when you want you css files to be located in different folder than the JavaScript). In other words, if aggregated resources of both types should be located in the same folder, use destinationFolder parameter. However, if you want css resources to be located in a different folder than js resource, than cssDestinationFolder & jsDestinationFolder are your friends. Note that if you are building a war file, you can specify the target directory by prefixing the destination directory path with '${project.build.directory}/${project.build.finalName}'. | |
How is the maven plugin supposed to interact with the cssUrlRewriting. I've managed to make things work to some degree by maintaining a parallel tree of static resources and disabling the cssUrlRewriting, but feel that I may be missing something important.
You can control the processors chain, find out how to do that here: http://code.google.com/p/wro4j/wiki/ProcessorsManagement
Hi,
I want to use several wro4j files and process them differently (e.g. different source files, different destination folders, different compression).
I created the wro.xml files in 4 different directories and would use all 4 for generating 4 different all-targets in different destination directories.
How can I specify 4 different configurations and 4 different compression algorithms (e.g. cssMin, beautifyJs, ...) in the pom.xml?
Thanks for your help
Artur
Sorry for the inconvinience,
I did find the solution by moving the configuration into the <execution> section and using different <id/>s for each section.
Cheers
Artur
Hi Artur, you've found the solution I was about to suggest. Just one thing: there is no need to have multiple wro.xml files. You can create different groups and reuse the same wro.xml file for all processing variation you need.
Hi Alex,
thanks for your suggestion. I was using different wro4j configuration files because I wanted to generate the same files for two different devices, e.g. all.css for iphone and all.css for desktop. Both are using different input css files and the output css files should be stored in different directories. This is now working nicely with the different execution sections.
The only issue I've got at the moment is the wish to use the WRO4J maven plugin as simple as the WRO4J-Runner on command line. The reason is to use a simple way to specify the preprocessors by our web developr as propertty in the pom.xml like it works for WRO4J runner (-m -c BeautifyJs?). Especially because we want to use different compression algorithms for the "devel" profile and for the "prod" profile.
On "devel" we would like to use "cssLint" for css, "BeautifyJs?" for javascript, but on the prod profile perhaps "yuiCssMin" for CSS and "GoogleClosureAdvanced?" for javascript.
The easiest way would be the possibility to define it like the WRO4J URI filter in the <filter/> section using the ConfigurableWroManagerFactory and only specifying the <preprocessors> in the <configuration> instead of creating standalone factories for all algorithms available in WRO4J.
Thanks for your help
Artur
I am thinking about creating somekind of DSL for specifying processors, which could be used by maven plugin. Not sure how this should look like yet.
This feature isn't hard to implement, but I don't want to add it unless I have a good and simple way to use it. Once a feature is added, it should be supported in future releases.
You could try to implement ProcessorsFactory? interface which would read a property file where you would define the processors you would like to be used during processors. Your implementation could be a good starting point for this feature, because you are the first one who had the idea for this use-case.
The issue containing this feature has been created: http://code.google.com/p/wro4j/issues/detail?id=254
Hi,
I would keep it as consistent as possible with the <filter/> version of WRO4J. It would be enough to have the possibility to use <preprocessors>CssImportPre? lessCss dataUri yuiCssMin</preprocessors> as chain for one <configuration> section in the plugin.
Would it be too complicated to reuse the same code as in the <filter> configuration?
What do you think?
Thanks a lot for your help and your great work!
Artur
Actually I would rather keep this kind of configuration out of web.xml. The preferred way would be a property file or something similar. Check out the updated documentation: http://code.google.com/p/wro4j/wiki/Installation
This approach would keep the web.xml clean and allow you to change configuration programatically based on your environment or other preferences.
hi together,
I have a problem with the point that artur was asking: how to use multiple processings within one pom.xml? We did it like it is described here, but it is not working. the plugin is searching for the wro.xml instead of the specified wro-vcl.xml.
any ideas?
this is very importing for us.
regards dirk
<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> <modelVersion>4.0.0</modelVersion> <artifactId>myartifact</artifactId> <groupId>mytool</groupId> <version>1.0.0-SNAPSHOT</version> <packaging>war</packaging> <name>${project.artifactId}.${project.packaging} - ${project.version}</name> <parent> <groupId>myartifactfather</groupId> <artifactId>myartifacttool</artifactId> <version>1.0.0-SNAPSHOT</version> <relativePath>../base-pom.xml</relativePath> </parent> <dependencies> <dependency> <groupId>com.ibm.wps</groupId> <artifactId>portletapi</artifactId> <version>2.0</version> <scope>provided</scope> </dependency> </dependencies> <distributionManagement> <snapshotRepository> <id>nexus</id> <name>Repository</name> <url>myurl/</url> </snapshotRepository> </distributionManagement> <properties> <minimize>true</minimize> </properties> <build> <plugins> <!-- Optimizing css & js files --> <plugin> <groupId>ro.isdc.wro4j</groupId> <artifactId>wro4j-maven-plugin</artifactId> <version>1.4.1</version> <executions> <!-- VCL css & js --> <execution> <id>vcl</id> <configuration> <targetGroups>vcl</targetGroups> <wroFile>${basedir}/src/main/webapp/WEB-INF/wro-vcl.xml</wroFile> <destinationFolder>${basedir}/src/main/webapp/vcl/</destinationFolder> <extraConfigFile>${basedir}/src/main/webapp/WEB-INF/wro-vcl.properties</extraConfigFile> </configuration> <phase>compile</phase> <goals> <goal>run</goal> </goals> </execution> <!-- js --> <execution> <id>js</id> <configuration> <targetGroups>all-js</targetGroups> <wroFile>${basedir}/src/main/webapp/WEB-INF/wro-js.xml</wroFile> <destinationFolder>${basedir}/src/main/webapp/js</destinationFolder> <extraConfigFile>${basedir}/src/main/webapp/WEB-INF/wro-js.properties</extraConfigFile> </configuration> <phase>compile</phase> <goals> <goal>run</goal> </goals> </execution> </executions> <configuration> <contextFolder>${basedir}/src/main/webapp/</contextFolder> <minimize>${minimize}</minimize> <ignoreMissingResources>false</ignoreMissingResources> <wroManagerFactory>ro.isdc.wro.maven.plugin.manager.factory.ConfigurableWroManagerFactory</wroManagerFactory> </configuration> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-war-plugin</artifactId> <version>2.1.1</version> <configuration> <archive> <manifestEntries> <SCM-Revision>${buildNumber}</SCM-Revision> </manifestEntries> </archive> </configuration> </plugin> </plugins> </build> </project>Hi,
Can you show the content of the wro-vc.properties & wro-js.properties files?
Also, could we move this discussion to mailing list? (I don't want to pollute this wiki page with too much comments).
Thanks, Alex
I have tried locally, and as long as all required files exist, everything works as expected.
wro-vcl.properties:
but the problem is that the files are not loaded.
i start maven like this: mvn wro4j:run and this is the result:
Try to run it using:
From some reason, when running the wro4j:run goal directly, the options aren't picked-up. I think this is something related to how maven works when multiple executions are configured (not related to wro4j maven plugin)
it works. thank you for your support!