jira.codehaus.org

  • Log In Access more options
    • Online Help
    • Keyboard Shortcuts
    • About JIRA
    • JIRA Credits
    • What?s New
  • Dashboards Access more options (Alt+d)
  • Projects Access more options (Alt+p)
  • Issues Access more options (Alt+i)
  • Maven 2.x Compiler Plugin
  • MCOMPILER-43

Maven compiler creates ghost classes when invoked with a compilerId of 'eclipse'

  • Log In
  • Views
    • XML
    • Word
    • Printable

Details

  • Type: Bug Bug
  • Status: Closed Closed
  • Priority: Critical Critical
  • Resolution: Fixed
  • Affects Version/s: 2.0.1
  • Fix Version/s: 2.1
  • Labels:
    None
  • Environment:
    Windows XP, java 5 and java 1.4 with maven 2.0.4

Description

The maven-compiler-plugin, along with the plexus-eclipse-compiler component, is generating ghost classes (i.e. java source files that compile, but don't generate a .class file). If I put a deliberate error into the Logger.java file then the compilers, javac and eclipse, both catch it. However, only javac when invoked through maven will create a .class files for the 2 java files in the example project. I'm using the following pom definition:

<?xml version="1.0" encoding="UTF-8"?>

<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.abc.logging</groupId>
<artifactId>abc-logging</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>ABC Logging</name>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.4</source>
<target>1.4</target>
<verbose>true</verbose>
<fork>false</fork>
<compilerId>eclipse</compilerId>
</configuration>
<dependencies>
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-compiler-eclipse</artifactId>
<version>1.5.1</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
</project>

If you execute "mvn clean compile" then there will only be 1 class file, Foo.class, in the target/classes/com/abc/logging directory. However if you change the pom's <compilerId> element to be javac then 3 classes are now in the target folder. This would indicate an eclipse compiler bug, but wait there's more. The plexus-eclipse-compiler component uses the org.eclipse.jdt.core:core:3.1.0 repo artifact for compiling. So if you run the batch compiler in the core-3.1.0 jar like

java -jar <repo path>/org/eclipse/jdt/core/3.1.0/core-3.1.0.jar -verbose -d target/classes src/main/java

then you will get the following output indicating all 3 classes were created.

E:\dev\workspace-eclipse\compiler-test>java -jar "C:\Documents and Settings\wbeckwit\.m2\repository\org\eclipse\jdt\core\3.1.0\core-3.1.0.jar" -verbose -d target/classes -verbose src/main/java
Collecting source files inside E:\dev\workspace-eclipse\compiler-test\src\main\java
Collecting source files inside E:\dev\workspace-eclipse\compiler-test\src\main\resources
parsing E:\dev\workspace-eclipse\compiler-test\src\main\java\com\abc\logging\Foo.java - #1/2
parsing E:\dev\workspace-eclipse\compiler-test\src\main\java\com\abc\logging\Logger.java - #2/2
[reading java/lang/Object.class]
analyzing E:\dev\workspace-eclipse\compiler-test\src\main\java\com\abc\logging\Foo.java - #1/2
writing com\abc\logging\Foo.class - #1
completed E:\dev\workspace-eclipse\compiler-test\src\main\java\com\abc\logging\Foo.java - #1/2
analyzing E:\dev\workspace-eclipse\compiler-test\src\main\java\com\abc\logging\Logger.java - #2/2
[reading java/util/Map.class]
[reading java/util/HashMap.class]
[reading java/lang/Class.class]
[reading java/lang/String.class]
[reading java/lang/Throwable.class]
[reading java/io/Serializable.class]
[reading java/lang/Cloneable.class]
[reading java/util/AbstractMap.class]
writing com\abc\logging\Logger$Bar.class - #2
writing com\abc\logging\Logger.class - #3
completed E:\dev\workspace-eclipse\compiler-test\src\main\java\com\abc\logging\Logger.java - #2/2
[2 units compiled]
[3 .class files generated]
----------
1. WARNING in E:\dev\workspace-eclipse\compiler-test\src\main\java\com\abc\logging\Logger.java
(at line 8)
private boolean debug; // *** comment this invocation out and the class file will be generated
^^^^^
The field Logger.debug is never read locally
----------
1 problem (1 warning)
E:\dev\workspace-eclipse\compiler-test>

Also if you use the lastest 3.2 eclipse compiler available here, http://download.eclipse.org/eclipse/downloads/drops/R-3.2-200606291905/download.php?dropFile=ecj.jar, then you still get 3 classes compiled.

Therefore this indicates a maven bug, but wait there's even more. The Logger.java file has 2 "// ***" comments in it. If you comment out the boolean declaration then the eclipse compiler, when invoked through maven, will create the 3 class files. Howeve if you also comment out the marked method invocation then the we're back to getting only 1 class file generated. WTF!? Again javac invoked via maven and the eclipse core-3.1.0 compiler always generates 3 class files. Can someone help the universe make sense again?

Setting the <fork> element to true has no affect on the results seen.

  • Options
    • Sort By Name
    • Sort By Date
    • Ascending
    • Descending
    • Download All

Attachments

  1. Hide
    Zip Archive
    compiler-test.zip
    27/Aug/06 11:04 AM
    2 kB
    Binyan
    1. XML File
      compiler-test/pom.xml 1 kB
    2. Java Source File
      compiler-test/src/main/.../logging/Foo.java 0.1 kB
    3. Java Source File
      compiler-test/src/.../logging/Logger.java 0.7 kB
    Download Zip
    Show
    Zip Archive
    compiler-test.zip
    27/Aug/06 11:04 AM
    2 kB
    Binyan

Issue Links

relates to

Bug - A problem which impairs or prevents the functions of the product. PLXCOMP-59 Possible problem with class files not being created by plexus-compiler-eclipse

  • Critical - Crashes, loss of data, severe memory leak.
  • Closed - The issue is considered finished, the resolution is correct. Issues which are not closed can be reopened.

Activity

Ascending order - Click to sort in descending order
  • All
  • Comments
  • Work Log
  • History
  • Activity
Hide
Permalink
Nicholas Daley added a comment - 22/Feb/07 6:13 PM

Same thing happens to me.
I'm running Mac OS X 10.3. And am using it so that I can compile Java 5 code (as Java 5 isn't available for Mac OS X 10.3).

