Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

mvn install fails due to "incompatible types"

Tags:

maven

maven-3

I'm getting the following error from "mvn clean install"

[ERROR] /private/tmp/framework/src/main/java/org/jboss/narayana/txframework/api/annotation/transaction/WSBA.java:[21,65] incompatible types found : org.jboss.narayana.txframework.api.configuration.transaction.CompletionType required: org.jboss.narayana.txframework.api.configuration.transaction.CompletionType [ERROR] /private/tmp/framework/src/main/java/org/jboss/narayana/txframework/api/annotation/service/ServiceRequest.java:[32,56] incompatible types found : org.jboss.narayana.txframework.api.configuration.service.RequestType required: org.jboss.narayana.txframework.api.configuration.service.RequestType [INFO] 2 errors

I'm assuming this is a dependency issue and there is another instance of CompletionType in the build path somewhere. I've checked this is not the case and also tried with an empty ~/.m2/repository.

I've tried renaming the package of the offending packages and this does not fix the problem. I simply get the same error with the new package name on both lines.

My dependencies in the pom.xml shouldn't be including a lib that has these classes in.

I've tried to reproduce this on another developer's computer and the problem does not occur.

I am seeing this problem on two of my computers. These computers have a lot of their environment synced, so it doesn't surprise me that the problem is also being synced. However on my office computer I can do a successful "mvn install" within Intellij, but not on the command line. On my home computer I get this problem, both on the command line and within IntelliJ.

I've tried Googleing for this issue, but once I remove text specific to my project from the build, I don't have anything specific enough to search on.

The pom.xml can be found here:

http://anonsvn.jboss.org/repos/labs/labs/jbosstm/trunk/txframework/framework/pom.xml

Yes, I am aware that this is a JBoss package, in which the problem occurs. I work for JBoss and this is my code, so I can't get them to fix it ;-)

Thanks.

like image 806
Paul Robinson Avatar asked Dec 07 '11 15:12

Paul Robinson


2 Answers

This is caused by a bug in the annotation processing of the compiler in this version of the Oracle JDK:

java version "1.6.0_27" Java(TM) SE Runtime Environment (build 1.6.0_27-b07) Java HotSpot(TM) 64-Bit Server VM (build 20.2-b06, mixed mode)

It also occurs in the equivalent mac version, which at the time of posting is the latest release.

I fixed the problem by switching to this release of OpenJDK:

java version "1.6.0_22" OpenJDK Runtime Environment (IcedTea6 1.10.4) (fedora-60.1.10.4.fc15-x86_64) OpenJDK 64-Bit Server VM (build 20.0-b11, mixed mode)

There are workarounds if you can't switch JDK (for example if you have a mac).

More details can be found on the bug report, that I am using to track this issue:

https://issues.jboss.org/browse/JBTM-997

like image 179
Paul Robinson Avatar answered Sep 23 '22 16:09

Paul Robinson


Edit: I restructured this answer, because its primary purpose is to provide a solution to find the problem rather than solving it. The elements are added in the order I posted them in the comments or in here.

0) It is not a regular dependency problem, because that would go away if you change the name of your classes.

1) It could be related to the java version. Try setting source and target explicitly.

2) It can be a jar thats wrongly in your dependency structure, try this: add this to your pom:

<plugins>
    <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-dependency-plugin</artifactId>
            <configuration>
                <outputDirectory>
                    ${project.build.directory}
                </outputDirectory>
            </configuration>
            <executions>
                <execution>
                    <phase>initialize</phase>
                    <configuration>
                        <version>4.0.0</version>
                    </configuration>
                    <goals>
                        <goal>copy-dependencies</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
</plugins>

call clean install and then try this command on your shell (in the base path of the project, NOT the dist dir.):

find . -name "*jar" -exec jar -tvf {} \; |grep RequestType

That way you see how many representations of RequestType are on your classpath maybe you see where the wrong one comes from.

3) Its possible that the right version of your class exists now, but that the class that originating the problem (ServiceRequest.java) compiles against the wrong one. Put them both in the same classpath, then try again.

4) Have you somewhere on your disk an old version of the class? Try removing it (by moving it on a portable device if you still need it).

5) Delete every binary in your classpath manually. Don't rely on 'mvn clean' to work.

6) Print out the classpath (google will tell you how) maven is using. Check that there is nothing on that you did not expect.

7) (Obscure) Its possible to create the very same directory twice by using the more obscure features of UTF. That would happen if your paths contain a non ASCII Character and one of your machines is a Mac (really, no joke. For german capable: http://www.danisch.de/blog/2011/11/18/wer-unicode-und-utf-erfunden-hat-gehort-erschlagen/).

8) Have you checked that your environment variables are set correctly? Double check them.

9) call:

mvn clean
mvn compile

then see how many instances of the offending classes you have.

like image 44
Angelo Fuchs Avatar answered Sep 21 '22 16:09

Angelo Fuchs