升级Tycho从1.7.0到2.7.5后依赖解析失败问题
Tycho升级到2.7.5后Debian包构建依赖解析失败:寻找不存在的eclipse-plugin类型构件
问题背景
我用Tycho构建OSGi构件(Eclipse插件),另有一个项目通过自定义MOJO构建包含这些构件的Debian包,OSGi构件在Debian包项目的POM中声明为普通POM依赖。之前构建正常,但升级Tycho从1.7.0到2.7.5(需使用wrapAsBundle特性)后,依赖解析阶段失败——系统尝试拉取私有Artifactory仓库中不存在的*.eclipse-plugin类型构件。
变更前构建日志
[INFO] Downloading from xyz.repository.snapshot: https://repository.xyz/artifactory/xyz-snapshot/xyz/xyz.service.ticket/1.0.0-SNAPSHOT/maven-metadata.xml [INFO] Downloaded from xyz.repository.snapshot: https://repository.xyz/artifactory/xyz-snapshot/xyz/xyz.service.ticket/1.0.0-SNAPSHOT/maven-metadata.xml (1.3 kB at 80 kB/s) [INFO] [INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ xyz.os.runtime ---
变更后构建日志
[DEBUG] Skipped remote request for xyz.service:xyz.service.ticket:1.0.0-SNAPSHOT/maven-metadata.xml, already updated during this session. [DEBUG] Using transporter WagonTransporter with priority -1.0 for https://repository.xyz/artifactory/xyz-snapshot/ [DEBUG] Using connector BasicRepositoryConnector with priority 0.0 for https://repository.xyz/artifactory/xyz-snapshot/ with username=abc, password=*** [INFO] Downloading from xyz.repository.snapshot: https://repository.xyz/artifactory/xyz-snapshot/xyz/xyz.common.data/1.0.0-SNAPSHOT/xyz.common.data-1.0.0-SNAPSHOT.eclipse-plugin [DEBUG] Writing tracking file /home/gitlab-runner/.m2/repository/xyz/common/xyz.common.data/1.0.0-SNAPSHOT/xyz.common.data-1.0.0-SNAPSHOT.eclipse-plugin.lastUpdated [INFO] ------------------------------------------------------------------------ [INFO] BUILD FAILURE [INFO] ------------------------------------------------------------------------ [INFO] Total time: 6.942 s [INFO] Finished at: 2024-11-15T21:36:23+01:00 [INFO] ------------------------------------------------------------------------ [ERROR] Failed to execute goal on project xyz.os.runtime: Could not resolve dependencies for project xyz.os:xyz.os.runtime:debian:3.7.0.20241115213614-testing: Could not find artifact xyz.os.runtime.common:xyz.os.runtime.common.data:eclipse-plugin:1.0.0-SNAPSHOT in technology.xyz.repository.snapshot (https://repository.xyz/artifactory/xyz-snapshot/) -> [Help 1] org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal on project xyz.os.runtime: Could not resolve dependencies for project xyz.os:xyz.os.runtime:debian:3.7.0.20241115213614-testing: Could not find artifact xyz.os.runtime.common:xyz.os.runtime.common.data:eclipse-plugin:1.0.0-SNAPSHOT in xyz.repository.snapshot (https://repository.xyz/artifactory/xyz-snapshot/) at org.apache.maven.lifecycle.internal.LifecycleDependencyResolver.getDependencies (LifecycleDependencyResolver.java:269) at org.apache.maven.lifecycle.internal.LifecycleDependencyResolver.resolveProjectDependencies (LifecycleDependencyResolver.java:147) at org.apache.maven.lifecycle.internal.MojoExecutor.ensureDependenciesAreResolved (MojoExecutor.java:248) at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:202) at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:156)
当前Tycho配置
<plugin> <groupId>org.eclipse.tycho</groupId> <artifactId>tycho-compiler-plugin</artifactId> <version>${tycho.version}</version> </plugin> <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>tycho-versions-plugin</artifactId> <version>${tycho.version}</version> </plugin> <plugin> <groupId>org.eclipse.tycho</groupId> <artifactId>target-platform-configuration</artifactId> <version>${tycho.version}</version> <configuration> <pomDependencies>wrapAsBundle</pomDependencies> </configuration> </plugin>
问题原因
Tycho 2.x版本中,pomDependencies=wrapAsBundle的行为发生了变更:它会将所有POM依赖都视为需要包装成OSGi bundle的构件,包括原本就是Tycho构建的Eclipse插件。而这些插件在仓库中是以jar类型存储的,但Tycho现在会尝试拉取eclipse-plugin类型的构件,导致依赖查找失败。
解决方法
1. 限制wrapAsBundle作用范围
只对非Tycho构建的普通JAR依赖启用包装,对Tycho构建的OSGi插件直接使用原始类型。修改target-platform-configuration配置:
<plugin> <groupId>org.eclipse.tycho</groupId> <artifactId>target-platform-configuration</artifactId> <version>${tycho.version}</version> <configuration> <pomDependencies>consider</pomDependencies> <dependency-resolution> <extraRequirements> <!-- 仅对需要包装的普通JAR依赖添加wrap指令 --> <requirement> <type>pom</type> <id>com.example:non-osgi-dependency</id> <versionRange>[1.0.0,)</versionRange> <parameters> <wrapAsBundle>true</wrapAsBundle> </parameters> </requirement> </extraRequirements> </dependency-resolution> </configuration> </plugin>
2. 显式指定依赖类型
在Debian包项目的POM依赖中,明确指定Tycho构建构件的类型为jar,避免Tycho默认查找eclipse-plugin类型:
<dependency> <groupId>xyz.os.runtime.common</groupId> <artifactId>xyz.os.runtime.common.data</artifactId> <version>1.0.0-SNAPSHOT</version> <type>jar</type> </dependency>
3. 检查Artifactory部署配置
确保Tycho构建的OSGi插件部署到Artifactory时,正确生成并上传maven-metadata.xml,且构件类型被正确识别为jar(若需存储为eclipse-plugin类型,需保持依赖声明与仓库存储一致)。
内容的提问来源于stack exchange,提问作者Martin
相关产品推荐
相关产品推荐

