maven multimodule中的自定义pom.xml文件名 [英] custom pom.xml filename in maven multimodule

查看:125
本文介绍了maven multimodule中的自定义pom.xml文件名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个maven3多模块项目,由于一个奇怪的原因,我需要为我的一个子模块自定义POM文件名(即:module-pom.xml)

I have a maven3 multimodule project, and for a strange reason i need to customize POM filename for one of my child module (ie: module-pom.xml)

是否可以在父pom中配置它?

Is it possible to configure this in the parent pom ?

奇怪的原因有点长,以解释抱歉,但你将有简单的背景。

The strange reason is a bit long to explain sorry, but you will have the plain context.

上下文


  • 我正在努力闭源项目,也使用LGPLed项目。这个项目名为 main

我想 main 声明每个项目的模块,关闭和打开。完整版本应使用唯一的 mvn clean package 命令。

I want main to declare modules of every projects, closed and opened. The full build should be made with a unique mvn clean package command.

在<$ c内$ c> main reactor项目,我有 lgpl-reactor 包含3个LGPL模块的多模块项目(API,插件和分发项目)。有些开发人员只能访问 lgpl-reactor ,所以我也希望这个项目从其文件夹中构建 mvn clean package 命令,就像一个完全独立的项目。

Inside the main reactor project, i have lgpl-reactor multimodule project containing 3 LGPL modules (API, Plugins and Distribution project). Some developper will have access to lgpl-reactor only, so i also want this project to build from its folder with mvn clean package command, like a fully standalone project.

我还有 main-dist 项目一个maven-assembly-plugin only项目(用于构建发行版)。

I also have main-dist project that is a maven-assembly-plugin only project (to build the distribution).

问题


  • 如果我将父引用添加到 lgpl-reactor pom。 xml,全局 main 构建工作完美,由 main-dist 创建的程序集是有效的,但是独立构建的lgpl-reactor失败(未找到主pom.xml)。

  • If I add parent reference to lgpl-reactor pom.xml, the global main build works perfectly, and assembly created by main-dist is valid, but the standalone build of lgpl-reactor fails (main pom.xml not found).

