|
| 1 | +# Maven and Tycho |
| 2 | + |
| 3 | +The IBEX GUI is built using Tycho, which is a Maven plugin used for building Eclipse RCP products. |
| 4 | + |
| 5 | +This document provides a brief overview of both Maven and Tycho. |
| 6 | + |
| 7 | +:::{seealso} |
| 8 | +[Code chats](/processes/meetings/Code-Chats-and-Lightning-Talks) have been given on this topic ( |
| 9 | +[slides](https://stfc365.sharepoint.com/:p:/r/sites/ISISExperimentControls/ICP%20Discussions/GUI_Chat_Slides/IBEX%20GUI%20build%20system.pptx?d=w74aa3046025f4622bcdeadbdeca9395c&csf=1&web=1&e=aQEGJZ), |
| 10 | +[recording](https://stfc365.sharepoint.com/sites/ISISExperimentControls/_layouts/15/stream.aspx?id=%2Fsites%2FISISExperimentControls%2FICP%20Discussions%2FGUI%5FChat%5FSlides%2FIBEX%20GUI%20build%20System%20Code%20chat%2Emp4&referrer=StreamWebApp%2EWeb&referrerScenario=AddressBarCopied%2Eview&referrer=StreamWebApp%2EWeb&referrerScenario=AddressBarCopied%2Eview%2E0f53ae8b%2D3184%2D43c1%2D955e%2D039109fcd0e1) |
| 11 | +). |
| 12 | +::: |
| 13 | + |
| 14 | +## Maven |
| 15 | + |
| 16 | +The official description: |
| 17 | + |
| 18 | +> _Apache Maven is a software project management and comprehension tool. Based on the concept of a project object model |
| 19 | +> (POM), Maven can manage a project's build, reporting and documentation from a central piece of information._ |
| 20 | +
|
| 21 | +In simple terms, Maven is a build automation tool used primarily for Java projects. |
| 22 | + |
| 23 | +See the [getting started guide in the Maven documentation](https://maven.apache.org/guides/getting-started/index.html) |
| 24 | +for more information about what Maven is. |
| 25 | + |
| 26 | +### POM files |
| 27 | + |
| 28 | +POM files are XML files, called `pom.xml`, that describes the software project being built, its dependencies on other |
| 29 | +external modules and components, the build order, directories, and required plug-ins. In many ways, it can be considered |
| 30 | +the equivalent of a C-style Makefile as it defines how the project is built. |
| 31 | + |
| 32 | +See [the Maven documentation](https://maven.apache.org/pom.html) for detailed information on the various sections of a |
| 33 | +`pom.xml` in a pure Maven project. |
| 34 | + |
| 35 | +### Building a Maven project |
| 36 | + |
| 37 | +Maven uses multiple build phases - for example, `compile`, `test`, `package`. If you are really unsure, a good |
| 38 | +default is to run `mvn clean verify` to build a project; this will clean the project (deleting any old build files), |
| 39 | +and then run compilation, unit tests, packaging, and verification (e.g. checkstyle) phases. |
| 40 | + |
| 41 | +For more information, see the Maven |
| 42 | +[build lifecycle documentation](https://maven.apache.org/guides/introduction/introduction-to-the-lifecycle.html). |
| 43 | + |
| 44 | +## Tycho |
| 45 | + |
| 46 | +Tycho is a set of Maven plugins and extensions for building Eclipse-based applications with Maven. Tycho allows Maven |
| 47 | +to support building bundles, fragments, features, P2 repositories, RCP applications etc. |
| 48 | + |
| 49 | +Tycho is used to build the IBEX GUI application. |
| 50 | + |
| 51 | +### Parent POM |
| 52 | + |
| 53 | +Maven allows a parent POM to be defined which contains references to the other POM files for the other projects that |
| 54 | +make up an application. This is used in the IBEX GUI because it allows the centralisation of the settings for |
| 55 | +building the application. |
| 56 | + |
| 57 | +The [IBEX GUI parent `pom.xml`](https://github.com/ISISComputingGroup/ibex_gui/blob/master/base/uk.ac.stfc.isis.ibex.client.tycho.parent/pom.xml) |
| 58 | +contains a lot of information, so here is a stripped down version to show the key points: |
| 59 | + |
| 60 | +```xml |
| 61 | +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
| 62 | + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> |
| 63 | + <modelVersion>4.0.0</modelVersion> |
| 64 | + <groupId>CSS_ISIS</groupId> |
| 65 | + <artifactId>uk.ac.stfc.isis.ibex.client.tycho.parent</artifactId> |
| 66 | + <version>1.0.0-SNAPSHOT</version> |
| 67 | + <packaging>pom</packaging> |
| 68 | + |
| 69 | + <properties> |
| 70 | + <tycho.version>4.0.9</tycho.version> |
| 71 | + <tycho-repo.url>https://oss.sonatype.org/content/groups/public/</tycho-repo.url> |
| 72 | + <photon-repo.url>http://download.eclipse.org/releases/2024-09</photon-repo.url> |
| 73 | + <photon-updates-repo.url>http://download.eclipse.org/eclipse/updates/4.33</photon-updates-repo.url> |
| 74 | + <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> |
| 75 | + </properties> |
| 76 | + |
| 77 | + <repositories> |
| 78 | + <repository> |
| 79 | + <id>photon-updates</id> |
| 80 | + <layout>p2</layout> |
| 81 | + <url>${photon-updates-repo.url}</url> |
| 82 | + </repository> |
| 83 | + </repositories> |
| 84 | + |
| 85 | + <build> |
| 86 | + <plugins> |
| 87 | + <plugin> |
| 88 | + <groupId>org.eclipse.tycho</groupId> |
| 89 | + <artifactId>tycho-maven-plugin</artifactId> |
| 90 | + <version>${tycho.version}</version> |
| 91 | + <extensions>true</extensions> |
| 92 | + </plugin> |
| 93 | + <!-- Other maven plugins omitted such as unit testing and checkstyle --> |
| 94 | + </plugins> |
| 95 | + </build> |
| 96 | + |
| 97 | + <modules> |
| 98 | + <module>../uk.ac.stfc.isis.ibex.client.product</module> |
| 99 | + <module>../uk.ac.stfc.isis.ibex.feature.base</module> |
| 100 | + <!-- Other modules that make up IBEX would be listed here --> |
| 101 | + <module>../uk.ac.stfc.isis.ibex.ui.mainmenu.tests</module> |
| 102 | + </modules> |
| 103 | +</project> |
| 104 | +``` |
| 105 | + |
| 106 | +Let's explain the various parts shown: |
| 107 | +* At the top we have the standard Maven metadata: `groupId`, `artifactId`, `version`. |
| 108 | +* The properties section is used to define URLs for the Tycho plugin and the Eclipse RCP framework. The versions here |
| 109 | +are updated periodically during [dependency updates](/processes/dev_processes/Dependency-Updates) |
| 110 | +* The repositories section tells Maven to look for a repository for the Eclipse RCP framework version specified above |
| 111 | +* The build section defines the Maven plugins necessary to build the application. The Tycho plugin entry tells Maven to |
| 112 | +download Tycho and use it as part of the build process |
| 113 | +* The modules section lists the locations of the POM files for the various modules that make up the application. When a |
| 114 | +new module is added to IBEX, it will need to be added to this list. |
| 115 | + |
| 116 | +### Child POM |
| 117 | + |
| 118 | +A typical child POM look like |
| 119 | +[this](https://github.com/ISISComputingGroup/ibex_gui/blob/master/base/uk.ac.stfc.isis.ibex.dashboard/pom.xml). |
| 120 | +It is very simple - it points at the parent POM to get most of its information. These is one of these `pom.xml` files |
| 121 | +for each module that makes up the IBEX client. |
| 122 | + |
| 123 | +The packaging type is defined as `eclipse-plugin`; this is a packaging type defined by Tycho. Other Tycho types used in |
| 124 | +IBEX are `eclipse-feature` for features, `eclipse-test-plugin` for fragment projects that define unit tests and |
| 125 | +`eclipse-repository` for configuring builds. |
| 126 | + |
| 127 | +### Application POM |
| 128 | + |
| 129 | +In IBEX we define a separate project called `uk.ac.stfc.isis.ibex.e4.client.product` which defines how the product is |
| 130 | +built. It has a |
| 131 | +[POM file](https://github.com/ISISComputingGroup/ibex_gui/blob/master/base/uk.ac.stfc.isis.ibex.e4.client.product/pom.xml) |
| 132 | +of packaging type `eclipse-repository`. |
| 133 | + |
| 134 | +The key area is the `materialize-products` section, this tells Tycho to actually create the product. Without this Maven |
| 135 | +will compile & unit test the code, but will not produce an executable. |
0 commit comments