Maven (Tycho) With RCP Application

1. What is Maven
Maven is a build automation tool used primarily for Java projects.
Maven's primary goal is to allow a developer to comprehend the complete state of a development effort in the shortest period of time. In order to attain this goal there are several areas of concern that Maven attempts to deal with.
  • Making the build process easy
  • Providing a uniform build system
  • Providing quality project information
  • Providing guidelines for best practices development
  • Allowing transparent migration to new features
2. What is Tycho
Eclipse Tycho is a set of Apache Maven plug-ins for building Eclipse components. It supports build of Eclipse plug-ins, features, update sites and products.

Tycho uses the metadata of the Eclipse components in the MANIFEST.MF file as much as possible. This leads to relative small pom.xml configuration files.

3. What is POM
Maven projects are configured using a Project Object Model, which is stored in a pom.xml file. Eclipse project create one Master POM file and all other POMs extend the Master POM unless explicitly set, meaning the configuration specified in the Master POM is inherited by the POMs you created for your projects.
Master pom.xml file looks like the following:

<?xml version="1.0" encoding="UTF-8"?>
<project>
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.vogella</groupId>
  <artifactId>parent</artifactId>
  <version>1.0.0-SNAPSHOT</version>
  <packaging>pom</packaging>
  <modules>
    <module>../com.test.tycho.plugin</module>
    <module>../com.test.tycho.feature</module>
    <module>../com.test.tycho.p2updatesite</module>
    <module>../com.test.tycho.plugin.tests</module>
  </modules>

  <properties>
    <tycho.version>0.20.0</tycho.version>
    <kepler-repo.url>http://download.eclipse.org/releases/kepler</kepler-repo.url>
  </properties>

  <repositories>
    <repository>
      <id>kepler</id>
      <url>${kepler-repo.url}</url>
      <layout>p2</layout>
    </repository>
  </repositories>

  <build>
    <plugins>
      <plugin>
        <groupId>org.eclipse.tycho</groupId>
        <artifactId>tycho-maven-plugin</artifactId>
        <version>${tycho.version}</version>
        <extensions>true</extensions>
      </plugin>

      <plugin>
        <groupId>org.eclipse.tycho</groupId>
        <artifactId>target-platform-configuration</artifactId>
        <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>
    </plugins>
  </build>
</project>

3.1 Package attribute

The package attribute defines which components should be created by Tycho. For more details See Packaging_Types.

Package Attribute Description
eclipse-plugin Used for Plug-ins
eclipse-feature Used for features
eclipse-repository Used for update sites and Eclipse products

3.2 Source Encoding
You can set the source code encoding via the project.build.sourceEncoding parameter.

<properties>
<properties>
 <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties> 

4. Eclipse Configuration For Setup Tycho
For integration of Maven and Tycho into Eclipse, a Tycho m2e connector is needed.
Go to Preferences->Maven->Discovery and click on Open Catalog. Find and select the Tycho Configurator.



5. Building Eclipse components
lips
5.1. Create Master Maven project for the build
Create a new General/Project named com.test.tycho.releng and convert it to a maven project by selecting Configure/Convert to Maven Project from the context menu.


Group Id: Group Id is similar to package names in Java, all projects that belong together will get the same Group Id.
Artifact Id: The Artifact Id is the name of the project. It should match the Bundle-SymbolicName found in MANIFEST.MF.
Version No: It should be set accordingly to Bundle-Version from the manifest.
Packaging: has to be set to pom for in order to specify that this project consists only of a pom.xml file


5.2 Add common property to master pom files
Add the properties, repositories and build section to master POM file as give below

<?xml version="1.0" encoding="UTF-8"?>
<project>
  <modelVersion>4.0.0</modelVersion>
  <groupId>test.tycho</groupId>
  <artifactId>com.test.tycho.releng</artifactId>
  <version>1.0.0-SNAPSHOT</version>
  <packaging>pom</packaging>

  <properties>
    <tycho.version>0.20.0</tycho.version>
    <kepler-repo.url>http://download.eclipse.org/releases/kepler</kepler-repo.url>
  </properties>

  <repositories>
    <repository>
      <id>kepler</id>
      <url>${kepler-repo.url}</url>
      <layout>p2</layout>
    </repository>
  </repositories>

  <build>
    <plugins>
      <plugin>
        <groupId>org.eclipse.tycho</groupId>
        <artifactId>tycho-maven-plugin</artifactId>
        <version>${tycho.version}</version>
        <extensions>true</extensions>
      </plugin>

      <plugin>
        <groupId>org.eclipse.tycho</groupId>
        <artifactId>target-platform-configuration</artifactId>
        <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>
    </plugins>
  </build>
</project> 

5.3 Pom for plug-in project
Select plugin project and convert it into maven project as described in 5.1 with only Packaging change.
For plugin change Packaging to eclipse-plugin. 

After converting Pulgin-project you need to add this project into master POM.

  1. Open the Overview tab of com.test.tycho.releng/pom.xml and Add... a Module. Select the com.test.tycho.plugin.
  2. Check Update POM parent section in selected projects.


After add plugin project into master Pom make sure your plugin pom look like below.

<?xml version="1.0" encoding="UTF-8"?>
<project>
  <modelVersion>4.0.0</modelVersion>
  <parent>
    <relativePath>../com.test.tycho.releng/pom.xml</relativePath>
    <groupId>test.tycho</groupId>
    <artifactId>parent</artifactId>
    <version>1.0.0-SNAPSHOT</version>
  </parent>

  <artifactId>com.test.tycho.plugin</artifactId>
  <packaging>eclipse-plugin</packaging>
</project> 

5.4 Pom for feature project
Select plugin project and convert it into maven project as described in 5.1 with only Packaging change.
For plugin change Packaging to eclipse-feature. 


After converting Pulgin-project you need to add this project into master POM as described above for plugin project.

After add plugin project into master Pom make sure your plugin pom look like below.

<?xml version="1.0" encoding="UTF-8"?>
<project>
  <modelVersion>4.0.0</modelVersion>
  <parent>
    <relativePath>../com.test.tycho.releng/pom.xml</relativePath>
    <groupId>test.tycho</groupId>
    <artifactId>parent</artifactId>
    <version>1.0.0-SNAPSHOT</version>
  </parent>
  
  <artifactId>com.test.tycho.feature</artifactId>
  <packaging>eclipse-feature</packaging>
</project> 

6. Build
Right click on the project and select Run As/Maven build... Under Goals enter clean install.


After running your consol view look like following

[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.575s
[INFO] Finished at: Fri May 23 16:18:15 IST 2014
[INFO] Final Memory: 2M/15M
[INFO] ------------------------------------------------------------------------

No comments :

Post a Comment