如果我从 lgpl-reactor pom.xml,独立的 lgpl-reactor 构建工作,但由 main-dist 创建的程序集不是有效(缺失。

If I remove parent reference from lgpl-reactor pom.xml, the standalone lgpl-reactor build works, but assembly created by main-dist is NOT valid (missing.

如何解决这个问题?


  • 使用a其他POM文件 module-pom.xml 用于 lgpl-reactor main 模块内的模块声明声明清单。当从 main 项目执行完整版本时, module-pom.xml 包含对父POM的引用并且正常工作。

  • use another POM file module-pom.xml for lgpl-reactor module declaration inside main modules declaration list. When perfoming the full build from main project, module-pom.xml contains reference to parent POM and is working properly.

使用默认的POM文件 pom.xml 进行 lgpl-reactor 。这个POM很难用< parent> 标签

use the default POM file pom.xml for standalon build of lgpl-reactor. This POM can hardly reference the parent pom with the relativePath property of <parent> tag

但我怎么能这样做?如果可能的话 ?或者有更好的解决方案吗?

But HOW can i do that ? if possible ? Or is there any better solution ?

主要反应堆项目目录

lgpl-lib [LGPL Library]
lgpl-ext [LGPL Reactor Project]
closed-core [Closed source module]
closed-spring [Closed source module]
closed-web [Closed source module]
closed-webserver [Closed source module]
main-dist [Main assembly module]
pom.xml [Main Reactor POM]

LGPL反应堆项目目录

lgpl-api [LGPL API module]
lgpl-plugins [LGPL Plugins module]
lgpl-ext-dist [LGPL assembly module]
main-pom.xml [Main Reactor POM, copy of main pom.xml]
pom.xml [Standalone LGPL Reactor POM]
module-pom.xml [Module LGPL Reactor POM]

主反应堆POM (pom.xml & lgpl-reactor / main-pom.xml)

Main Reactor POM (pom.xml & lgpl-reactor/main-pom.xml)

    ...
    <modelVersion>4.0.0</modelVersion>
    <groupId>main.group</groupId>
    <artifactId>main</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>Main</name>
    <packaging>pom</packaging>
    ...
    <modules>
        <module>closed-core</module>
        <module>closed-web</module>
        <module>closed-webserver</module>
        <module>closed-spring</module>
        <module>lgpl-reactor</module>
        <module>lgpl-lib</module>
        <module>main-dist</module>
    </modules>
    ...

lgpl-reactor / pom.xml

...
<modelVersion>4.0.0</modelVersion>
<artifactId>lgpl-reactor</artifactId>
<name>LGPL Reactor</name>
<packaging>pom</packaging>

<parent>
    <groupId>main.group</groupId>
    <artifactId>main</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <relativePath>main-pom.xml</relativePath>
</parent>
...
    ...
<modules>
    <module>lgpl-api</module>
    <module>lgpl-plugins</module>
    <module>lgpl-ext-dist</module>
</modules>
    ...

pom.xml main-dist

<project>
    <parent>
        <groupId>main.group</groupId>
        <artifactId>main</artifactId>
        <version>0.0.1-SNAPSHOT</version>
    </parent>
    <artifactId>main-dist</artifactId>

    <packaging>pom</packaging>

    <description>Main Distribution</description>

    <build>
        <plugins>
            <plugin>
                <artifactId>maven-assembly-plugin</artifactId>
                <executions>
                    <execution>
                        <id>plugins-assembly</id>
                        <phase>package</phase>
                        <goals>
                            <goal>single</goal>
                        </goals>
                        <configuration>
                            <descriptors>
                                <descriptor>assembly.xml</descriptor>
                            </descriptors>
                            <appendAssemblyId>false</appendAssemblyId>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

    <dependencies>
        <dependency>
            <groupId>closed</groupId>
            <artifactId>closed-webserver</artifactId>
            <version>0.0.1-SNAPSHOT</version>
        </dependency>
        <dependency>
            <groupId>closed</groupId>
            <artifactId>closed-api</artifactId>
            <version>0.0.1-SNAPSHOT</version>
        </dependency>
    </dependencies>
</project>

main-dist的汇编文件

<assembly
    xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2 http://maven.apache.org/xsd/assembly-1.1.2.xsd">
    <id>plugins-assembly</id>
    <formats>
        <format>dir</format>
        <format>zip</format>
    </formats>
    <includeBaseDirectory>false</includeBaseDirectory>

    <fileSets>
        <fileSet>
            <directory>../closed-webserver/conf</directory>
            <outputDirectory>conf</outputDirectory>
        </fileSet>
    </fileSets>

    <dependencySets>
        <dependencySet>
            <excludes><exclude>main.group:closed-webserver</exclude></excludes>
            <outputDirectory>lib</outputDirectory>
        </dependencySet>
    </dependencySets>

    <moduleSets>
        <moduleSet>
            <useAllReactorProjects>true</useAllReactorProjects>

            <includes>
                <include>main.group:closed-webserver</include>
            </includes>

            <binaries>
                <outputFileNameMapping>${module.artifactId}${dashClassifier?}.${module.extension}</outputFileNameMapping>
                <unpack>false</unpack>
                <includeDependencies>false</includeDependencies>
            </binaries>
        </moduleSet>

        <moduleSet>
            <useAllReactorProjects>true</useAllReactorProjects>

            <includes>
                <include>main.group:closed-spring</include>
            </includes>

            <binaries>
                <outputFileNameMapping>${module.artifactId}${dashClassifier?}.${module.extension}</outputFileNameMapping>
                <unpack>false</unpack>
                <includeDependencies>false</includeDependencies>
            </binaries>

        </moduleSet>

        <moduleSet>
            <useAllReactorProjects>true</useAllReactorProjects>

            <includes>
                <include>main.group:lgpl-ext-dist</include>
            </includes>

            <binaries>
                <outputDirectory>plugins</outputDirectory>
                <unpack>false</unpack>
                <includeDependencies>true</includeDependencies>
            </binaries>

        </moduleSet>
    </moduleSets>

</assembly>


推荐答案

您可以覆盖默认的pom.xml。 Maven有-f命令选项。

You can override default pom.xml. Maven have -f command option.

mvn -f <path>/pom.xml clean install

这篇关于maven multimodule中的自定义pom.xml文件名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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