【问题标题】:Intellij Idea 13.x and ASM 5.x library incompatible?Intellij Idea 13.x 和 ASM 5.x 库不兼容?
【发布时间】:2014-05-26 20:47:52
【问题描述】:

我无法让 Intellij Idea 13.0 针对 ASM 5.0.3 编译我的代码

我有一个多模块 Maven 项目。它编译并安装成功。

显然com.google.findbugs:findbugs 依赖于asm:asm:3.3,我想使用org.ow2.asm:asm:5.0.3 来操作一些字节码。

所以在父 pom.xml 中,我从类路径中排除了 asm:asm:3.3 依赖项。当我从命令行运行 mvn install 时,这可以正常工作。

我无法让 Build -> Make Project 菜单选择在 Intellij Idea 中工作。

这是我的pom.xml 文件的相关部分。

parent.pom

<dependency>
    <groupId>org.ow2.asm</groupId>
    <artifactId>asm</artifactId>
    <version>5.0.3</version>
</dependency>

<dependency>
    <groupId>org.ow2.asm</groupId>
    <artifactId>asm-tree</artifactId>
    <version>5.0.3</version>
</dependency>

<dependency>
    <groupId>org.ow2.asm</groupId>
    <artifactId>asm-util</artifactId>
    <version>5.0.3</version>
</dependency>

<dependency>
    <groupId>org.ow2.asm</groupId>
    <artifactId>asm-commons</artifactId>
    <version>5.0.3</version>
</dependency>


<dependency>
    <groupId>com.google.code.findbugs</groupId>
    <artifactId>findbugs</artifactId>
    <version>2.0.3</version>
    <exclusions>
        <exclusion>
            <groupId>asm</groupId>
            <artifactId>asm</artifactId>
        </exclusion>
        <exclusion>
            <groupId>asm</groupId>
            <artifactId>asm-commons</artifactId>
        </exclusion>
        <exclusion>
            <groupId>asm</groupId>
            <artifactId>asm-tree</artifactId>
        </exclusion>
    </exclusions>
</dependency>

这是失败的代码

18       public static void main(final String[] args) throws IOException 
19       { 
20           final InputStream is = NotEmptyTest.class.getResourceAsStream("/com/vertigrated/annotation/NotEmptyTest.class"); 
21           final ClassReader cr = new ClassReader(is); 
22           final ClassNode cn = new ClassNode(); 
23           cr.accept(cn, 0); 
24           for (final MethodNode mn : cn.methods)
25           { 
26 - 38 snipped for brevity 
39           } 
40       } 
41   }

这是错误信息:

Information:Using javac 1.7.0_25 to compile java sources
Information:java: Errors occurred while compiling module 'tests'
Information:Compilation completed with 1 error and 2 warnings in 2 sec
Information:1 error
Information:2 warnings
/<path to my source code>/NotEmptyTest.java
    Error:Error:line (24)java: incompatible types
  required: org.objectweb.asm.tree.MethodNode
  found:    java.lang.Object
    Warning:Warning:java: /<path to my project>//NotEmptyTest.java uses unchecked or unsafe operations.
    Warning:Warning:java: Recompile with -Xlint:unchecked for details.

正如您在屏幕截图中看到的,它报告了 Javadoc 中库的正确版本,但自动完成显示旧的 3.3 非类型安全返回值 List 而不是 List&lt;MethodNode&gt;


(来源:vertigrated.com

这是 Maven 所知道的,这是正确的:

[INFO] --- maven-dependency-plugin:2.8:list (default-cli) @ tests ---
[INFO] 
[INFO] The following files have been resolved:
[INFO]    com.google.code.findbugs:bcel:jar:2.0.1:compile
[INFO]    junit:junit:jar:4.11:test
[INFO]    xml-apis:xml-apis:jar:1.0.b2:compile
[INFO]    com.apple:AppleJavaExtensions:jar:1.4:compile
[INFO]    javax.inject:javax.inject:jar:1:compile
[INFO]    jaxen:jaxen:jar:1.1.6:compile
[INFO]    org.ow2.asm:asm-util:jar:5.0.3:compile
[INFO]    com.google.inject:guice:jar:3.0:compile
[INFO]    dom4j:dom4j:jar:1.6.1:compile
[INFO]    com.google.code.findbugs:jFormatString:jar:2.0.1:compile
[INFO]    net.jcip:jcip-annotations:jar:1.0:compile
[INFO]    org.ow2.asm:asm-tree:jar:5.0.3:compile
[INFO]    commons-lang:commons-lang:jar:2.6:compile
[INFO]    com.google.code.findbugs:jsr305:jar:2.0.1:compile
[INFO]    org.hamcrest:hamcrest-core:jar:1.3:test
[INFO]    aopalliance:aopalliance:jar:1.0:compile
[INFO]    com.google.code.findbugs:findbugs:jar:2.0.3:compile
[INFO]    org.ow2.asm:asm-commons:jar:5.0.3:compile
[INFO]    org.ow2.asm:asm:jar:5.0.3:compile

如何让 Intellij Idea 在内部使用正确的依赖项?

【问题讨论】:

    标签: java maven intellij-idea java-bytecode-asm


    【解决方案1】:

    看起来您最终在 IntelliJ IDEA 的编译类路径中添加了 asm-5.0.3.jar。 此 JAR 通过剥离可以剥离的每一位,包括通用签名(这就是 List&lt;MethodNode&gt; 变成 List,在您的情况下实际上是 List&lt;Object&gt;),针对最小尺寸进行了优化。

    为确保是这种情况,请尝试将asmasm-tree 等的依赖项替换为asm-debug-all。你得到的 JAR 会更大,但项目现在应该可以编译了。

    下一个问题是如何在 mvn 中编译,但在 IntelliJ IDEA 中失败。您可以在“模块”下的“项目结构”对话框中的“依赖项”选项卡上查看类路径。可能在 IntelliJ 中没有正确导入类路径(在这种情况下,请向 IntelliJ IDEA 的issue tracker 报告,您可能很快就会得到一些帮助)。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-07-30
      • 1970-01-01
      • 1970-01-01
      • 2014-09-15
      • 1970-01-01
      • 2010-10-03
      相关资源
      最近更新 更多