Maven - 无法在本地解决版本范围的 Maven 依赖关系

Maven - Unable to resolve maven dependency locally for version range

我正在尝试编译一个名为 web-server 的 Maven 项目,该项目依赖于指定依赖版本范围内的 search-client [2.0,3.0]。然而,由于存储库中“指定范围内没有版本可用于 > com.test.search:search-client:jar:[2.0,3.0)”,编译失败。

这些是我正在执行的步骤:

  1. 进行更改并在本地构建搜索客户端

这会在我的本地 m2 存储库中为此客户端 pom 构建一个 2.0-SNAPSHOT jar。

  1. 尝试构建依赖于上述的网络服务器

这不会编译并给出以下错误:

[ERROR] Failed to execute goal on project common: Could not resolve dependencies for project com.test.web:common:jar:2.0-SNAPSHOT: Failed to collect dependencies at com.test.search:search-client:jar:[2.0,3.0): No versions available for com.test.search:search-client:jar:[2.0,3.0) within specified range -> [Help 1]

Web 服务器 POM:

<?xml version="1.0" encoding="UTF-8"?>
<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/maven-v4_0_0.xsd">

    <modelVersion>4.0.0</modelVersion>

    <parent>
        <artifactId>web-parent</artifactId>
        <groupId>com.test.web</groupId>
        <version>2.0-SNAPSHOT</version>
    </parent>

    <artifactId>common</artifactId>
    <packaging>jar</packaging>

    <properties>
        <kotlin.version>1.3.61</kotlin.version>
    </properties>

    <dependencies>

        <dependency>
            <groupId>com.test.search</groupId>
            <artifactId>search-client</artifactId>
            <version>[2.0,3.0)</version>
        </dependency>
        
        .
        .
        .
        //Many More Dependencies
    </dependencies>

    <build>
        <sourceDirectory>src/main/kotlin</sourceDirectory>
        <testSourceDirectory>src/test/kotlin</testSourceDirectory>
        <!--<testSourceDirectory>src/test/kotlin</testSourceDirectory>-->
        <plugins>
            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
            </plugin>
            <plugin>
                <artifactId>maven-source-plugin</artifactId>
            </plugin>
            <plugin>
                <artifactId>maven-javadoc-plugin</artifactId>
            </plugin>
            <plugin>
                <groupId>org.jetbrains.kotlin</groupId>
                <artifactId>kotlin-maven-plugin</artifactId>
                <version>${kotlin.version}</version>
                <executions>
                    <execution>
                        <id>compile</id>
                        <phase>compile</phase>
                        <goals>
                            <goal>compile</goal>
                        </goals>
                    </execution>
                    <execution>
                        <id>test-compile</id>
                        <phase>test-compile</phase>
                        <goals>
                            <goal>test-compile</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <jvmTarget>1.8</jvmTarget>
                </configuration>
            </plugin>
        </plugins>
    </build>

    <reporting>
        <plugins>
            <plugin>
                <artifactId>maven-javadoc-plugin</artifactId>
            </plugin>
        </plugins>
    </reporting>
</project>

搜索客户端 POM:

<?xml version="1.0" encoding="UTF-8"?>
<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">
    <parent>
        <artifactId>search-parent</artifactId>
        <groupId>com.test.search</groupId>
        <version>2.0-SNAPSHOT</version>
    </parent>
    <modelVersion>4.0.0</modelVersion>

    <artifactId>search-client</artifactId>
    <packaging>jar</packaging>

    <name>test Search Client</name>

    <dependencies>

        <!-- test Search -->
        <dependency>
            <groupId>com.test.search</groupId>
            <artifactId>search-api</artifactId>
            <version>${project.parent.version}</version>
        </dependency>

        <!-- test -->
        <dependency>
            <groupId>com.test.common</groupId>
            <artifactId>common-client</artifactId>
        </dependency>

        <!-- Languages & Frameworks -->
        <dependency>
            <groupId>org.jetbrains.kotlin</groupId>
            <artifactId>kotlin-stdlib</artifactId>
        </dependency>

        <!-- Utils -->
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <scope>provided</scope>
        </dependency>

        <!-- Testing -->
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.jetbrains.kotlin</groupId>
            <artifactId>kotlin-test-junit</artifactId>
            <scope>test</scope>
        </dependency>

        <!-- Codecs -->
        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-core</artifactId>
        </dependency>
        <dependency>
            <groupId>com.fasterxml.jackson.module</groupId>
            <artifactId>jackson-module-kotlin</artifactId>
        </dependency>

    </dependencies>

    <build>
        <plugins>

            <plugin>
                <groupId>org.xolstice.maven.plugins</groupId>
                <artifactId>protobuf-maven-plugin</artifactId>
            </plugin>

            <plugin>
                <artifactId>kotlin-maven-plugin</artifactId>
                <groupId>org.jetbrains.kotlin</groupId>
            </plugin>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-source-plugin</artifactId>
            </plugin>

        </plugins>
    </build>

</project>

2.0-SNAPSHOT不在[2.0,3.0)吗?我被严格要求不要增加版本。另外,在这样的maven依赖设计中,如何进行本地开发?

请帮忙,我卡住了!

非常感谢:)

根据POM Reference, Version Order Specification

"1-snapshot" < "1" < "1-sp" (qualifier padding)

2.0-SNAPSHOT2.0,它总是在 Maven 中:快照版本是下一个发布版本的 pre-versions。

所以,不,2.0-SNAPSHOT 不在 [2.0,3.0) (2.0 <= x < 3.0) 中。 (1,3.0) (1 < x < 3.0) 应该做到。

而且,您的 Web 服务器 POM 中有一个拼写错误:

            <version>_____3,0)</version>