Search code examples
mavenmaven-assembly-plugin

Exclude persistence.xml file from transitive Maven dependency


I am having a Maven project that randomly pulls one of the persistence.xml files from the transitive Maven dependencies. How can I configure the dependency to exclude its persistence.xml file?

For clarity, I'll elaborate this issue further:

I have a Maven project A. The pom file of A has a dependency B which in turn has dependencies C and D (A, B, C, and D are related projects) along with other dependencies. Projects C and D each have different persistence.xml files. So, when I build the project A after building projects B, C, and D, a persistence.xml file is randomly picked up from either C or D, and packaged with project A. I want to ensure that only the persistence.xml file from project C gets packaged in project A. How do I do this?

I can add more information if required.


Solution

  • If the dependency includes a persistence.xml which usually is a bad idea you can not exclude that file on a dependency level.

    The question is: Why is the persistence.xml file in the other projects?

    Furthermore it sounds like those projects are highly coupled. That sounds to me like a candidate for a multi module build (may be different thing).

    If you want to be sure to have the persistence.xml file from a particular dependency that means the persistence.xml file should be located in the project where you need it and not in dependant projects. (location in src/main/resources).