In my project i use two source directory (by build-helper-maven-plugin). I have a class that present in both of them. So, when i try to run "mvn compile", i get "Class is duplicated" error.
I can't delete one of the files - both of them must be present and i need to solve this problem by tuning pom.xml.
I've looked trough this topics:
- What's the "right" way to (temporarily) exclude sources from a maven build, and is there an easy way to do it from Eclipse?
- How to ignore .java files when compiling using maven?
but the solutions don't work for me. I've realized that i can't specify an absolute path to the file using maven-compiler-plugin section - only relative path from the root of the source directory. So, i can either exclude both of them or include both.
POM.xml:
<project>
<modelVersion>4.0.0</modelVersion>
<artifactId>child-project</artifactId>
<packaging>war</packaging>
<name>child-project</name>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<parent>
<groupId>com.project</groupId>
<artifactId>project</artifactId>
<relativePath>../pom.xml</relativePath>
<version>1.0</version>
</parent>
<build>
<finalName>child-project</finalName>
<!-- First source directory. Contains A.java file i need to exclude-->
<sourceDirectory>${basedir}/src</sourceDirectory>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.5.1</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
<!-- doesn't work
<excludes>
<exclude>${basedir}/src/com/project/A.java</exclude>
</excludes>
-->
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<executions>
<execution>
<phase>generate-sources</phase>
<goals><goal>add-source</goal></goals>
<configuration>
<sources>
<!-- Second source directory. Contains A.java file i need to include-->
<source>${custom-directory}/webapp/src</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
...
</plugins>
</build>
</project>