I've tried running the eclipse compiler directly from the command line (same as the guy above), and all of my files compile (again the same).

But, when I compile through maven only about half of the files compile.

Show
Nicholas Daley added a comment - 22/Feb/07 6:13 PM Same thing happens to me. I'm running Mac OS X 10.3. And am using it so that I can compile Java 5 code (as Java 5 isn't available for Mac OS X 10.3). I've tried running the eclipse compiler directly from the command line (same as the guy above), and all of my files compile (again the same). But, when I compile through maven only about half of the files compile.
Hide
Permalink
Nicholas Daley added a comment - 22/Feb/07 6:58 PM

Is this a problem with maven-compiler-plugin?
Or is it a problem with plexus-compiler-eclipse?
Should this issue be moved to the plexus project's issue tracker?

Show
Nicholas Daley added a comment - 22/Feb/07 6:58 PM Is this a problem with maven-compiler-plugin? Or is it a problem with plexus-compiler-eclipse? Should this issue be moved to the plexus project's issue tracker?
Hide
Permalink
Nicholas Daley added a comment - 22/Feb/07 7:09 PM

Given that maven-compiler-plugin works fine with plexus-compiler-javac, I assume that this is actually a problem in plexus-compiler-eclipse.

NOTE: I do not know anything about the internals of these projects, so this is just an educated guess.
So I am linking MCOMPILER-43 issue to a newly created PLXCOMP-59 issue.

Show
Nicholas Daley added a comment - 22/Feb/07 7:09 PM Given that maven-compiler-plugin works fine with plexus-compiler-javac, I assume that this is actually a problem in plexus-compiler-eclipse. NOTE: I do not know anything about the internals of these projects, so this is just an educated guess. So I am linking MCOMPILER-43 issue to a newly created PLXCOMP-59 issue.
Hide
Permalink
Benjamin Bentmann added a comment - 07/Dec/08 12:53 PM

The underyling issue PLXCOMP-59 has just been fixed in org.codehaus.plexus:plexus-compiler-eclipse:1.6-SNAPSHOT. If somebody wants to take it for a test drive: Guide to Testing Development Versions of Plugins

Show
Benjamin Bentmann added a comment - 07/Dec/08 12:53 PM The underyling issue PLXCOMP-59 has just been fixed in org.codehaus.plexus:plexus-compiler-eclipse:1.6-SNAPSHOT. If somebody wants to take it for a test drive: Guide to Testing Development Versions of Plugins
Hide
Permalink
Holger Hoffstätte added a comment - 09/Dec/08 4:33 AM

Thanks - I used the attached test project and can confirm that it works properly now.

Show
Holger Hoffstätte added a comment - 09/Dec/08 4:33 AM Thanks - I used the attached test project and can confirm that it works properly now.
Hide
Permalink
John Casey added a comment - 05/Feb/10 3:47 PM

comments indicate this has been fixed with maven-compiler-plugin 2.1, which uses plexus-compiler-* version 1.6.

Show
John Casey added a comment - 05/Feb/10 3:47 PM comments indicate this has been fixed with maven-compiler-plugin 2.1, which uses plexus-compiler-* version 1.6.

People

  • Assignee:
    John Casey
    Reporter:
    Binyan
Vote (4)
Watch (4)

Dates

  • Created:
    27/Aug/06 11:04 AM
    Updated:
    05/Feb/10 3:47 PM
    Resolved:
    05/Feb/10 3:47 PM
  • Atlassian JIRA (v5.0.4#731-sha1:3aa7374)
  • Report a problem
  • Powered by a free Atlassian JIRA open source license for Codehaus. Try JIRA - bug tracking software for your team.