Change source directory in profile maven
Asked Answered
D

2

41

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?

Deil answered 2/10, 2013 at 15:36 Comment(0)
I
87

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>
Intwine answered 2/10, 2013 at 17:11 Comment(2)
So if (in Eclipse Luna) i added (linked) in my BuildPath (clicking the right mouse button on my MavenProject) a source folder where its directory is "/Users/MyName/Desktop/source", i have to write <src.dir>/Users/MyName/Desktop/source<src.dir> ?? And everything goes right?Ankara
@Tomek I'd like to know if the above setting will take in bootstrap template in the build path as well?Jargonize
R
1

See Maven model, it is not allowed to define a sourceDirectory within a profile. The only thing you can do is specify the sourceDirectory within the plugin configuration, assuming it is available.

Ronnie answered 2/10, 2013 at 17:5 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.