Time for action – creating a parent project

It's common for the parent and child projects to be located outside the workspace; for historical reasons, Eclipse doesn't deal well with nested projects in the workspace. It's also common for the parent project to host all of the Tycho configuration information, which makes setting up the child projects a lot easier.

  1. Create a General project by navigating to the File | New | Project | General | Project menu.
  2. Unselect Use default location.
  3. Put in a location that is outside the Eclipse workspace.
  4. Name the project com.packtpub.e4.parent.
  5. Click on Finish.
  6. Create a new file pom.xml in the root of the project.
  7. Copy the content of the com.packtpub.e4.clock.ui plug-in's pom.xml file to the parent, but change the artifactId to com.packtpub.e4.parent and the packaging to pom.
  8. Create a properties element in the pom.xml file and inside a tycho.version element with the value 0.25.0, as well as an eclipse element with the value http://download.eclipse.org/releases/neon/.
  9. Modify the reference to 0.25.0 in the existing Tycho plugin and replace it with ${tycho.version}.
  10. Modify the reference to http://download.eclipse.org/releases/neon/ in the existing repositories url and replace it with ${eclipse}.
  11. Move the com.packtpub.e4.clock.ui plug-in underneath the parent project.
  12. Add a modules element to the pom.xml file and underneath a module element with the value com.packtpub.e4.clock.ui.
  13. The parent pom.xml file should look like:
    <?xml version="1.0" encoding="UTF-8"?>
    <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>
      <groupId>com.packtpub.e4</groupId>
      <artifactId>com.packtpub.e4.parent</artifactId>
      <version>1.0.0-SNAPSHOT</version>
      <packaging>pom</packaging>
      <properties>
        <tycho.version>0.25.0</tycho.version><eclipse>http://download.eclipse.org/releases/neon/</eclipse>
      </properties>
      <modules>
        <module>com.packtpub.e4.clock.ui</module>
      </modules>
      <build>
        <plugins>   
          <plugin>          
            <groupId>org.eclipse.tycho</groupId>
            <artifactId>tycho-maven-plugin</artifactId>
            <version>${tycho.version}</version>
            <extensions>true</extensions>
          </plugin>
        </plugins>
      </build>
      <repositories>
        <repository>
          <id>eclipse</id>
          <layout>p2</layout>
          <url>${eclipse}</url>
        </repository>
      </repositories>
    </project>
  14. Modify the com.packtpub.e4.clock.ui/pom.xml file and add a parent element with a groupId, artifactId, and version that are the same as the parent. It is possible to remove the version and groupId from the child pom.xml file, as it will default to the parent's groupId and version if not specified:
    <parent>
      <groupId>com.packtpub.e4</groupId>
      <artifactId>com.packtpub.e4.parent</artifactId>
      <version>1.0.0-SNAPSHOT</version>
    </parent>
  15. Remove the plugins and repositories elements from the pom.xml file in the com.packtpub.e4.clock.ui project.
  16. Now change into the parent project and run mvn clean package. The parent will be built, and in turn build all the modules in the list:
    [INFO] Reactor Summary:
    [INFO]
    [INFO] com.packtpub.e4.parent ............ SUCCESS [0.049s]
    [INFO] com.packtpub.e4.clock.ui .......... SUCCESS [1.866s]
    [INFO]
    [INFO] BUILD SUCCESS
    

What just happened?

Each plug-in is its own Eclipse project, and therefore its own Maven project. To build a set of projects together, there needs to be a parent POM, which acts as an aggregator.

At build time, Maven calculates the order in which projects need to be built, and then arranges the build steps appropriately.

The other benefit provided by a parent pom.xml file is the ability to specify standard build plug-ins and configuration information. In this case, the parent specifies the link with Tycho and its versions. This simplifies the implementation of the other plug-ins and features that lie underneath the parent project.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
13.59.61.119