如何在Tycho中使用相同的目标平台多个子项目

gos*_*sua 5 tycho maven

是否可以为每个maven子项目使用相同的.target文件?

来自父.pom文件的代码段

<groupId>root.server</groupId>
<artifactId>root.server</artifactId>
Run Code Online (Sandbox Code Playgroud)

来自子.pom文件的片段

<groupId>child.project</groupId>
<artifactId>child.project.parent</artifactId>

                <target>
                    <artifact>
                        <groupId>root.server</groupId>
                        <artifactId>root.server</artifactId>
                        <version>${project.version}</version> 
                        <classifier>targetfile</classifier>
                    </artifact>
                </target>
Run Code Online (Sandbox Code Playgroud)

当我在子项目中尝试"mvn clean install"时,我得到一个例外:Could not resolve target platform specification artifact.当我在子项目的父项中尝试"mvn clean install"时,一切正常.

有没有办法为所有项目(父+子项目)重用一个.target文件?

Sim*_*mon 10

它是可能的,它是首选的方法.

您应该专门为您的.target文件创建一个子模块(例如,称为目标定义).这应该是具有pom包装类型的项目.您还应该包含以下代码段 - 这是允许其他模块访问.target文件的部分:

  <plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>build-helper-maven-plugin</artifactId>
    <version>1.3</version>
    <executions>
      <execution>
        <id>attach-artifacts</id>
        <phase>package</phase>
        <goals>
          <goal>attach-artifact</goal>
        </goals>
        <configuration>
          <artifacts>
            <artifact>
              <file>targetFilename.target</file>
              <type>target</type>
        <classifier>targetFilename</classifier>
            </artifact>
          </artifacts>
        </configuration>
      </execution>
    </executions>
  </plugin>
Run Code Online (Sandbox Code Playgroud)

现在在您的父pom中,您可以在target-platform-configuration中引用此模块,您的子模块也将使用它:

<plugin>
  <groupId>org.eclipse.tycho</groupId>
  <artifactId>target-platform-configuration</artifactId>
  <version>${tycho-version}</version>
  <configuration>
    <target>
      <artifact>
         <groupId>org.example</groupId>
         <artifactId>target-definition</artifactId>
         <version>1.0.0-SNAPSHOT</version>
         <classifier>targetFilename</classifier>
      </artifact>
    </target>
  </configuration> 
</plugin>
Run Code Online (Sandbox Code Playgroud)

还有一个增强请求,可以为.target文件创建包装类型,以便将来提供帮助.