在配置文件中提供依赖关系和在maven pom.xml

时间:2015-09-03 04:47:41

标签: maven pom.xml

在配置文件中提供依赖项和提供正常依赖项之间有什么区别。

下面给出了一个仅包含依赖关系和配置文件块的pom.xml。

但我不知道有什么区别。

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

    <dependencies>
        <dependency>
            <groupId>org.apache.storm</groupId>
            <artifactId>storm-kafka</artifactId>
            <version>0.9.3</version>
        </dependency>       
    </dependencies>

    <profiles>
        <profile>
            <id>one</id>                
            <dependencies>
                <dependency>
                    <groupId>org.apache.storm</groupId>
                    <artifactId>storm-core</artifactId>
                    <version>0.9.3</version>                    
                </dependency>               
            </dependencies>
        </profile>
        <profile>
            <id>two</id>
            <activation>
                <activeByDefault>true</activeByDefault>
            </activation>
            <dependencies>
                <dependency>
                    <groupId>org.apache.storm</groupId>
                    <artifactId>storm-core</artifactId>
                    <version>0.9.3</version>
                    <scope>provided</scope>
                </dependency>
                <dependency>
                    <groupId>org.slf4j</groupId>
                    <artifactId>log4j-over-slf4j</artifactId>
                    <version>1.6.6</version>
                    <scope>provided</scope>
                </dependency>               
            </dependencies>
        </profile>
    </profiles>
</project>

1 个答案:

答案 0 :(得分:2)

配置文件处于活动状态时,仅应用配置文件中的依赖关系和配置。在您的情况下,默认情况下,配置文件1不活动,因此您必须在调用Maven时激活它。由于<activeByDefault>true</activeByDefault>,配置文件2始终处于活动状态。 您可以使用参数-P激活配置文件,例如mvn clean install -Pone

相关问题