thanks all. this is helpful info to know. On Thu, Feb 15, 2024 at 1:22 PM Tamás Cservenák <ta...@cservenak.net> wrote:
> Howdy, > > usually you should consider maven build (in case maven, session == cli > invocation) as this hierarchy: > * remote repositories: > * * local repository: > * * * session > > Maven will prefer things "most specific" if present: > - if is in reactor (current session), will use that > - if is in local repository (and all things like expiration etc passes) > will use that > - otherwise it goes to remote > > This also implies if you want to build A and then B from _same multi module > build_ (that has let's assume modules A, B and C), ideally you > * maven install all the reactor > * maven -f A compile > etc > > > On Thu, Feb 15, 2024 at 9:28 PM Francois Marot <francois.ma...@gmail.com> > wrote: > > > to add on Joseph answer: if you are in the B directory, then only B is in > > the reactor (more or less meaning "the list of project being built by > this > > Maven invocation"). > > My rule of thumb is to never do that and always run from the root. If you > > want to speedup the build and you know that only B has been modified, you > > can use maven options such as: > > > > - mvn test -pl :B // it will only build/test the B module > > - mvn test -pl :B -am // it will build B and all the modules B > > depends onto > > - mvn test -rf :B // it resumes the build from B in case B's > > tests failed , so it will also build modules after B > > > > you can note that I add a semi-column before the module name because in > > case the module is a sub-module (or sub-sub-sub...module), not directly > at > > the parent's root, then it is required. > > Hope this helps > > > > > > Le jeu. 15 févr. 2024 à 20:55, Joseph Leonard < > > joseph.leon...@alfasystems.com> a écrit : > > > > > Builds in the reactor are always favoured over the m2 repo because the > > > builds in the reactor will be up-to-date whereas the jar in the repo > may > > be > > > out of date. > > > > > > If you run mvn compile in directory B then you will not be running a > > multi > > > module build - and therefore module A will not be in the reactor. This > is > > > why the m2 repo will always be used for module A in this scenario. > > > > > > Joe > > > > > > -----Original Message----- > > > From: Siddharth Jain <siddh...@gmail.com> > > > Sent: Thursday, February 15, 2024 7:50 PM > > > To: Maven Users List <users@maven.apache.org> > > > Subject: Re: How does maven resolve inter-module dependencies in a > > > multi-module build? > > > > > > External Email: Please be vigilant and check the contents and source > for > > > signs of malicious activity. > > > > > > thanks Joe. but then if classes are available both in the target > > directory > > > of module A as well as a jar file in M2 repository which takes > > precedence? > > > > > > also i have noticed that while running mvn compile from the root works, > > > running mvn compile from the directory of B does not pick up classes > from > > > A's target directory. it only picks up from M2 repo in that case. > > > > > > On Thu, Feb 15, 2024 at 11:28 AM Joseph Leonard < > > > joseph.leon...@alfasystems.com> wrote: > > > > > > > Hi Sid, > > > > It will resolve the classes directory of module A that will have been > > > > populated during module A's 'compile' build. > > > > Joe > > > > > > > > On 2024/02/15 17:50:44 Siddharth Jain wrote: > > > > > Hello, > > > > > > > > > > I am working on a multi-module Maven build. e.g., I have a root > > > > > directory containing 3 sub-projects A, B, C and a parent pom > defined > > > > > in the root directory. I notice that I can run mvn compile from the > > > > > root directory > > > > and > > > > > it will build the 3 projects. The projects may have > > > > > inter-dependencies e.g., B depends on A and let's say C depends on > > > both A and B. > > > > > > > > > > My question is while building B how does maven locate the compiled > > > > > code > > > > of > > > > > A (the dependency) since maven compile by itself does not install > > > > > the > > > > built > > > > > artifact into M2 repository? > > > > > > > > > > Sid > > > > > > > > > > > > > > >