在maven多模块项目中构建单个模块

时间:2015-06-09 04:41:15

标签: java maven

我看了几篇使用mvn -pl module -am的SO帖子在我的情况下,错误是COULD NOT FIND THE SELECTED PROJECT IN THE REACTOR

目录结构:

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

我刚刚在relativePath中使用each child's parent node in pom.xml,在parent's module part

中使用了 mvn install -pl sample1 -amd
   mvn install -pl ../sample1 -amd

将这个错误抛给我。

   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)

构建sample1但不构建sample2。我通过检查目标目录找到了它不构建的解决方案。它在样本2中是空的。

有什么建议吗?

{{1}}

1 个答案:

答案 0 :(得分:1)

我复制了你的错误,这似乎与你把父母放在与样本相同的目录中的事实有关。我不确定,但我认为这违反了maven的单根原则。看看this博文。它建议将父级分成两部分并使用包含以下模块的根pom:

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

作为子节点的根pom引用父节点作为父节点。我尝试使用-pl和-amd标志,它似乎有效。