Skip up-to-date source files

When generating output files using xsl:result-document command (typically in the many-to-dynamic goal), the XSLT generator Maven plugin has no way how to determine if the output files are up-to-date or need re-generating.

This implies that when using XSLT 2.0 (which introduces the xsl:result-document command), all generator invocations should always be run to prevent not generating output files which need to be re-generated. This might present a significant performance penalty in an IDE, where multiple time-consuming executions of the generator may result from every saving of a resource file.

To overcome this, the initialize and finalize goals have been introduced.

  • Configure the initialize goal to run BEFORE any other execution of the generator. It binds by default to Maven phase initialize, which is usually fine.
  • Configure the finalize goal to run AFTER any other execution of the generator. It binds by default to Maven phase process-resources, which is fine provided you only use the generator in the main scope. If you use it in the test scope, you should bind it to the relevant last phase it is used in (eg. process-test-resources).

Having the timestamp of the previous build, the plugin can then skip source files with last-updated timestamp older than that, thus eliminating unnecessary invocations (or even instantiations) of the XSLT engine.

<plugin>
  <groupId>net.sf.xsltmp</groupId>
  <artifactId>xslt-generator-maven-plugin</artifactId>
  ...
  <executions>
          <execution>
                ...
          </execution>
          ... all other executions ...
          <execution>
            <id>initialize</id>
            <goals>
              <goal>initialize</goal>
            </goals>
          </execution>
          <execution>
            <id>finalize</id>
            <goals>
              <goal>finalize</goal>
            </goals>
          </execution>
  </executions>
</plugin>

Note! When the generator is run in the build after the finalize goal, it will never perform the generation. If you eg. configure the finalize goal in process-resources phase in the default Maven lifecycle (to stop repeating re-generations in IDE) and also have the generator configured in some other lifecycle (typically site), then running mvn install site will effectively never generate anything in the site phase, because the generator has always been already finalized in the process-resources phase of the default lifecycle triggered by the install keyword by the time the build proceeds to the site phase. To resolve this, force the generation in the site phase:

<execution>
        <id>do-stuff-in-site</id>
        <phase>site</phase>
        <goals>
                ...
        </goals>
        <configuration>
                <force>true</force>
                ...
        </configuration>
</execution>