Jake Wharton
Jake Wharton

Reputation: 76115

Including Git Repo Contents As Subdir With Maven

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.

Upvotes: 1

Views: 741

Answers (2)

Pascal Thivent
Pascal Thivent

Reputation: 570645

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>
[...]

Upvotes: 2

Jon
Jon

Reputation: 475

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).

Upvotes: 0

Related Questions