4

I'm currently learning how to use Maven to build projects that I write in Java. Before, I've only used javac to compile my projects and I've gotten used to the error messages produced by it. I tried to compile the following erroneous, test program using mvn compile and then javac manually:

public class App {
    public static void main( String[] args )
    {
        System.out.print(a);
    }
}

javac produces:

App.java:5: error: cannot find symbol
    System.out.print(a);
                     ^
  symbol:   variable a
  location: class App
1 error

but mvn compile produces this (among a bunch of other stacktraces and output):

...     
[ERROR] /home/htor/maven-test/cflat/src/main/java/no/uio/ifi/cflat/App.java:[5,25] error: cannot find symbol
[ERROR] -> [Help 1]
...

The latter is not as useful as the first error message and it doesn't contain the full error message from javac. I've tried using -e and -X but the error is reported identically, just with more noice around.

How can I get the full Javac error message in the error messages from Maven?

1 Answers1

3

After searching a bit more it seems this behaviour was caused by a bug in the Maven compiler plugin. The solution to this question solved my problem: maven "cannot find symbol" message unhelpful. Just add this to your pom.xml file to use the newest compiler plugin:

<project>
    ...
    <build>
        ....
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.1</version>
                <configuration>
                    <source>1.7</source>
                    <target>1.7</target>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>
Community
  • 1
  • 1
  • You rock. The current version of swagger codegen (2.1.4) creates a pom.xml with the old, bad value. This made errors sensible again. – Steve Broberg Dec 09 '15 at 18:20