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?

有帮助吗?

解决方案

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.

其他提示

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.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top