maven compilation error: duplicate classes

vpalle picture vpalle · May 19, 2009 · Viewed 40.7k times · Source

In my maven2 project I have a directory ${basedir}/autogen that contains some autogenerated source code files produced by wsdl2java.

When running mvn compile I get an compilation error, because of duplicate classes, that lives in ${basedir}/autogen. This is true. But what is the compilation phase doing in ${basedir}/autogen? I have not told maven to add this directory as a source directory. And there seems to be no way of telling maven to ignore the directory.

Answer

Nicholas Hemley picture Nicholas Hemley · Sep 19, 2011

I had the same problem when using the maven-processor-plugin and found that the solution was to configure the maven-compiler plugin as follows:

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>2.1</version>
            <configuration>
                <source>1.6</source>
                <target>1.6</target>
                <compilerArgument>-proc:none</compilerArgument>
            </configuration>
        </plugin>

-proc:none means that compilation takes place without annotation processing and therefore no duplicate classes (which are typically generated in the generate-sources phase)

I hope that helps.