如何将Eclipse产品及物化产物部署至Maven与Nexus仓库?
Hey there! Let's break down how to handle both your deployment needs—getting your Eclipse product into a Maven repo, and pushing that materialized product to Nexus when single-artifact guides fall short.
Since Eclipse products rely on OSGi bundles and p2 repositories, Tycho is the go-to Maven plugin for this workflow. Here's a step-by-step approach:
Set up your Tycho build foundation
First, configure your parentpom.xmlto use Tycho, include Eclipse's p2 repositories (for dependencies), and define your project group/version:<properties> <tycho-version>4.0.0</tycho-version> <project.version>1.0.0-SNAPSHOT</project.version> </properties> <repositories> <repository> <id>eclipse-releases</id> <url>https://download.eclipse.org/releases/latest/</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> </plugins> </build>Configure your product project
In your Eclipse product project'spom.xml, set the packaging toeclipse-productand link to your.productfile:<packaging>eclipse-product</packaging> <build> <plugins> <plugin> <groupId>org.eclipse.tycho</groupId> <artifactId>tycho-product-plugin</artifactId> <version>${tycho-version}</version> <configuration> <productFile>src/main/resources/com.yourcompany.yourproduct.product</productFile> <archiveFileName>${project.artifactId}-${project.version}.zip</archiveFileName> </configuration> </plugin> </plugins> </build>Deploy the built product
Use Maven'sdeploygoal to push the generated zip artifact to your Maven repo (or Nexus). You can either rely on Tycho's default deployment or explicitly configure themaven-deploy-pluginif you need custom paths:mvn clean deploy -Dmaven.deploy.repo.id=your-nexus-repo-id -Dmaven.deploy.repo.url=http://your-nexus-url/repository/maven-releases/Make sure your
settings.xmlhas the Nexus credentials mapped toyour-nexus-repo-id:<servers> <server> <id>your-nexus-repo-id</id> <username>nexus-user</username> <password>nexus-password</password> </server> </servers>
A materialized product is the fully expanded, runnable version of your Eclipse product (not just a zip archive). Since Nexus/Maven repos work best with packaged artifacts, here's how to handle this:
Package the materialized product
First, use Tycho'stycho-p2-director-pluginto materialize the product, then usemaven-assembly-pluginto package the entire directory into a zip/tar.gz:<!-- In your product project's pom.xml --> <plugin> <groupId>org.eclipse.tycho</groupId> <artifactId>tycho-p2-director-plugin</artifactId> <version>${tycho-version}</version> <executions> <execution> <id>materialize-product</id> <goals> <goal>materialize-products</goal> </goals> <configuration> <products> <product> <id>com.yourcompany.yourproduct.product</id> <rootFolder>materialized-product</rootFolder> </product> </products> </configuration> </execution> </executions> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-assembly-plugin</artifactId> <version>3.6.0</version> <executions> <execution> <id>package-materialized</id> <phase>package</phase> <goals> <goal>single</goal> </goals> <configuration> <descriptors> <descriptor>src/main/assembly/materialized-assembly.xml</descriptor> </descriptors> </configuration> </execution> </executions> </plugin>Create the
materialized-assembly.xmldescriptor to bundle the entire materialized directory:<assembly xmlns="http://maven.apache.org/ASSEMBLY/2.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/ASSEMBLY/2.0.0 http://maven.apache.org/xsd/assembly-2.0.0.xsd"> <id>materialized</id> <formats> <format>zip</format> </formats> <fileSets> <fileSet> <directory>${project.build.directory}/materialized-product</directory> <outputDirectory>/</outputDirectory> <includes> <include>**/*</include> </includes> </fileSet> </fileSets> </assembly>Deploy the packaged materialized product
Use themaven-deploy-pluginto push the generated zip to Nexus, adding a classifier to distinguish it from the regular product zip:<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-deploy-plugin</artifactId> <version>3.1.0</version> <executions> <execution> <id>deploy-materialized</id> <phase>deploy</phase> <goals> <goal>deploy-file</goal> </goals> <configuration> <file>${project.build.directory}/${project.artifactId}-${project.version}-materialized.zip</file> <groupId>com.yourcompany</groupId> <artifactId>your-eclipse-product</artifactId> <version>${project.version}</version> <classifier>materialized</classifier> <packaging>zip</packaging> <repositoryId>your-nexus-repo-id</repositoryId> <url>http://your-nexus-url/repository/maven-releases/</url> </configuration> </execution> </executions> </plugin>Run
mvn clean deployas before, and the materialized product will show up in Nexus with thematerializedclassifier.
If you need to deploy materialized products for multiple platforms (Windows, Linux, macOS), just create separate assembly descriptors and classifiers (e.g., materialized-linux-x86_64, materialized-win32-x86_64) to keep them organized.
内容的提问来源于stack exchange,提问作者positron

