tags:

views:

18

answers:

2

I have a separate git repository for document templates that I have no control over but whose contents need to be included as a folder in my final WAR. The versioning of these do not matter and the latest ones should always be used when packaging the war.

Is this possible with Maven or do I need to script something separately? I would very much like to avoid using a git submodule at all costs.

A: 

checkout the section on war resources here

Just point the webResoruces configuration to your git repo and it will be included in the war. You may alwo want to add an ignore option for the .git folder (unless you want all of git's artifacts in your war as well).

Jon
+1  A: 

Is this possible with Maven or do I need to script something separately? I would very much like to avoid using a git submodule at all costs.

It should be possible to use the Maven SCM Plugin and its scm:checkout goal to get the content of your git repository (providing all the required information in the configuration like the connectionUrl, the checkoutDirectory, etc) during the prepare-package phase (and get it packaged in your war during package). Something like this:

[...]
<build>
  [...]
  <plugins>
    <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-scm-plugin</artifactId>
      <version>1.1</version>
      <executions>
        <execution>
          <phase>prepare-package</phase>
          <goals>
            <goal>checkout</goal>
          </goals>
          <configuration>
            <checkoutDirectory>${project.build.directory}/${project.build.finalName}/somepath</checkoutDirectory>
            <connectionUrl>scm:git:git://server_name[:port]/path_to_repository</connectionUrl>
            ...
          </configuration>
        </execution>
      </executions>
    </plugin>
    [...]
  </plugins
  [...]
</build>
[...]
Pascal Thivent
Perfect, thank you! Very elegant.
Jake Wharton
@Jake You're welcome. I forgot to mention that but it might be wise to put the above in a profile used during final delivery only to avoid the checkout during development.
Pascal Thivent