In Riversim, I am leveraging GeoTools to generate GeoTIFF overlays of river channels and width imagery that I am generating. However, I encountered an issue when trying to use GeoTools with Maven’s assembly plugin. The core of the issue is that GeoTools dependencies have the colliding META-INF filenames for various component packages and the assembly plugin just clobbers files (or ignores them) rather than merging them.

The fix was to switch from using the assembly plugin to the “shade plugin”:http://maven.apache.org/plugins/maven-shade-plugin/ as it merges and manages files better than the assembly plugin. This became an issue when trying to load the gt-epsg-hsql dependency to incorporate the HSQL EPSG codes database to add coordinate data to the TIFF files I’m generating because the META-INF/services files were competing

Unfortunately, this led to a negative side-effect where the manifest settings that the assembly plugin was generating automatically (version) and semi-manually (vendor information) were not being included. The workaround there is to manually inject the following metadata into the manifest file:

  • Implementation-Vendor
  • Implementation-Vendor-Id
  • Implementation-Version

These are leveraged by the ImageIO / IIORegistry and the various IIO plugins will blow up without setting these. Why on earth the ImageIO subsystem was designed to care so much about these bits of data is, at present, beyond me; All the same, the issue needed to be resolved as I use the ImageIO libraries to manipulate TIFF and GeoTIFF files.

Here’s the relevant bits for the shade plugin in the Maven pom.xml:

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-shade-plugin</artifactId>
  <version>1.3.1</version>
  <executions>
     <execution>
        <phase>package</phase>
        <goals>
           <goal>shade</goal>
        </goals>
        <configuration>
           <transformers>
              <!-- This bit sets the main class for the executable jar as you otherwise -->
              <!-- would with the assembly plugin                                       -->
              <transformer implementation=
                     "org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                <manifestEntries>
                   <Main-Class>Extractor</Main-Class>
                   <Implementation-Vendor>John Ewart</Implementation-Vendor>
                   <Implementation-Vendor-Id>net.johnewart</Implementation-Vendor-Id>
                   <Implementation-Version>0.1</Implementation-Version>
                </manifestEntries>
              </transformer>
              <!-- This bit merges the various GeoTools META-INF/services files         -->
              <transformer implementation=
                    "org.apache.maven.plugins.shade.resource.ServicesResourceTransformer"/>
           </transformers>
        </configuration>
     </execution>
  </executions>
</plugin>
Filed under: , , , , ,