合并 pom.xml 与 parent 的合并

Mergin pom.xml with that of parent

我继承了一个maven项目,它的结构有点混乱。 parent 文件夹中有一个主页 pom.xml,child 文件夹中还有一个。这个结构有点混乱,因为 parent 除了管理 child 之外什么也没有。

有没有办法合并两者?我尝试手动这样做但失败了。我认为我的问题出在 Tycho 和 eclipse 插件上。

这里是 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> 

而 parent 是:

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

在父pom.xml改变 <packaging>pom</packaging><packaging>eclipse-plugin</packaging>
<artifactId>my.project.foo.parent</artifactId><artifactId>my.project.foo</artifactId>

然后,擦除(或移动)子节点中的pom.xml,并移动所有内容 子文件夹到父文件夹。 (如果不删除它,它可能会覆盖父级中的 pom.xml。)