Change source directory in profile maven

According to the documentation, you can change only few <build> parameters in the profile and <sourceDirectory> is not one of them.

I’d configure the main <build> to take sources from path defined by some property (eg. src.dir), set this property to src/main/java and override it in the custom profile:

<project>
    ...
    <properties>
        <src.dir>src/main/java</src.dir>
    </properties>
    <build>
        <sourceDirectory>${src.dir}</sourceDirectory>
        ...
    </build>
    <profiles>
        <profile>
            <id>development</id>
            <properties>
                <src.dir>${project.build.directory}/new-src</src.dir>
            </properties>
        </profile>
    </profiles>
</project>

Leave a Comment