3

When I build my project using sbt assembly, I get java.util.zip.ZipException: duplicate entry: META-INF/MANIFEST.MF. The solution that google recommends, is to use MergeStrategy.discard.

That works in getting the project to build - but it crashes at runtime, because Dropwizard (a dependency) relies on info contained in manifest.mf (full issue details: https://github.com/dropwizard/dropwizard/issues/455 ).

The recommendation when encountering that error, is to merge the manifests.

I've tried all the MergeStrategies on Manifest.MF that seem like they'd do the trick (filterDistinctLines, concat, first, last), they all cause the build to fail with java.util.zip.ZipException: duplicate entry: META-INF/MANIFEST.MF. The only thing that compiles is discard, but that causes the program to crash at runtime due to Dropwizard relying on the mf file.

Any ideas what to do here? Is there a way to merge the manifests as described in the comments at https://github.com/dropwizard/dropwizard/issues/455 ?

Ali
  • 261,656
  • 265
  • 575
  • 769

1 Answers1

0

So I ended up doing this:

  • Separated the Scala & Java projects
  • Build the sbt project as is - copy it to the java project/lib directory
  • Added a system dep for lib/scala project, and used the add-jar plugin to add this jar to the classpath when building the fatjar:

           <plugin>
                <groupId>com.googlecode.addjars-maven-plugin</groupId>
                <artifactId>addjars-maven-plugin</artifactId>
                <version>1.0.5</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>add-jars</goal>
                        </goals>
                        <configuration>
                            <resources>
                                <resource>
                                    <directory>${real.base.dir}/lib</directory>
                                </resource>
                            </resources>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
    
  • Build the java project fatjar and deploy it - it now has access to the scala jar on the classpath.

Script (server is the name of the java project i made):

sbt clean assembly
cp target/scala*/project*.jar server/lib
cd server
mvn clean install
cd ../
cp server/target/server*.jar target
Ali
  • 261,656
  • 265
  • 575
  • 769