有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java Maven依赖关系仅用于测试目的

我有一个maven依赖项,如下所示:

<dependency>
    <groupId>org.springframework.data</groupId>
    <artifactId>spring-data-jpa</artifactId>
    <version>${version}</version>
</dependency>

问题是${version}属性应该替换为1.8.1。发布或1.9.0。根据安装时选择的配置文件发布,但仅用于测试1.9.0。应该使用RELEASE,即使我使用的是1.8.1配置文件。有办法做到这一点吗?我尝试使用测试范围,但它没有像我认为的那样工作


共 (1) 个答案

  1. # 1 楼答案

    你喜欢这个工作吗

    <profiles>
        <profile>
            <id>defaultProfile</id>
            <activation>
                <activeByDefault>true</activeByDefault>
            </activation>
            <properties>
                <magicVersion>1.9.0.RELEASE</magicVersion>
            </properties>
        </profile>
        <profile>
            <id>Release181</id>
            <properties>
                <magicVersion>1.8.1.RELEASE</magicVersion>
            </properties>
        </profile>
        <profile>
            <id>test</id>
            <properties>
                <magicVersion>1.9.0.RELEASE</magicVersion>
            </properties>
        </profile>      
    </profiles>
    

    激活测试配置文件的想法将覆盖版本,即使您的1.8.1配置文件已经设置了该版本。用例是

    mvn -P Release181,test test