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

查看:39
本文介绍了在配置文件 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>
				<sourceDirectory>... )

pom中的定义如下:

<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?

推荐答案

根据 文档,您只能更改配置文件中的少数 参数, 不是其中之一.

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

我会配置主 以从某些属性(例如 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天全站免登陆