custom pom.xml filename in maven multimodule

java, maven-2, maven-3

Solution

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

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

Problem

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

Original source

Related problems