jMn
jMn

Reputation: 238

Propagate provided dependency to dependent project

I have simple Maven project structure:

mainProject
|-- subProject1
|   |-- subSubProject
|-- subProject2

The point is that I have mainProject which contains dependencies used in each of subProjects (those dependencies are common for each subproject), but I don't want them to be included in my WAR file at the end when it's compiled and built (scope provided). Also, I don't want to declare dependencies in each of the subprojects since I already declared them in mainProject.

WAR file include all subproject libs in it's built files.

Thanks

Upvotes: 1

Views: 635

Answers (2)

saurav
saurav

Reputation: 3462

In my opinion there can be two solution for this problem.

1.) You can changed the scope to compile and while building the war file you can exclude all those jars that you don't want in your war file using maven-war-plugin like this.

<build>
<plugins>
  <plugin>
    <artifactId>maven-war-plugin</artifactId>
    <version>2.4</version>
    <configuration>
      <packagingExcludes>WEB-INF/lib/xyz.jar</packagingExcludes>
    </configuration>
  </plugin>
</plugins>

2.) If they are 3rd party specific jars then you can move them to server lib directory and at the run time your web container will provide the required classes.

Upvotes: 1

Eric Hydrick
Eric Hydrick

Reputation: 3527

I don't have a lot of experience with Maven, but I remember seeing parent poms listed in a file poms I've worked with. It seems you like you include your main project pom as a parent pom, and then also add the subproject-specific dependencies in their respective poms. I think the scope=provided in the parent pom will still keep the common dependencies from being the war file at the end.

Upvotes: 0

Related Questions