【问题标题】:Maven Tycho: Not a valid OSGi versionMaven Tycho:不是有效的 OSGi 版本
【发布时间】:2015-07-14 02:14:48
【问题描述】:

在我的项目中,我尝试使用 Maven/Tycho 导出 Eclipse RCP 应用程序。

所有插件(以及产品本身)在“SNAPSHOT”发布配置中使用以下版本模式:

OSGI: x.y.z.qualifier
MVN:  x.y.z-SNAPSHOT

交付将使用以下模式

OSGI: x.y.z.vyyyyMMddHHmm
MVN:  x.y.z-vyyyyMMddHHmm

如您所见,“-”和“.”之间只有区别

对于 RCP 插件,我必须使用以下 maven 插件禁用 tycho 执行的检查以验证版本

<build>
    <plugins>
        <plugin>
            <groupId>org.eclipse.tycho</groupId>
            <artifactId>tycho-packaging-plugin</artifactId>
            <version>0.22.0</version>
            <configuration>
                <strictVersions>false</strictVersions>
            </configuration>
        </plugin>
    </plugins>
</build>

到目前为止,一切都很好。

说到RCP应用的产品,我有以下pom.xml文件

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <parent>
        <groupId>XXXXXX.user-interfaces</groupId>
        <artifactId>user-interfaces-parent-pom</artifactId>
        <version>0.2.0-v201505041341</version>
        <relativePath>../../poms/parent-pom</relativePath>
    </parent>


    <artifactId>XXXXXX.product</artifactId>
    <name>XXXXXX.product</name>
    <packaging>eclipse-repository</packaging>

    <!-- Make OSGi happy -->
    <!-- version>0.2.0.v201505041341</version-->

    <build>
        <plugins>
            <plugin>
                <groupId>org.eclipse.tycho</groupId>
                <artifactId>tycho-p2-director-plugin</artifactId>
                <version>${tycho.version}</version>
                <executions>
                    <execution>
                        <id>create-product-distributions</id>
                        <goals>
                            <goal>materialize-products</goal>
                            <goal>archive-products</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>

父 pom.xml 仅定义了更多内容,例如 P2 存储库和 tycho-maven-plugin 构建步骤。

<build>
    <plugins>
        <plugin>
            <groupId>org.eclipse.tycho</groupId>
            <artifactId>tycho-maven-plugin</artifactId>
            <extensions>true</extensions>
        </plugin>
    </plugins>
</build>

问题 当我编译快照时,一切正常,但是一旦我按照上面的解释使用 TIMESTAMP 更改 SNAPSHOT,Maven Tycho 就会抱怨给我以下堆栈跟踪:

[ERROR] Failed to execute goal org.eclipse.tycho:tycho-packaging-plugin:0.22.0:build-qualifier-aggregator (default-build-qualifier-aggregator) on project XXXXXX.product: Not a valid OSGi version 0.2.0-v201505041341 for project MavenProject: XXXXX.user-interfaces:XXXXXX.product:0.2.0-v201505041341 @ /local/XXXXX/pom.xml -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.eclipse.tycho:tycho-packaging-plugin:0.22.0:build-qualifier-aggregator (default-build-qualifier-aggregator) on project XXXXXX.product: Not a valid OSGi version 0.2.0-v201505041341 for project MavenProject: XXXXXX.user-interfaces:XXXXXX.product:0.2.0-v201505041341 @ /local/XXXXXXX/pom.xml
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:212)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:116)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:80)
    at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:51)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:120)
    at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:347)
    at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:154)
    at org.apache.maven.cli.MavenCli.execute(MavenCli.java:582)
    at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:214)
    at org.apache.maven.cli.MavenCli.main(MavenCli.java:158)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)
Caused by: org.apache.maven.plugin.MojoFailureException: Not a valid OSGi version 0.2.0-v201505041341 for project MavenProject: XXXXXXX.user-interfaces:XXXXXX.product:0.2.0-v201505041341 @ /local/XXXXXX/pom.xml
    at org.eclipse.tycho.buildversion.BuildQualifierMojo.getParsedOSGiVersion(BuildQualifierMojo.java:177)
    at org.eclipse.tycho.buildversion.BuildQualifierMojo.calculateQualifiedVersion(BuildQualifierMojo.java:143)
    at org.eclipse.tycho.buildversion.BuildQualifierMojo.execute(BuildQualifierMojo.java:134)
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:132)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:208)
    ... 19 more

我查看了源代码,发现 Tycho 尝试从 Maven 工件中获取版本,而不是从产品文件本身获取版本。

使其工作的唯一方法是删除 pom.xml 中的注释

<!-- Make OSGi happy -->
<version>0.2.0.v201505041341</version>

有没有办法让第谷使用“-”而不是“。”还是告诉它从其他地方获取版本?

谢谢

【问题讨论】:

  • 我放弃了使用 tyco 构建 eclipse 插件,并开始为我的 eclipse 插件使用纯 OSGI 构建。这对于构建和发布非常有效。
  • @ChristianKuetbach “纯 OSGI 构建”是什么意思?你也用过maven吗?
  • 是的,但不是泰科。我无法同时使用 maven 发布插件和 tyco,因为在发布阶段存在错误的版本组合(maven 使用了发布版本而 tycho 仍然是 SNAPSHOT)
  • 你有什么例子吗?

标签: java maven eclipse-rcp packaging tycho


【解决方案1】:

Tycho 仅支持 '-' 用于 SNAPSHOT 识别到 OSGI 限定符,在其他情况下它应该是 x.x.x.x 格式。

您可以使用set-version maven 目标https://eclipse.org/tycho/sitedocs/tycho-release/tycho-versions-plugin/set-version-mojo.html 在发布前设置OSGI 版本。

例如,您使用预定义的 1.0.0-SNAPSHOT (1.0.0.qualifier) 版本进行开发和发布之前您需要调用 mvn tycho-versions:set-version -DnewVersion=1.0.2.qualifier 要么 mvn tycho-versions:set-version -DnewVersion=1.0.2.v123456

它将修改您的源代码,之后您可以通过mvn package构建具有更新版本的产品

【讨论】:

  • 您好,感谢您的意见。不幸的是,它有效,但把“。”而不是“-”。奇怪的是,在 SNAPSHOT/限定符中第谷消化了“-”而不是在发布期间。
【解决方案2】:

您可以使用 maven-bundle-plugin 创建一个 OSGI 包。

我的应用程序使用了很多插件,但我认为演示会展示它是如何工作的:

http://felix.apache.org/documentation/subprojects/apache-felix-maven-bundle-plugin-bnd.html

专业版: 它与 maven 配合得非常好

缺点: 这是行家的第一种方式。您需要在 maven 中设置导入和导出包,然后重新创建 MANIFEST.MF

【讨论】:

    【解决方案3】:

    没有使第谷使用“-”而不是“.”的解决方法。 ?

    已编辑:

    <plugin>
      <groupId>org.eclipse.tycho</groupId>
      <artifactId>tycho-p2-plugin</artifactId>
      <version>${parent.tycho.version}</version>
      <executions>
       <execution>
       <!-- Do not attach metadata before the source-feature execution -->
       <id>default-p2-metadata-default</id>
       <configuration>
        <attachP2Metadata>false</attachP2Metadata>
       </configuration>
      </execution>
     </executions>
    </plugin>
    

    【讨论】:

    • 我不知道
    猜你喜欢
    • 2012-01-11
    • 2020-04-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-03-07
    • 2020-01-08
    • 1970-01-01
    相关资源
    最近更新 更多