简体   繁体   中英

How to make wro4j-maven-plugin fail the build when a preprocessor fails?

I am using the wro4j-maven-plugin for preprocessing my .js , .css and .less resources.

When a preprocessor fails, like when a .less file contains a syntax error, the plugin just outputs a stacktrace in the build and keeps on building.

This results in having to monitor the build process, or risk having broken resources. Is there any way to make this plugin failOnError like one would do with an AntRun ?

pom.xml:

<plugin>
    <groupId>ro.isdc.wro4j</groupId>
    <artifactId>wro4j-maven-plugin</artifactId>
    <version>1.4.5</version>
    <executions>
      <execution>
        <phase>compile</phase>
        <goals>
          <goal>run</goal>
        </goals>
      </execution>
    </executions>
    <configuration>
        <minimize>true</minimize>
        <jsDestinationFolder>${basedir}/WebContent/resources/min/js/</jsDestinationFolder>
        <cssDestinationFolder>${basedir}/WebContent/resources/min/css/</cssDestinationFolder>
        <contextFolder>${basedir}/WebContent/</contextFolder>
        <wroFile>${basedir}/WebContent/WEB-INF/wro.xml</wroFile>
        <extraConfigFile>${basedir}/WebContent/WEB-INF/wro.properties</extraConfigFile>
        <ignoreMissingResources>false</ignoreMissingResources>
        <wroManagerFactory>ro.isdc.wro.maven.plugin.manager.factory.ConfigurableWroManagerFactory</wroManagerFactory>
    </configuration>
</plugin>

wro.properties:

preProcessors=cssUrlRewriting,cssImport,yuiJsMin
postProcessors=lessCss,yuiCssMin

The default behavior of the lessCss processor when an exception occurs is to abort the processing and leave the resource unchanged. The reasoning behind this is that when a valid css is processed with lessCss, it may fail because it has invalid syntax from Less point of view. This usually happens when you process mixed resources (css & less).

The next wro4j version (1.4.7) will change the default behavior when dealing with exceptions during resource proccessing. Thus, when an exception will occur - the overall processing will fail (it will be possible to configure this behavior).

There is a workaround for earlier versions (including 1.4.5). You can extend the LessCssProcessor and override the onException method. Example:

/**
 * Invoked when a processing exception occurs.
 */
protected void onException(final WroRuntimeException e) {
   throw e;
}

By using this new processor instead, your build will fail anytime the processor will fail.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM