Daniel Kim
Daniel Kim

Reputation: 446

Maven Shared Dependency

Just got head into Maven and I've got situation where I have cyclic dependency problem. my original structure was

|-mainProject
|-webProject

where mainProject has webProject as a dependency (war packaging). Got error since webProject also depends on mainProject, so I changed the structure

|-coreProject
|-mainProject
|-webProject

so that core get packaged into a jar and both main&web have core as dependency. Now I see different error while creating -shade.jar.

CoreProject's components need to be used by both main&web projects. What would be the best practice in this case?


my dependency graph looks like

mainProject(jar) -> webProject(war)   --
                |-> coreProject(jar) <-|
                |-> jetty jars

I'm using embedded jetty in mainProject, so that my final outcome would be single jar file from mainProject which includes web&coreProjects.

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-shade-plugin:1.4:shade (default) on project mainProject: Error creating shaded jar: Invalid signature file digest for Manifest main attributes -> [Help 1]

I have tried filters such as

<filters>
   <filter>
      <artifact>*:*</artifact>
      <excludes>
         <exclude>META-INF/*.SF</exclude>
         <exclude>META-INF/*.DSA</exclude>
         <exclude>META-INF/*.RSA</exclude>
      </excludes>
   </filter>
</filters>

but still getting the same error

Upvotes: 0

Views: 1070

Answers (2)

Stephen C
Stephen C

Reputation: 719436

CoreProject's components need to be used by both main&web projects. What would be the best practice in this case?

If CoreProject consists of Java classes but no web stuff, make it a JAR project.

If CoreProject also has web stuff in it (i.e. stuff the belongs in a WAR not a JAR), then you could make it a WAR project, and have the other two WAR projects incorporate it using WAR file overlaying. You can read more about this here.

It is certainly the case that cyclic dependencies are problematic in Maven. You either need to break the cycle (by reorganizing things) or pull it all into a single Maven artifact.

Upvotes: 0

Perception
Perception

Reputation: 80633

It's highly unusual to have a WAR project as a dependency for another project in the way you described. A valid scenario I can think of is bundling the WAR into a 'higher' level archive (like an EAR). But in that case your dependency is defined in your EAR project and not the other way around. In any case, if you want to follow best practices then place your core classes in mainProject and set its packaging to JAR. Then add a dependency for it to your webProject.

If both mainProject and webProject will always be deployed together you should consider defining them as submodules in a multimodule POM.

Upvotes: 1

Related Questions