Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change source directory in profile maven

Tags:

maven

I want to use a different source directory for a specific maven profile, however, when I try to specify it in the profile definition I get this error:

Unrecognised tag: 'sourceDirectory' (position: START_TAG seen ...<build>\r\n\t\t\t\t<sourceDirectory>... )

The definition in the pom is as follows:

<profile>
    <id>development</id>
    <build>
        <sourceDirectory>${project.build.directory}/new-src</sourceDirectory>
        .
        . 
        .
    </build>
</profile>

What I am trying to do is to process the source files before its compilation if and only if this profile is active. My process will change the source files on the fly, throw the changed sources in the "new-src" directory and compile that directory as if it was the usual "src/main/java". Everything else in the lifecycle should behave normally. If this approach is flawed, could anyone point me into the right direction?

like image 577
amaurs Avatar asked Oct 02 '13 15:10

amaurs


People also ask

Which option rightly gives the project's source directory in Maven?

Source Directories The Maven property ${project. basedir} defaults to the top level directory of the project, so the build directory defaults to the target directory in project base dir. It also sets the property ${project.

What is target directory in Maven?

The target directory is used to house all output of the build. The src directory contains all of the source material for building the project, its site and so on. It contains a subdirectory for each type: main for the main build artifact, test for the unit test code and resources, site and so on.

What is ${ Basedir in Maven?

basedir : The directory that the current project resides in. This means this points to where your Maven projects resides on your system. It corresponds to the location of the pom. xml file.


1 Answers

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> 
like image 193
Tomek Rękawek Avatar answered Oct 02 '22 10:10

Tomek Rękawek