在配置文件Maven中更改源目录 [英] Change source directory in profile maven

查看:309
本文介绍了在配置文件Maven中更改源目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想为特定的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>... )

pom中的定义如下:

The definition in the pom is as follows:

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

当且仅当此配置文件处于活动状态时,我试图做的工作是在编译源文件之前对其进行处理.我的过程将动态更改源文件,将更改后的源扔到"new-src"目录中,然后像通常的"src/main/java"一样编译该目录.生命周期中的其他所有内容都应正常运行.如果这种方法有缺陷,谁能指出我正确的方向?

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?

推荐答案

根据文档,您只能在配置文件中更改几个<build>参数,而<sourceDirectory>不是其中之一.

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

我将主<build>配置为从某些属性(例如src.dir)定义的路径中获取源,将此属性设置为src/main/java并在自定义配置文件中覆盖它:

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>

这篇关于在配置文件Maven中更改源目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