在Maven多模块项目中构建单个模块 [英] Build a single module in maven multi-module project

查看:1296
本文介绍了在Maven多模块项目中构建单个模块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我读了一些使用mvn -pl module -am的SO帖子,错误是COULD NOT FIND THE SELECTED PROJECT IN THE REACTOR

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

目录结构:

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

我只是在each child's parent node in pom.xml中使用了relativePath,对于parent's module part

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

向我抛出该错误.

   mvn install -pl ../sample1 -amd

生成sample1,但不生成sample2.我通过检查目标目录来解决它不是正在构建的解决方案.在sample2中为空.

builds sample1 but not sample2. I came to the solution that it is not building by checking target directory. It is empty in sample2.

有什么建议吗?

   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)

推荐答案

我复制了您的错误,这似乎与您将父项放置在与示例相同的目录中有关.我不确定,但我相信这违反了Maven的单根原则.看看

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

root pom作为子代都引用父代作为父代.我用-pl和-amd标志尝试了这一点,它似乎起作用了.

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.

这篇关于在Maven多模块项目中构建单个模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