2

I'm building a web app with Dropwizard, and trying to use the Shiro bundle module (Maven repo) to integrate Shiro authentication.

My problem is that in the remote Maven repo the filename is dw-shiro-bundle-0.0.1-20130412.232035-4.jar, instead of dw-shiro-bundle-0.0.1-SNAPSHOT.jar. I understand this happens when you build the same SNAPSHOT version four times to avoid clobbering the first three, and the index takes care of finding the latest one.

However I'm also following this advice to avoid using maven-shade-plugin and effectively do the shading myself, since the final JAR is otherwise too big. maven-assembly-plugin is configured to copy the Shiro bundle JAR to lib/dw-shiro-bundle-0.0.1-SNAPSHOT.jar, but in the final JAR's MANIFEST.MF, the dependency is listed as io.ifar.dw-shiro-bundle-0.0.1-20130412.232035-4.jar, and hence I get a ClassDefNotFoundError at runtime.

A workaround is to manually rename the lib jar to io.ifar.dw-shiro-bundle-0.0.1-20130412.232035-4.jar so it gets picked up on the classpath, but it's not really a solution. Is there a way to either:

  1. fix the MANIFEST.MF entry
  2. normalize the name of third-party JARs as they are downloaded by Maven to strip any build numbers, or
  3. automate the process of renaming the JAR file to include the build number?

My plugins are as follows:

In maven-jar-plugin:

    <configuration>
      <forceCreation>true</forceCreation>
      <archive>
        <manifest>
          <mainClass>${mainClass}</mainClass>
          <addClasspath>true</addClasspath>
          <classpathLayoutType>custom</classpathLayoutType>
          <customClasspathLayout>lib/${artifact.groupId}.${artifact.artifactId}-${artifact.version}${dashClassifier?}.${artifact.extension}</customClasspathLayout>
        </manifest>
      </archive>
    </configuration>

In maven-dependency-plugin:

    <executions>
      <execution>
        <id>copy-dependencies</id>
        <phase>package</phase>
        <goals>
          <goal>copy-dependencies</goal>
        </goals>
        <configuration>
          <overWriteReleases>true</overWriteReleases>
          <overWriteSnapshots>true</overWriteSnapshots>
          <overWriteIfNewer>true</overWriteIfNewer>
          <prependGroupId>true</prependGroupId>
        </configuration>
      </execution>
    </executions>

assembly.xml:

   <?xml version="1.0" encoding="UTF-8"?>
    <assembly>
      <id>package</id>
      <formats>
        <format>zip</format>
      </formats>
      <includeBaseDirectory>true</includeBaseDirectory>
      <fileSets>
        <fileSet>
          <directory>target/dependency</directory>
          <outputDirectory>/lib</outputDirectory>
          <includes>
            <include>**/*</include>
          </includes>
        </fileSet>
        <fileSet>
          <directory>${project.build.directory}/</directory>
          <outputDirectory>/</outputDirectory>
          <includes>
            <include>*.jar</include>
          </includes>
        </fileSet>
        <fileSet>
          <includes>
            <include>configuration.yml</include>
          </includes>
        </fileSet>
      </fileSets>
    </assembly>
Community
  • 1
  • 1
orlade
  • 2,060
  • 4
  • 24
  • 35

1 Answers1

2

As soon as I posted this I found the answer. I guess that's just how it goes.

Buried in the documentation for the Maven Archiver is a section on Handling Snapshot Versions, which says to replace ${artifact.version} with ${artifact.baseVersion}. And it works! The 20130412.232035-4 on the end is replaced with SNAPSHOT.

orlade
  • 2,060
  • 4
  • 24
  • 35