Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 354379 - Maven dependencies in webapps may override each other due to naming scheme
Summary: Maven dependencies in webapps may override each other due to naming scheme
Status: CLOSED NOT_ECLIPSE
Alias: None
Product: z_Archived
Classification: Eclipse Foundation
Component: m2e (show other bugs)
Version: unspecified   Edit
Hardware: All All
: P3 critical (vote)
Target Milestone: ---   Edit
Assignee: Project Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-08-10 10:16 EDT by Sune Wettersteen CLA
Modified: 2021-04-19 13:24 EDT (History)
1 user (show)

See Also:


Attachments
A web deployment assembly containing two dependencies with the same artifact ID which results in identical (and thus conflicting) deployment names (96.28 KB, image/png)
2011-08-10 10:17 EDT, Sune Wettersteen CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Sune Wettersteen CLA 2011-08-10 10:16:06 EDT
Maven dependencies in webapps may override each other due to naming schemes. Maven will name jar files based on the artifact ID rather than using a fully qualified name based on both the group ID and the artifact ID. Due to the flat nature of the web application libraries this means that two different maven dependencies with identical artifact IDs will override each other.

The consequence of this is that a project depending on more than one artifact with the same artifact ID (and version), will only have one of these deployed to the web application (WEB-INF/lib).

A practical example:
Including version 1.0 of
com.googlecode.wicketelements » common
org.codehaus.hydra-cache » common

will attempt to put two "common-1.0.jar" (or similar) classes in the WEB-INF/lib directory when deploying the web app. Of course due to this naming scheme, only one of the jar files can exist in the lib folder. Ultimately this results in ClassNotFoundExceptions or similar.

As seen in the attached screenshot, the web deployment descriptor generated for a project which has two dependencies with the same artifact ID and the deployment path generated for each of them (which are identical).

This naming scheme may be standard for maven, but in order to overcome this deficiency the maven-war-plugin offers a way to map dependency names/version to file names:

<plugin>
  <artifactId>maven-war-plugin</artifactId>
  <version>2.1.1</version>
  <configuration>
    <archiver>
      <manifest_entry>value</manifest_entry>
    </archiver>
    <archive>
      <manifest>
        <addClasspath>true</addClasspath>
      </manifest>
    </archive>
    <attachClasses>true</attachClasses>
    <outputFileNameMapping>@{groupId}@-@{artifactId}@-@{version}@.@{extension}@</outputFileNameMapping>
  </configuration>
</plugin>

The "outputFileNameMapping" would ensure that dependencies get fully qualified names. However, even though this is configured in the project pom file, it is not reflected in the web deployment assembly used by eclipse. The m2e functionality should definitely be able to be able to pick up this configuration and ensure that the web deployment assembly generated reflects these settings.

I see this as a critical bug (or missing functionality) since dependency inclusion becomes random when having dependencies with identical artifact IDs. We've also experienced that the jar file which prevails and gets deployed in the web app is not stable across platforms (eclipse running on windows and mac do not end up including the same jar file). In all cases you will be missing a dependency which may end up having serious consequences at runtime.
Comment 1 Sune Wettersteen CLA 2011-08-10 10:17:27 EDT
Created attachment 201243 [details]
A web deployment assembly containing two dependencies with the same artifact ID which results in identical (and thus conflicting) deployment names
Comment 2 Matthew Piggott CLA 2011-08-10 10:37:40 EDT
m2e-wtp isn't part of the Eclipse project, issues for it should be filed at: https://issues.sonatype.org/browse/MECLIPSEWTP
Comment 3 Sune Wettersteen CLA 2011-08-10 11:08:07 EDT
Thanks, I will file the report with them instead :)
Comment 4 Denis Roy CLA 2021-04-19 13:24:29 EDT
Moved to https://github.com/eclipse-m2e/m2e-core/issues/