【问题标题】:Is it possible to exclude (or include) classes or resources on a per profile basis in Maven?是否可以在 Maven 中基于每个配置文件排除(或包含)类或资源?
【发布时间】:2018-07-18 19:20:40
【问题描述】:

我有两个 Maven 配置文件 P1 和 P2,我想做的是根据我用于构建项目的配置文件,应该排除某些资源。

例如

<profiles>
    <profile>
        <id>P1</id>
        <properties>
            <app.home>Path to project home</app.home>
            <exclude>src/main/java/foo/*.*</exclude> <!-- need to exclude all files in src/main/java/foo in this profile -->
        </properties>
    </profile>
    <profile>
        <id>P2</id>
        <properties>
            <app.home>Path to project home</app.home>
            <exclude>src/main/java/bar/*.*</exclude> <!-- need to exclude all files in src/main/java/bar in this profile-->
        </properties>
    </profile>
</profiles>

所以,在这里我要做的是在使用 P1 配置文件构建时排除 src/main/java/foo/ 中的所有文件,并在使用 P2 构建时排除 src/main/java/bar 中的所有文件个人资料。

这可能吗?如果没有,是否有其他选择?

【问题讨论】:

  • 你应该使用两个独立的模块,这意味着有一个多模块构建。因为这违反了关注点分离。

标签: java maven


【解决方案1】:

您可以将buildMaven Compiler Plugin 添加到您的个人资料中,并在其中添加exclude

例如

<profile>
    <id>P1</id>
    <properties>
        <app.home>Path to project home</app.home>
    </properties>
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <excludes>
                        <exclude>**src/main/java/foo/*.*</exclude>
                    </excludes>
                </configuration>
            </plugin>
        </plugins>
    </build>
</profile>

更多信息请参见Maven: excluding java files in compilation

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-06-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-01-31
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多