【问题标题】:Different result by different profile activate method?不同配置文件激活方法的结果不同?
【发布时间】:2013-03-05 06:15:29
【问题描述】:

我使用 maven 大约两年了,但我认为我对 maven 中的配置文件并不完全了解,尤其是当我遇到以下问题时。

我有一个maven项目,三个模块,secweb-parent、secweb-service和secweb-web,secweb-sevice依赖spring-webmvc,secweb-web依赖secweb-service。

问题是:

1)当我使用'mvn clean install -Dinclude'时,效果很好,在secweb-web.war中会找到spring-mvc.jar

2)当我使用'mvn clean install -Pinclude-jar'时不起作用,在secweb-web.war中找不到spring-mvc.jar p>

有人知道为什么吗?使用配置文件时有什么需要注意的吗?

(我知道我可以定义依赖范围,这里这个项目只是为了演示不同配置文件激活方法的不同结果)


用于 secweb-parent 的 pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <properties>
        <project.version>1.0.0</project.version>
    </properties>

    <groupId>com.mediatek.dt</groupId>
    <artifactId>secweb-parent</artifactId>
    <version>${project.version}</version>
    <packaging>pom</packaging>

    <modules>
        <module>../secweb-web</module>
        <module>../secweb-service</module>
    </modules>
</project>

用于 secweb 服务的 pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <parent>
        <groupId>com.mediatek.dt</groupId>
        <artifactId>secweb-parent</artifactId>
        <version>${project.version}</version>
        <relativePath>../secweb-parent</relativePath>
    </parent>

    <artifactId>secweb-service</artifactId>

    <profiles>
        <profile>
            <id>include-jar</id>
            <activation>
                <property>
                    <name>include</name>
                </property>
            </activation>
            <dependencies>
                <dependency>
                    <groupId>org.springframework</groupId>
                    <artifactId>spring-webmvc</artifactId>
                    <version>2.5</version>
                </dependency>
            </dependencies>
        </profile>
    </profiles>
</project>

用于 secweb-web 的 pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <parent>
        <groupId>com.mediatek.dt</groupId>
        <artifactId>secweb-parent</artifactId>
        <version>${project.version}</version>
        <relativePath>../secweb-parent</relativePath>
    </parent>

    <artifactId>secweb-web</artifactId>
    <packaging>war</packaging>

    <dependencies>
        <dependency>
            <groupId>com.mediatek.dt</groupId>
            <artifactId>secweb-service</artifactId>
            <version>${project.version}</version>
        </dependency>
    </dependencies>
</project>

【问题讨论】:

    标签: maven


    【解决方案1】:

    您可以使用Maven Help Plugin 来检查活动配置文件,如下例所示

    change directory to the parent
    e.g. cd /my/project/secweb-parent
    Then execute the following command twice for comparing
    
    mvn help:help:active-profiles
    
    mvn help:help:active-profiles -Pinclude-jar
    

    无论如何,重要的一点是版本,您已定义为1.0.0。我更喜欢使用 1.0.0-SNAPSHOT

    您可能会看到有关 SNAPSHOT 的更多信息,here

    你为什么要使用这个? SNAPSHOT 版本用于正在积极开发的项目。如果您的项目依赖于正在积极开发的软件组件,您可以依赖 SNAPSHOT 版本,并且 Maven 会在您运行构建时定期尝试从存储库下载最新的快照。同样,如果您的系统的下一个版本将具有“1.4”版本,那么在正式发布之前,您的项目将具有“1.4-SNAPSHOT”版本。

    作为默认设置,Maven 不会检查远程存储库上的 SNAPSHOT 版本。要依赖 SNAPSHOT 版本,用户必须明确启用使用 POM 中的存储库或 pluginRepository 元素下载快照的能力。

    在我们的 stackoverflow 上还有一个关于快照的有用问答,here 也是如此。

    我希望这会有所帮助。

    【讨论】:

    • 感谢您的回复,但我找不到与 1) mvn help:help:active-profiles 和 2) mvn help:help:active-profiles -Pinclude-jar 的输出有任何不同之处.
    猜你喜欢
    • 2010-11-04
    • 2011-11-12
    • 2014-10-29
    • 1970-01-01
    • 2019-11-02
    • 2015-08-19
    • 1970-01-01
    • 1970-01-01
    • 2020-11-07
    相关资源
    最近更新 更多