Building a single module in a multi-module maven project

I have read several SO posts that use mvn -pl module -am

In my case the error isCOULD NOT FIND THE SELECTED PROJECT IN THE REACTOR

Directory structure:

  parent  
      pom.xml
  sample1
      pom.xml - has dependency on sample2
  sample2
      pom.xml

      

I have used relativePath

in each child parent node in pom.xml

and similarly forparent module part

   mvn install -pl sample1 -amd

      

causes this error.

   mvn install -pl ../sample1 -amd

      

creates sample1, but not sample2. I ended up with a solution it doesn't create by checking the target directory. It is empty in smaple2.

Any suggestions?

   gopi@gopi-ThinkPad-T440s:~/learn/maven/parent$ mvn -e install -pl sample1 -amd
   [INFO] Error stacktraces are turned on.
   [INFO] Scanning for projects...
   [ERROR] Could not find the selected project in the reactor: sample1 -> [Help 1]
   org.apache.maven.MavenExecutionException: Could not find the selected project in the reactor: sample1
at org.apache.maven.DefaultMaven.trimSelectedProjects(DefaultMaven.java:749)
at org.apache.maven.DefaultMaven.createDependencyGraph(DefaultMaven.java:703)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:290)
at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:156)
at org.apache.maven.cli.MavenCli.execute(MavenCli.java:537)
at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:196)
at org.apache.maven.cli.MavenCli.main(MavenCli.java:141)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289)
at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)
at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415)
at   org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)

      

+3


source to share


1 answer


I reproduced your error and it seems to be due to the fact that you put the parent in the same directory as the samples. I'm not sure, but I believe this is a violation of the maven single root principle. Check out this blog post. He suggests splitting the parent in two and using root memory containing modules like this:

/pom.xml
/parent/pom.xml
/child1/pom.xml

      



Both pom roots as children refer to the parent as parent. I've tried this with the -pl and -amd flags and it seems to work.

+1


source







All Articles