Java Maven 项目的多个 pom 文件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/22452133/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Multiple pom files for a maven project
提问by Selvakumar Esra
i have a project which has multiple maven project and 1 parent pom which has all other projects as maven modules.
我有一个项目,其中有多个 maven 项目和 1 个父 pom,其中所有其他项目都作为 maven 模块。
pom.xml
pom.xml
<modules>
<module>abc-codegen</module>
<module>stellar-codegen</module>
<module>abc-engine</module>
<module>stellar-engine</module>
</modules>
out of those maven projects few projects(abc-codegen, stellar-codegen) are used for code generation. the codegen artifacts are used by other maven modules such as abc-engine.
在这些 maven 项目中,很少有项目(abc-codegen、stellar-codegen)用于代码生成。其他 Maven 模块(例如 abc-engine)使用 codegen 工件。
the codegen modules may not be built everytime other application modules(abc-engine etc) are built and released.
每次构建和发布其他应用程序模块(abc-engine 等)时,可能不会构建代码生成模块。
pom-codegen.xml
pom-codegen.xml
<modules>
<module>abc-codegen</module>
<module>stellar-codegen</module>
</modules>
However, the codegen projects should remain inside the parent folder (svn/my-service/trunk) for the sake of consistency with other such applications.
但是,为了与其他此类应用程序保持一致,codegen 项目应保留在父文件夹 (svn/my-service/trunk) 中。
One of the idea i have is to create another pom file called as pom-codegen.xml under the parent folder and generate code when required by explicitely calling
我的一个想法是在父文件夹下创建另一个名为 pom-codegen.xml 的 pom 文件,并在需要时通过显式调用生成代码
mvn -f pom-codegen.xml clean deploy
The only i have to do is tell my CI to execute the above command and trigger deploy the artifact when required. whilst Other build (mvn clean install) will check the sanity of the code. can we do this any other approach?
我唯一要做的就是告诉我的 CI 执行上述命令并在需要时触发部署工件。而其他构建(mvn clean install)将检查代码的完整性。我们可以用其他方法做到这一点吗?
采纳答案by cowls
Yes you can use Maven Profiles to manage this.
是的,您可以使用 Maven 配置文件来管理它。
E.g. in the parent POM create a profiles section
例如在父 POM 中创建一个配置文件部分
<profiles>
<profile>
<id>aggregate-all</id>
<modules>
<module>abc-codegen</module>
<module>stellar-codegen</module>
<module>abc-engine</module>
<module>stellar-engine</module>
</modules>
</profile>
<profile>
<id>aggregate-codegen</id>
<modules>
<module>abc-codegen</module>
<module>stellar-codegen</module>
</modules>
</profile>
</profiles>
Now to build everything you run:
现在构建您运行的所有内容:
mvn clean install -P aggregate-all
To build just the code generation projects you run
仅构建您运行的代码生成项目
mvn clean install -P aggregate-codegen
Obviously you can tweak this approach to suit your needs however works best. So you could create a profile that builds just the engine projects.
显然,您可以调整此方法以满足您的需求,但效果最佳。因此,您可以创建一个仅构建引擎项目的配置文件。