1

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:

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>
Community
  • 1
  • 1
Vladimir
  • 19
  • 4
  • 1
    The maven way of doing this would be to have an API module for the interface of the class and a separate module for each implementation of that class. Sounds a bit like over engineering for that single class, but that is how maven is supposed to work. Have you considered this option? – SpaceTrucker Mar 12 '13 at 13:38

0 Answers0