如何使用Tycho发布保留特性历史版本的p2站点?
Hey there! Let me walk you through how to keep historical plugin/feature versions in your Tycho-generated p2 repository—this is a common transition pain point when moving from Eclipse's Build Site to automated Tycho builds, and I’ve worked through this a few times.
The core issue here is that Tycho defaults to generating a fresh repository each build, which would overwrite old versions. We need to either incrementally update an existing repository or configure Tycho to pull all historical versions from your Maven repo during the build. Here are two reliable approaches:
Approach 1: Incrementally Update an Existing P2 Repository
This method merges your new Tycho-built features into an existing repository (like the one you created with Eclipse Build Site) so all versions are preserved.
Steps:
- Keep your historical repository intact: Make sure you have a copy of your old p2 repo (with feature.1.0.0, feature.2.0.0, etc.) stored locally or on a server.
- Configure Tycho to merge repositories: Add this configuration to your Tycho project's
pom.xmlto use thetycho-p2-repository-plugin'smirrorgoal, which combines your new build with the historical repo:
<plugin> <groupId>org.eclipse.tycho</groupId> <artifactId>tycho-p2-repository-plugin</artifactId> <version>${tycho.version}</version> <executions> <execution> <id>merge-history-and-new-build</id> <phase>package</phase> <goals> <goal>mirror</goal> </goals> <configuration> <source> <!-- First source: your newly built Tycho repository --> <repository> <url>file:${project.build.directory}/repository</url> <layout>p2</layout> </repository> <!-- Second source: your existing historical p2 repository --> <repository> <url>file:/path/to/your/historical-p2-repo</url> <layout>p2</layout> </repository> </source> <destination> <!-- Final combined repository with all versions --> <url>file:/path/to/final-combined-p2-repo</url> <layout>p2</layout> </destination> <!-- Critical: append new content instead of overwriting --> <append>true</append> <mirrorOptions> <mirrorAll>true</mirrorAll> <!-- Keep all existing installable units --> </mirrorOptions> </configuration> </execution> </executions> </plugin>
- Run the build: When you execute
mvn clean package, Tycho will build the new feature version, then merge it into your historical repo—preserving all old versions in the final combined repository.
Approach 2: Aggregate All Versions via category.xml
If you want to manage everything through your category.xml and Maven repository, this method pulls all historical feature/plugin versions from your Maven repo (local or remote) during the build.
Prerequisite:
First, make sure all your historical feature/plugin versions are installed in your Maven repository. If you have the old Eclipse Build Site artifacts, you can import them using:
# Example command to install a feature JAR to Maven mvn install:install-file -Dfile=feature.1.0.0.jar -DgroupId=com.yourproject -DartifactId=com.yourproject.feature -Dversion=1.0.0 -Dpackaging=eclipse-feature
Steps:
- Simplify your category.xml: You don’t need to list every version—just the feature ID. Tycho will pull all available versions from Maven:
<category-def name="My Project Features" label="All Versions of My Project Features"> <iu id="com.yourproject.feature" /> <!-- No version specified --> </category-def>
- Configure Tycho to include all versions: Update your
pom.xmlto tell Tycho to fetch all versions of the feature from your Maven repo:
<plugin> <groupId>org.eclipse.tycho</groupId> <artifactId>tycho-p2-repository-plugin</artifactId> <version>${tycho.version}</version> <executions> <execution> <id>create-category-repo-with-all-versions</id> <phase>package</phase> <goals> <goal>category-repository</goal> </goals> <configuration> <categoryDefinitions> <categoryDefinition>category.xml</categoryDefinition> </categoryDefinitions> <!-- Key setting: include every available version of the feature --> <includeAllVersions>true</includeAllVersions> <!-- Point to your Maven repository (local or remote) --> <repositories> <repository> <url>file:${settings.localRepository}</url> <layout>p2</layout> </repository> <!-- Add remote Maven repos here if your artifacts are stored remotely --> </repositories> </configuration> </execution> </executions> </plugin>
- Build the repository: Running
mvn clean packagewill generate a p2 repo that includes every version of your feature available in your Maven repo—just like your old Eclipse Build Site did.
Important Notes
- Don’t clean the final repository: If you’re using a CI tool like Jenkins, make sure your final combined repo directory is persisted (not cleaned between builds) to retain historical versions.
- Consistent group/artifact IDs: Ensure your historical features/plugins use the same Maven groupId/artifactId as your new Tycho builds—this helps Tycho find and aggregate them correctly.
- Test the repo: After building, check the
content.jarandartifacts.jarin the repo to confirm all versions are present, or add the repo to Eclipse and verify you can see all feature versions in the install dialog.
内容的提问来源于stack exchange,提问作者simonso




