如何阻止tycho-p2-repository-plugin纳入Eclipse复合仓库中的所有插件
Hey there! It sounds like you’re dealing with that frustrating scenario where Tycho’s p2 repository plugin is pulling in way more plugins than you need from the Eclipse composite repo when building your own p2 repository. Let’s break down the most practical fixes to get this under control:
1. 使用目标平台定义文件(推荐方案)
This is the cleanest, most maintainable way to lock down exactly what Tycho can access. Instead of adding the Eclipse composite repo directly to your pom, create a .target file that explicitly includes only the bits you need:
- Make a new file (like
my-project.target) in your project root. - Open it with the Eclipse Target Editor, add the Eclipse composite repo as a software site.
- Instead of selecting the entire site, expand it and pick only the specific features or plugins your project depends on. You can even use pattern matching here (e.g., include
org.eclipse.core.runtime*and exclude everything else). - Link this target file to your pom so Tycho uses it:
<build> <plugins> <plugin> <groupId>org.eclipse.tycho</groupId> <artifactId>tycho-target-platform-configuration-plugin</artifactId> <version>${tycho.version}</version> <configuration> <target> <file>${project.basedir}/my-project.target</file> </target> </configuration> </plugin> </plugins> </build>
With this setup, Tycho will only resolve artifacts from your curated target platform—no more accidental inclusion of the entire Eclipse repo.
2. 在Pom中直接过滤仓库内容
If you’d rather keep the repo in your pom, you can add inclusion rules to restrict which artifacts Tycho can pull from the Eclipse composite repo:
<repositories> <repository> <id>eclipse-4.34-composite</id> <url>http://*/eclipse-4.34/e4.34-composite/</url> <layout>p2</layout> <includes> <!-- 只列出项目实际需要的插件/特性 --> <include>org.eclipse.core.runtime:osgi.bundle</include> <include>org.eclipse.equinox.common:osgi.bundle</include> <!-- 针对特性,使用特性ID和eclipse-feature类型 --> <include>org.eclipse.core.runtime.feature.group:eclipse-feature</include> </includes> </repository> <!-- 其他仓库(比如Orbit)放在这里 --> </repositories>
This tells Tycho to ignore every artifact in the composite repo except the ones you’ve explicitly listed.
3. 检查你的Feature定义
Sometimes the problem is closer to home—your .feature.xml might be including a overly broad dependency (like org.eclipse.sdk.feature.group) that drags in almost the entire Eclipse SDK. Swap those out for narrow, specific dependencies:
- 不推荐:
<import feature="org.eclipse.sdk.feature.group" versionRange="4.34.0"/> - 推荐:
<import feature="org.eclipse.core.runtime.feature.group" versionRange="4.34.0"/>
4. 配置仓库插件限制打包范围
Double-check your tycho-p2-repository-plugin configuration to make sure it’s only packaging your project’s artifacts and their direct transitive dependencies. By default it should do this, but explicit settings never hurt:
<plugin> <groupId>org.eclipse.tycho</groupId> <artifactId>tycho-p2-repository-plugin</artifactId> <version>${tycho.version}</version> <configuration> <includeAllDependencies>false</includeAllDependencies> </configuration> </plugin>
This flag ensures you don’t end up with every artifact from your linked repos cluttering your output.
Pick the approach that fits your workflow best—target files are great for long-term maintainability, while pom filtering works for quick fixes.
备注:内容来源于stack exchange,提问作者rkamthe

