---- [EMAIL PROTECTED] schrieb: > Hi, > > I´ve read about dependencyManagement, versions, version ranges and so on. > But still I have some questions: > > Following example: > > A1.0 references B1.0 > A1.0 references C1.0 > B1.0 references C2.0 > > which version of C will be used (packed in a war for example) in this > scenario, if A is a module of type war, ear or zip ? > how can I fail the build or trace at least a warning that there´s the same > artifact, but in different versions?
A version declaration like <version>1.1</version> effectively says "I don't really care what version of this dependency is used, but I have a mild preference for version 1.1". When building module A, if all references to a library use this form, then Maven will use the declaration "closest to" pom A to select the actual version used. So in your example, if all the declarations are of the above form, then when compiling module A, C1.0 will be used because it is referenced directly from the pom for module A. However the form "[x.y]" can be used to specify that only that version is acceptable. So if B declares its dependency on C as <version>[2.0]</version> then I *believe* that when compiling A, C2.0 will be used (because A has used the form that says it doesn't really care). If A declares <version>[1.0]</version> but B declares <version>[2.0]</version> then an error is reported and the build fails, because there is no version that can satisfy them both. In general, version dependencies should be specified in the least-constrained form possible. Certainly *libraries* should avoid [x.y] type constraints if possible, as it makes it very difficult to combine that lib with anything else. In your case, if A is actually an application (not a library) then specifying dependencies with [x.y] seems to be what you want; you will get exactly that version, or the build will fail if a dependency declares that it is not compatible with that version. But if A is a library, then don't even try; libraries have no right to force specific versions on users of that library. The most they should do is declare minimum supported versions, with something like: <version>[1.3,]</version> You may find the commands mvn dependency:list mvn dependency:tree useful in tracking what depends on what. NB: I'm no great expert on this area; double check before trusting my comments on this :-) Regards, Simon --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
