简体   繁体   English

如何在多模块Maven项目中编译其中的单个模块?

[英]How to compile a single module inside it in a multi-module maven project?

This is how the project may looks like: 这是该项目的外观:

  • moduleA moduleA

    -- pom.xml -pom.xml

  • moduleB moduleB

    -- pom.xml -pom.xml

  • pom.xml 的pom.xml

moduleA has a dependency on moduleB. moduleA对moduleB有依赖性。 I have set <modules> in the parent pom.xml and other configurations in the child pom.xmls. 我在父pom.xml中设置了<modules> ,在子pom.xmls中设置了其他配置。 And I can run mvn package in the parent dir, but every time I run mvn package in the directory of moduleA it fails. 而且我可以在父目录中运行mvn package ,但是每次我在moduleA目录中运行mvn package都会失败。

I know that running mvn package -pl moduleA in the parent directory can fix the problem. 我知道在父目录中运行mvn package -pl moduleA可以解决此问题。 Since Apache Flume allows me to compile any single module in its own directory, why can't my project? 由于Apache Flume允许我在其自己的目录中编译任何模块,所以为什么我的项目不能?

Instead of launching goal "package", launch goal "install" on the root pom (or just moduleB). 代替启动目标“包”,而是在根pom(或仅是moduleB)上启动目标“安装”。 This will place moduleB in the local repository (~/.m2/repository) and Maven will be able to fetch it when it compiles only moduleA. 这会将moduleB放置在本地存储库(〜/ .m2 / repository)中,当Maven仅编译moduleA时,它将能够获取它。 Then you'll be able to compile only moduleA. 然后,您将只能编译moduleA。

I had this issue: maven session does not declare a top level project 我遇到了这个问题: Maven会话未声明顶级项目

when I'm trying to run one module through command line like :- mvn clean install -pl moduleA where it was looking for parent module, So I've tried this & it worked with :- mvn clean install -pl .,moduleA in your case you can try this assuming dependency is already build & available in maven repo, else mvn clean install -pl .,moduleA --also-make should work. 当我尝试通过命令行运行一个模块时,例如: mvn clean install -pl moduleA在寻找父模块的地方,因此,我尝试了此方法,并与: mvn clean install -pl .,moduleA一起使用您的情况下,您可以尝试此假设mvn clean install -pl .,moduleA --also-make是依赖关系已经在Maven mvn clean install -pl .,moduleA --also-make建立并且可用,否则mvn clean install -pl .,moduleA --also-make应该可以工作。 This will build only one specific project in multi-module maven project & as we've specified "." 这将在多模块Maven项目和我们指定的“。”中仅构建一个特定项目。 it would build parent pom which resolved the issue. 它会建立父pom来解决问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM