2016-08-13 34 views
0

我繼承了一個maven項目,其結構有點混亂。 父文件夾中有一個home pom.xml文件,而另一個文件夾位於子文件夾中。這種結構有點令人困惑,因爲除了管理孩子之外,父母沒有任何內容。Mergin pom.xml與父類

有沒有辦法將兩者合併?我嘗試手動,但失敗。我認爲我的問題在於Tycho和eclipse插件。

這裏是孩子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> 

和家長的是:

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

回答

1

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

然後,在子項中刪除(或移動)pom.xml,並將 子文件夾中的所有內容移動到父文件夾。 (如果不刪除它,可能會覆蓋父項中的pom.xml。)