简体   繁体   English

maven项目的多个pom文件

[英]Multiple pom files for a maven project

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. 在这些maven项目中,很少有项目(abc-codegen,stellar-codegen)用于代码生成。 the codegen artifacts are used by other maven modules such as abc-engine. codegen工件由其他maven模块使用,例如abc-engine。

the codegen modules may not be built everytime other application modules(abc-engine etc) are built and released. 每次构建和发布其他应用程序模块(abc-engine等)时,都可能无法构建codegen模块。

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. 我唯一需要做的就是告诉我的CI执行上述命令并在需要时触发部署工件。 whilst Other build (mvn clean install) will check the sanity of the code. 而其他构建(mvn clean install)将检查代码的完整性。 can we do this any other approach? 我们可以做任何其他方法吗?

Yes you can use Maven Profiles to manage this. 是的,您可以使用Maven配置文件来管理它。

Eg 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. 因此,您可以创建仅构建引擎项目的配置文件。

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

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