Reputation: 22974
I read few SO posts which uses mvn -pl module -am
In my case, the error is COULD NOT FIND THE SELECTED PROJECT IN THE REACTOR
Directory structure:
parent
pom.xml
sample1
pom.xml - has dependency on sample2
sample2
pom.xml
I just used relativePath
in each child's parent node in pom.xml
and similarly for parent's module part
mvn install -pl sample1 -amd
throws me that error.
mvn install -pl ../sample1 -amd
builds sample1 but not sample2. I came to the solution that it is not building by checking target directory. It is empty in sample2.
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)
Upvotes: 3
Views: 4589
Reputation: 1111
I replicated your error and it seems it has to do with the fact that you placed the parent in the same directory as the samples. I'm not sure but I believe this is a violation of maven's single root principle. Have a look at this blog post. It suggests splitting your parent in two and use a root pom containing the modules like this:
/pom.xml
/parent/pom.xml
/child1/pom.xml
Both the root pom as the child reference the parent as the parent. I tried this with the -pl and -amd flags and it seems to work.
Upvotes: 1