Question

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?

Was it helpful?

Solution

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top