Time for action – creating a parent project

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

  1. Create a General project by navigating to File | New | Project | General | Project.
  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 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. Inside, create two child tags: tycho-version (which has the content 0.18.0) and eclipse (with the value http://download.eclipse.org/releases/juno).
  9. Modify the reference to 0.18.0 in the existing Tycho plugin and replace it with ${tycho-version}.
  10. Modify the reference to http://download.eclipse.org/releases/juno 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 should look like:
    <?xml version="1.0" encoding="UTF-8"?>
    <project xsi:schemaLocation="http://maven.apache.org/
      POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" 
      xmlns="http://maven.apache.org/POM/4.0.0"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
      <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.18.0</tycho-version>
        <eclipse>http://download.eclipse.org/releases/
          juno</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>juno</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 also 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 of com.packtpub.e4.clock.ui.
  16. Now, change into the parent project and run mvn clean package. The parent will be built, which in turn builds 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.xml file, 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 accordingly.

The other benefit provided by a parent pom.xml 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