【问题标题】:"API restriction error" when exporting Eclipse plugin with maven-tycho:使用 maven-tycho 导出 Eclipse 插件时出现“API 限制错误”:
【发布时间】:2015-05-02 17:45:17
【问题描述】:

我目前正在尝试使用 Maven(Tycho 扩展)构建和导出 Ecipe 插件,但它会引发大量 API 限制错误

[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 01:09 min
[INFO] Finished at: 2015-03-02T13:57:35+03:00
[INFO] Final Memory: 78M/187M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.eclipse.tycho:tycho-compiler-plugin:0.22.0:compile (default-compile) on project GDBFifoBlocks: Compilation failure: Compilation failure:
[ERROR] /home/siarshai/Programming/Workspaces/eclipse-rcp-workspace/GDBFifoBlocksBackbone/src/neuromatrixplugin/fifoblocks/backbone/viewmodel/fifo/FIFOBlockBitFieldVMNode.java:[240]
[ERROR] update.setLabel(getMessageFormat().format(
[ERROR] messageAttrs, new StringBuffer(), null).toString(), columnIndex);
[ERROR] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[ERROR] Access restriction: The method 'MessageFormat.format(Object[], StringBuffer, FieldPosition)' is not API (restriction on classpath entry '/home/siarshai/.m2/repository/p2/osgi/bundle/com.ibm.icu/52.1.1.v201501240615/com.ibm.icu-52.1.1.v201501240615.jar')
[ERROR] /home/siarshai/Programming/Workspaces/eclipse-rcp-workspace/GDBFifoBlocksBackbone/src/neuromatrixplugin/fifoblocks/backbone/viewmodel/fifo/FIFOBlockBitFieldVMNode.java:[345]
[ERROR] update.setLabel(getMessageFormat().format(combinedAttrs, new StringBuffer(), null).toString(), columnIndex);
[ERROR] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[ERROR] Access restriction: The method 'MessageFormat.format(Object[], StringBuffer, FieldPosition)' is not API (restriction on classpath entry '/home/siarshai/.m2/repository/p2/osgi/bundle/com.ibm.icu/52.1.1.v201501240615/com.ibm.icu-52.1.1.v201501240615.jar')
[ERROR] /home/siarshai/Programming/Workspaces/eclipse-rcp-workspace/GDBFifoBlocksBackbone/src/neuromatrixplugin/fifoblocks/backbone/viewmodel/fifo/FIFOBlockBitFieldVMNode.java:[395]
[ERROR] update.setLabel(getMessageFormat().format(combinedAttrs, new StringBuffer(), null).toString(), columnIndex);
[ERROR] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[ERROR] Access restriction: The method 'MessageFormat.format(Object[], StringBuffer, FieldPosition)' is not API (restriction on classpath entry '/home/siarshai/.m2/repository/p2/osgi/bundle/com.ibm.icu/52.1.1.v201501240615/com.ibm.icu-52.1.1.v201501240615.jar')
[ERROR] /home/siarshai/Programming/Workspaces/eclipse-rcp-workspace/GDBFifoBlocksBackbone/src/neuromatrixplugin/fifoblocks/backbone/viewmodel/fifo/FIFOBlockElementVMNode.java:[290]
[ERROR] update.setLabel(getMessageFormat().format(messageAttrs, new StringBuffer(), null).toString(), columnIndex);
[ERROR] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[ERROR] Access restriction: The method 'MessageFormat.format(Object[], StringBuffer, FieldPosition)' is not API (restriction on classpath entry '/home/siarshai/.m2/repository/p2/osgi/bundle/com.ibm.icu/52.1.1.v201501240615/com.ibm.icu-52.1.1.v201501240615.jar')
[ERROR] /home/siarshai/Programming/Workspaces/eclipse-rcp-workspace/GDBFifoBlocksBackbone/src/neuromatrixplugin/fifoblocks/backbone/viewmodel/fifo/FIFOBlockElementVMNode.java:[366]
[ERROR] update.setLabel(getMessageFormat().format(combinedAttrs, new StringBuffer(), null).toString(), columnIndex);
[ERROR] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[ERROR] Access restriction: The method 'MessageFormat.format(Object[], StringBuffer, FieldPosition)' is not API (restriction on classpath entry '/home/siarshai/.m2/repository/p2/osgi/bundle/com.ibm.icu/52.1.1.v201501240615/com.ibm.icu-52.1.1.v201501240615.jar')

我的 pom.xml 文件:(有关详细信息,请参阅this 问题)

父项目

<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>
  <groupId>NMGDBPluginFeature</groupId>
  <artifactId>NMGDBPluginFeature.parent</artifactId>
  <version>1.0.0.gdbfifoblocks</version>
  <packaging>pom</packaging>

   <properties>
      <tycho-version>0.22.0</tycho-version>
      <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>  
   </properties>

   <repositories>
        <repository>
            <id>eclipse-luna</id>
            <layout>p2</layout>
            <url>http://download.eclipse.org/releases/luna</url>
        </repository>
    </repositories>

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

            <configuration>
                <compilerArgument>-warn:none</compilerArgument>     
                <compilerArgument>-err:none</compilerArgument>      
            </configuration>

         </plugin>
      </plugins>
   </build>



  <modules>
    <module>../GDBFifoBlocksBackbone</module>
    <module>../NMGDBPluginFeature</module>
  </modules>

</project>

特色项目:

<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>NMGDBPluginFeature</groupId>
    <artifactId>NMGDBPluginFeature.parent</artifactId>
    <version>1.0.0.gdbfifoblocks</version>
    <relativePath>./../GeneralExportingProject</relativePath>
  </parent>

  <artifactId>NMGDBPluginFeature</artifactId>
  <packaging>eclipse-feature</packaging>


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

            <configuration>
                <compilerArgument>-warn:none</compilerArgument>     
                <compilerArgument>-err:none</compilerArgument>      
            </configuration>

         </plugin>
      </plugins>
   </build>

</project>

插件项目:

<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>NMGDBPluginFeature</groupId>
    <artifactId>NMGDBPluginFeature.parent</artifactId>
    <version>1.0.0.gdbfifoblocks</version>
    <relativePath>./../GeneralExportingProject</relativePath>
  </parent>

  <artifactId>GDBFifoBlocks</artifactId>
  <packaging>eclipse-plugin</packaging>

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

            <configuration>
                <compilerArgument>-warn:none</compilerArgument>     
                <compilerArgument>-err:none</compilerArgument>      
            </configuration>

         </plugin>
      </plugins>
   </build>

</project>

我确信插件和导出功能配置(即 MANIFEST 和 feature.xml)写得很好。我已经试过了:

  1. 在 Eclipse > Window > Preferences > Java > Compiler > Error/Warning 中将所有 API 违规设置为“忽略”
  2. 从项目的构建路径中删除了 JRE 并再次添加(如几个错误主题中所建议的)
  3. 在 pom.xml 中添加了 -warn:none(可以在上面的配置中看到)

我在 Google 中没有发现其他建议。我应该将此报告为错误还是我的错误?

【问题讨论】:

  • 你真的想使用来自'com.ibm.icu'的MessageFormat吗?还是您尝试使用普通的java.text.MessageFormat
  • compilerArgument不是tycho-maven-plugin上的参数,所以这个配置没有效果。
  • @greg-449,不幸的是,还有许多其他受限制的课程。由于项目的性质,它们是不可避免的。
  • @oberlies 谢谢你,就是这样。我的错误:没有注意,我实际使用了哪个插件。公平地说,我的插件构建配置命令使用已经编译的文件,所以我认为 tycho 验证失败。

标签: java eclipse maven plugins tycho


【解决方案1】:

感谢@oberlies 评论,找到了答案。 compilerArgument 应该传递给 tycho-compiler-plugin 而不是 tycho-maven-plugin 所以正确的配置是

   <build>
      <plugins>

        <plugin>
              <groupId>org.eclipse.tycho</groupId>
              <artifactId>tycho-compiler-plugin</artifactId>
              <version>0.22.0</version>
            <configuration>
                <compilerArgument>-warn:none</compilerArgument>     
                <compilerArgument>-err:none</compilerArgument>      
            </configuration>
        </plugin>

         <plugin>
            <groupId>org.eclipse.tycho</groupId>
            <artifactId>tycho-maven-plugin</artifactId>
            <version>0.22.0</version>
            <extensions>true</extensions>   
         </plugin>

      </plugins>
   </build>

出于某种原因,Tycho 不会在编辑器中或运行期间警告不匹配的标签。

【讨论】:

  • Tycho 不会警告标签不匹配 - 这同样适用于所有 Maven 配置:插件配置适用于 Maven 插件的所有目标,因此存在是不适用的标签。 Maven(或第谷)可以通过扫描所有潜在目标及其参数来尝试找到永远应用的标签——但这还没有实现......
【解决方案2】:

如果eclipse插件项目确实有项目特定的设置,这些可能会覆盖编译器行为,所以即使标志设置为警告,错误仍然可能出现:

        <plugin>
            <groupId>org.eclipse.tycho</groupId>
            <artifactId>tycho-compiler-plugin</artifactId>
            <version>${tycho.version}</version>
            <configuration>
                <compilerArgument>-warn:+discouraged,forbidden</compilerArgument>
                <useProjectSettings>false</useProjectSettings>
            </configuration>
        </plugin>

您还可以从插件中删除项目特定的设置文件夹或调整此编译器标志的设置。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-03-20
    • 1970-01-01
    • 2012-06-15
    • 1970-01-01
    • 2012-06-21
    • 1970-01-01
    • 2019-11-04
    • 1970-01-01
    相关资源
    最近更新 更多