简体   繁体   中英

Define sourceDirectory in Maven profiles

In my pom.xml file, I have:

<build>
    <sourceDirectory>src</sourceDirectory>
    <resources> .. </resources>
    <plugins> .. </plugins>
</build>

However, When I try to use maven profiles:

 <profiles>
    <profile>
        <id>profileId</id>
        <build>
            <sourceDirectory>src</sourceDirectory>
            <resources> .. </resources>
            <plugins> .. </plugins>
        </build>
    </profile>
 </profiles>

Maven gives me an error saying:

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

Why wouldn't it let me define a source directory within a profile? Is there a way to define sourceDirectory in profiles?

According to the documentation , you can change only few 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 ) and 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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM