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

The*_*nce 3 java pom.xml maven

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

这些是我正在遵循的步骤:

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

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

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

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

[错误] 无法在项目通用上执行目标:无法解析项目 com.test.web:common:jar:2.0-SNAPSHOT 的依赖项:无法在 com.test.search:search-client:jar:[2.0 处收集依赖项,3.0): 指定范围内没有可用于 com.test.search:search-client:jar:[2.0,3.0) 的版本 -> [帮助 1]

网络服务器 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>
Run Code Online (Sandbox Code Playgroud)

搜索客户端 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>
Run Code Online (Sandbox Code Playgroud)

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

请帮助,我被困住了!

提前谢谢了 :)

Ger*_*ica 5

根据POM 参考,版本订购规范

" 1-snapshot" < " 1" < " 1-sp"(限定符填充)

2.0-SNAPSHOT小于Maven 中始终存在的值2.0快照版本是下一个发布版本的预版本。

所以,不,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>
Run Code Online (Sandbox Code Playgroud)