1

I encounter a very strange problem with Maven and Eclipse compiler.

While in Eclipse+m2eclipse, I have no problem compiling a small project (archetype quick start) with the following single class.

package test.test;
import com.Ostermiller.util.CSVParser;
public class TestCaseSensitive {
    CSVParser csvParser;
}

Ostermiller utils is added to pom.xml. Eclipse Kepler compiles the project. Next, mvn compile works out-of-the-box.

Now the issue, I switch to compiler 3.1 and asks for Eclipse compiler (to be able to handle same compilation issues in console mode as well as IDE mode). This is the POM :

<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>test</groupId>
<artifactId>test</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>

<name>test</name>
<url>http://maven.apache.org</url>

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<dependencies>
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>3.8.1</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.ostermiller</groupId>
        <artifactId>utils</artifactId>
        <version>1.07.00</version>
    </dependency>
</dependencies>

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.1</version>
            <configuration>
                <compilerId>eclipse</compilerId>
                <source>1.7</source>
                <target>1.7</target>
                <optimize>true</optimize>
                <showWarnings>true</showWarnings>
                <showDeprecation>true</showDeprecation>
                <fork>false</fork>
                <compilerArgument>-err:nullAnnot,null</compilerArgument>
            </configuration>
            <dependencies>
                <dependency>
                    <groupId>org.codehaus.plexus</groupId>
                    <artifactId>plexus-compiler-eclipse</artifactId>
                    <version>2.2</version>
                </dependency>
            </dependencies>
        </plugin>
    </plugins>
</build>

And now here is the result :

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project test: Compilation failure: Compilation failure:
[ERROR] /home/me/workspaces/4/3/ws/test/src/main/java/test/test/TestCaseSensitive.java:[3] The import com.Ostermiller cannot be resolved
[ERROR] /home/me/workspaces/4/3/ws/test/src/main/java/test/test/TestCaseSensitive.java:[7] CSVParser cannot be resolved to a type

The package com.Ostermiller exists (it compiles in maven default compiler as well in Eclipse IDE), but not after switching to eclipse compiler.

Please note that the reported error path is also wrong :

[ERROR] /home/me/workspaces/4/3/ws/test/src/main/java/...

should be

[ERROR] /home/me/workspaces/4.3/ws/test/src/main/java/...

Has someone an idea? Where shall the potential bug be reported?

Chandrayya G K
  • 8,719
  • 5
  • 40
  • 68
Sebastien
  • 279
  • 1
  • 10
  • I'm having the same issue except my error is: `The import org.xbill.DNS cannot be resolved`. It's definitely on the classpath as I can see with `mvn -X`. The only thing I could possibly see in common is that both our imports have capital letters in the package name. Maybe it has problems with that. – onlynone Apr 21 '16 at 15:44
  • There's also this question: http://stackoverflow.com/questions/17749375 where the asker is having problems with `org.omg.CORBA.IntHolder`. I think the upper case has the be related. – onlynone Apr 21 '16 at 15:48

1 Answers1

1

Have you tried using the jdt compiler provided by tycho?

See http://wiki.eclipse.org/Tycho/FAQ#Can_I_use_the_Tycho_compiler_support_in_non-OSGi_projects.2C_too.3F

That'd give you :

<plugin>
  <!-- Use compiler plugin with tycho as the adapter to the JDT compiler. -->
  <artifactId>maven-compiler-plugin</artifactId>
  <configuration>
     <compilerId>jdt</compilerId>
     <source>1.7</source>
     <target>1.7</target>
     <optimize>true</optimize>
     <showWarnings>true</showWarnings>
     <showDeprecation>true</showDeprecation>
     <fork>false</fork>
     <compilerArgument>-err:nullAnnot,null</compilerArgument>
  </configuration>
  <dependencies>
     <!-- This dependency provides the implementation of compiler "jdt": -->
     <dependency>
       <groupId>org.eclipse.tycho</groupId>
       <artifactId>tycho-compiler-jdt</artifactId>
       <version>${tycho-version}</version>
     </dependency>
   </dependencies>
</plugin>

Currently tycho-version=0.18.0

Fred Bricon
  • 5,369
  • 1
  • 31
  • 45
  • Yes I did, but there are incompatibilities with maven-compiler-plugin (Maven 3.1, Tycho 0.18.0). I also tried all tycho versions from 18 to 14 (I don't have the stacktrace anymore). Maven complains about a method which is not implemented by tycho : API missing method... Apparently, errors and warning have issues being transfered from Tycho to Maven. – Sebastien Jul 19 '13 at 18:20
  • tycho 0.18.1, compatible with maven 3.1.0, is now available – Fred Bricon Jul 30 '13 at 08:05