custom pom.xml filename in maven multimodule
Asked Answered
S

3

13

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)

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.

Context

  • I'm working on a closed source project that also use LGPLed projects. this project is called main

  • 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.

  • 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.

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

The problem

  • 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).

  • 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.

How to solve this ?

  • 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.

  • 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 ?

Directory of the Main Reactor Project

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]

Directory of the LGPL Reactor Project

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]

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 of 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>

assembly.xml of 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>
Soakage answered 24/8, 2012 at 2:13 Comment(4)
Can't you tell us what that strange reason is? That would probably help us to understand why you need this and then maybe come up with a solution.Charwoman
Ok, i have added some details ...Soakage
What about the custom pom route did not work for you? In the multi-module manifest, you can specify the custom POM file name of the child artifact.Mccartney
This is answered here - https://mcmap.net/q/906926/-custom-pom-xml-filename-in-maven-multimodule-for-tychoLympho
N
11

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

mvn -f <path>/pom.xml clean install
Neidaneidhardt answered 26/9, 2013 at 7:18 Comment(0)
S
3

I would suggest to change the folder structure into the following.

root (pom.xml)
  +-- closed-core
  +-- closed-web
  +-- closed-webserver
  +-- closed-spring
  +-- lgpl-reactor
         +-- lgpl-lib
         +-- lgpl-dist
         +-- lgpl-etc..

Than you don't need a separte module-pom.xml file. You can work with pom.xml as default.

If you wan't to build lgpl-reactory you can simply give:

mvn -pl lgpl-reactory clean package 

if you have dependencies within the other modules to lgpl you can use:

mvn -am -pl lgpl-reactory clean package 

This will build also all dependent modules.

Spelunker answered 24/8, 2012 at 9:37 Comment(5)
Problem is that the root pom.xml won't be published as LGPL and won't be available on the github repository of lgpl-reactor ... So, user cloning the lgpl-reactor from GitHub can't do that to build the project, they only have the lgpl-reactor directory.Soakage
Closed code source is on a private Git repository. lgpl-reactor directory is on a public GitHub repository. I can publish a copy of the root pom.xml as LGPL in the github repository, you are right.Soakage
Than the best thing would be to make a separate lgpgl project which will be released separately and your closed source part. Than you have no problems.Spelunker
Yes i think i'll choose this solution, but it less convenient in the eclipse environment to work with both project. But maven seems not to be designed to have in the same project differents repositories for differents parts/license. (I imagine other problems with maven:release plugin for example, it can't work properly with 2 different repositories ...)Soakage
release plugin is really an argument. In Eclipse you can put those two project into eclipse and turn on workspace resolution (which is by default as far as i know).Spelunker
S
0

A solution is to apply the inverse logic, and use "mvn -f standalone-pom.xml clean package" to build lgpl-reactor as a standalone project ... But it'll be better if standalone project is build with a standard maven2 command line.

Soakage answered 24/8, 2012 at 9:32 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.