当前位置: 动力学知识库 > 问答 > 编程问答 >

How to create a maven assembly with transitive dependencies for different deployment scenarios?

问题描述:

I'm having a problem reconciling building a project for use within an application server and for use as a stand-alone application.

To give an overall simplified context, say I have three Projects A, B, C.

Project A depends on Project B which depends on Project C.

Project C has a dependency X which is marked as provided since it was expected that it would be available as a J2Ee library within say an application server. i.e. jms.jar.

So if I perform an assembly build of Project A, I get all the transitive dependencies save for those mark as provided as expected.

Now I have a new deployment scenario where Project A needs to be used in a standalone environment i.e. outside an application server.

So now I need the jms jar to be a compile dependency. Does this mean that I should explicitly add a compile dependency for X in Project A. Doesn't this violate the Law of Demeter i.e. don't talk to strangers, in the sense Project A shouldn't explicitly know about Project C but only about Project B.

This is a simple example but in reality I have multiple dependencies which have been marked as provided but are now need to be compile or runtime dependencies so they end up in the artifact produced by the maven assembly plugin.

Is this a fundamental problem with Maven or am I not using the tools correctly?

Thanks in advance for any guidance.

网友答案:

If you need your build to have variations in it for different scenarios, you need to use profiles and keep certain things (such as some of the dependencies) in the various profiles.

http://maven.apache.org/pom.html#Profiles

Different dependencies for different build profiles in maven

answers a similar question - but you can swap in the "release" and "debug" for "Project A" and "Project C"

分享给朋友:
您可能感兴趣的文章:
随机阅读: