Yossi Gil Yossi Gil - 3 months ago 15
Java Question

Mergin pom.xml with that of parent

I inherited a

maven
project whose structure is a bit confusing.
There is one home pom.xml in the parent folder, and yet another one in a child folder. This structure is a bit confusing since there the parent has nothing in it, other than doing managing the child.

Is there a way to merge the two? I tried doing so manually but failed. I think my problem lies with Tycho and the eclipse plugin.

Here is the child
pom.xml
:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>my.project</groupId>
<artifactId>my.project.foo.parent</artifactId>
<version>2.4.0</version>
</parent>
<artifactId>my.project.foo</artifactId>
<packaging>eclipse-plugin</packaging>
</project>


And the parent is:

<?xml version="1.0" encoding="UTF-8"?>
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>my.project</groupId>
<artifactId>my.project.foo.parent</artifactId>
<version>2.4.0</version>
<packaging>pom</packaging>

<properties>
<tycho.version>0.24.0</tycho.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<mars-repo.url>http://download.eclipse.org/releases/mars</mars-repo.url>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>

<repositories>
<repository>
<id>mars</id>
<url>${mars-repo.url}</url>
<layout>p2</layout>
</repository>
</repositories>

<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>my.project</groupId>
<artifactId>my</artifactId>
<version>1.0</version>
</dependency>
<dependency>
<groupId>my.project</groupId>
<artifactId>cli</artifactId>
<version>1.0</version>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.eclipse.tycho</groupId>
<artifactId>tycho-maven-plugin</artifactId>
<version>${tycho.version}</version>
<extensions>true</extensions>
<configuration>
<encoding>UTF-8</encoding>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.eclipse.tycho</groupId>
<artifactId>target-platform-configuration</artifactId>
<version>${tycho.version}</version>
<configuration>
<environments>
<environment>
<os>linux</os>
<ws>gtk</ws>
<arch>x86</arch>
</environment>
<environment>
<os>linux</os>
<ws>gtk</ws>
<arch>x86_64</arch>
</environment>
<environment>
<os>win32</os>
<ws>win32</ws>
<arch>x86</arch>
</environment>
<environment>
<os>win32</os>
<ws>win32</ws>
<arch>x86_64</arch>
</environment>
<environment>
<os>macosx</os>
<ws>cocoa</ws>
<arch>x86_64</arch>
</environment>
</environments>
</configuration>
</plugin>
<plugin>
<groupId>org.eclipse.tycho</groupId>
<artifactId>tycho-packaging-plugin</artifactId>
<version>0.24.0</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.eclipse.tycho</groupId>
<artifactId>tycho-surefire-plugin</artifactId>
<version>${tycho.version}</version>
</plugin>
</plugins>
</build>
</project>

Answer

In the parent pom.xml change <packaging>pom</packaging> to <packaging>eclipse-plugin</packaging>
and <artifactId>my.project.foo.parent</artifactId> to <artifactId>my.project.foo</artifactId>

Then, erase (or move) pom.xml in the child, and move everything in the child folder to the parent folder. (If you do not erase it, it may override pom.xml in the parent.)

Comments