Question

I have maven project with next modules: app, app-impl, web. I build web with maven-war-plugin. Now app-impl depends on app. web depends on app-impl.

But web should depends only on app. By some magic maven-war-plugin should include app-impl in war. Could I do it without additional maven module?

Was it helpful?

Solution

I absolutely agree with @Torsten, but maybe there is something valid in your request:

when using IDE to develop the project, you can require it to stop offering your implementation classes in code completion lists.

If this is your reason, just add both dependencies, and for the implementation one, specify <scope>runtime</scope>. This ensures that:

  • your app module get to classpath of javac, but app-impl does not
  • both app and app-impl will be placed under WEB-INF/lib/ in your war
  • IDE (if properly implemented) will not offer you completions from app-impl

This definitely does not save you keystrokes, but gives you a better pom, carefully modelling the reality.

OTHER TIPS

IMHO having a dependency on app in web does not reflect the reality, as your web-application really depends on having an implementation of the interfaces I assume you have defined in app.

Consider having an alternative implementation in lets say app-impl2. How can maven possibly decide which implementation it should choose?

So having web depend on app-impl is to me the way to go and given the above setup also should work out of the box.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top