问题
I can't get Intellij Idea 13.0 to compile my code against ASM 5.0.3
I have a multi-module Maven project. It compiles and installs successfully.
Apparently com.google.findbugs:findbugs
has a dependency on asm:asm:3.3
and I want to use org.ow2.asm:asm:5.0.3
to manipulate some bytecode.
So in the parent pom.xml
I exclude the asm:asm:3.3
dependencies from the classpath. This works fine when I run mvn install
from the command line.
I can't get the Build -> Make Project menu selection to work in Intellij Idea.
Here is the relevant parts of my pom.xml
files.
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>
Here is the code that is failing
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 }
Here is the error message:
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.
As you can see in the screen capture, it reports the correct version of the libraries in the Javadoc but the AutoComplete shows the old 3.3
non-typesafe return value of List
instead of List<MethodNode>
:
(source: vertigrated.com)
Here is what Maven knows, which is correct:
[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
How do I get Intellij Idea to use the correct dependency internally?
回答1:
It looks like you end up having asm-5.0.3.jar
in your compilation class path in IntelliJ IDEA.
This JAR is optimized for minimal size by stripping every bit of it that could be stripped, including the generic signatures (that's how a List<MethodNode>
becomes a List
, which is effectively List<Object>
in your case).
To make sure this is the case, try replacing the dependencies on asm
, asm-tree
etc by asm-debug-all. The JAR you get will be bigger, but the project should compile now.
Next question is how this compiles in mvn
, but fails in IntelliJ IDEA. You can see the class path in the "Project Structure" dialog under "Modules", on the "Dependencies" tab. Maybe the class path was not imported correctly in IntelliJ (in that case, report to IntelliJ IDEA's issue tracker, you'll probably get some help rather soon).
来源:https://stackoverflow.com/questions/23877521/intellij-idea-13-x-and-asm-5-x-library-incompatible