简体   繁体   English

使用来自库的注释,该库不是Tycho构建中的包

[英]Using annotations from a library which is not a bundle in a Tycho build

I'm building an Eclipse plugin using Tycho and am making use of Declarative Services for my OSGi services. 我正在使用Tycho构建Eclipse插件,并且正在为我的OSGi服务使用Declarative Services。 Eclipse has a nice Editor for DS files, but it still is a manual process, which means it's slow and error-prone. Eclipse有一个很好的DS文件编辑器,但它仍然是一个手动过程,这意味着它很慢且容易出错。

In non-Tycho OSGi projects I can use the maven-scr-plugin to generate these annotations. 在非Tycho OSGi项目中,我可以使用maven-scr-plugin生成这些注释。 The catch with Tycho is that I can't add a reference to the org.apache.felix.annotations jar since it's Tycho的问题是我无法添加对org.apache.felix.annotations jar的引用,因为它是

  • not present in a p2 repository 不存在于p2存储库中
  • not a bundle 不是捆绑

These annotations are defined with a RetentionPolicy = CLASS , so they don't have to be in a bundle. 这些注释使用RetentionPolicy = CLASS定义,因此它们不必在捆绑中。

I know about dependency on pom-first artifacts , but it's not going to work for me since the annotations jar is not a bundle. 我知道对pom-first工件的依赖性 ,但它不适用于我,因为注释jar不是一个包。 Ideally I could just configure Tycho/Eclipse to look for an extra jar just at compile time. 理想情况下,我可以在编译时配置Tycho / Eclipse以寻找额外的jar。

How can I get a compile-time only jar considered by Tycho and Eclipse? 如何获得Tycho和Eclipse考虑的仅编译时jar?


Update : I've tried to use the extraClasspathElements option of the tycho-compiler-plugin . 更新 :我尝试使用tycho-compiler-pluginextraClasspathElements选项。 That does allow me to invoke the maven-scr-plugin (see the current pom.xml ). 这确实允许我调用maven-scr-plugin (参见当前的pom.xml )。 However, it seems that the scr plugin can't access the classes, as the build fails with 但是,似乎scr插件无法访问类,因为构建失败了

[ERROR] Failed to execute goal org.apache.felix:maven-scr-plugin:1.13.0:scr (generate-scr-descriptor) on project org.apache.sling.ide.eclipse-core: /mnt/md/robert/git/sling-ide-tools/eclipse-core/src/org/apache/sling/ide/eclipse/core/ServerUtil.java : Unable to load compiled class: org.apache.sling.ide.eclipse.core.ServerUtil [错误]无法在项目org.apache.sling.ide.eclipse-core:/ mnt / md /上执行目标org.apache.felix:maven-scr-plugin:1.13.0:scr(generate-scr-descriptor) robert / git / sling-ide-tools / eclipse-core / src / org / apache / sling / ide / eclipse / core / ServerUtil.java:无法加载编译的类:org.apache.sling.ide.eclipse.core。 ServerUtil

You can also see the full build log 您还可以查看完整的构建日志

Since you are using Tycho/Eclipse, you probably want to use "org.eclipse.equinox.ds" rather than "org.apache.felix.annotations". 由于您使用的是Tycho / Eclipse,因此您可能希望使用“org.eclipse.equinox.ds”而不是“org.apache.felix.annotations”。 If I understand correctly, org.eclipse.equinox.ds is a bundle. 如果我理解正确,org.eclipse.equinox.ds是一个包。 The Tycho FAQ mentions this as well: Tycho FAQ也提到了这一点:

http://wiki.eclipse.org/Tycho/FAQ#How_to_add_a_undeclared_dependency.3F__.28e.g..2C_OSGi_declarative_service.29 http://wiki.eclipse.org/Tycho/FAQ#How_to_add_a_undeclared_dependency.3F__.28e.g..2C_OSGi_declarative_service.29

EDIT: 编辑:

http://eclipse.org/tycho/sitedocs/tycho-compiler-plugin/compile-mojo.html#extraClasspathElements http://eclipse.org/tycho/sitedocs/tycho-compiler-plugin/compile-mojo.html#extraClasspathElements

EDIT2: A lot has changed. EDIT2:很多都改变了。 I'll be updating my answer when time permits. 如果时间允许,我会更新我的答案。 Check the comment threads in the meantime =) 在此期间检查注释线程=)

I think the best you can do is to separate your building in two steps. 我认为你能做的最好的事情就是分两步将你的建筑分开。 One for building the felix (scr/bnd) based bundles. 一个用于构建基于felix(scr / bnd)的捆绑包。 the result will be on a local maven repository and all will be already bundles with the manifests and component xmls. 结果将在本地maven资源库中,并且所有资源都将与清单和组件xmls捆绑在一起。

As the annotation is processed only at building time you won't have any problem with the following step. 由于仅在构建时处理注释,因此对以下步骤不会有任何问题。

The second step is to build the tycho based artifacts(bundles,features,rcp,p2,etc) that will consume the bundles in the first build. 第二步是构建基于tycho的工件(bundle,features,rcp,p2等),这些工件将使用第一个构建中的bundle。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM