1

我正在使用wro4j-maven-plugin来预处理我的.js,.css.less资源。

当预处理器失败时,例如.less文件包含语法错误时,插件只会在构建中输出堆栈跟踪并继续构建。

这导致必须监视构建过程,否则可能会破坏资源。有什么方法可以failOnError像使用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
4

1 回答 1

0

当发生异常时,lessCss 处理器的默认行为是中止处理并保持资源不变。这背后的原因是,当使用 lessCss 处理有效的 css 时,它可能会失败,因为从 Less 的角度来看它具有无效的语法。这通常发生在您处理混合资源(css & less)时。

下一个 wro4j 版本 (1.4.7) 将更改在资源处理期间处理异常时的默认行为。因此,当发生异常时 - 整体处理将失败(可以配置此行为)。

早期版本(包括 1.4.5)有一个解决方法。您可以扩展 LessCssProcessor 并覆盖 onException 方法。例子:

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

通过使用这个新处理器,您的构建将在处理器发生故障时失败。

于 2012-06-22T19:03:50.430 回答