Maven – 无法在本地解析Maven依赖项的版本范围

huangapple go评论76阅读模式
英文:

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. 进行更改并在本地构建 search-client

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

  1. 尝试构建依赖于上述搜索客户端的web-server

这不会编译,出现以下错误:

[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 Server 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>
        
        // 其他依赖项
    </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>

search-client 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依赖设计下,我应

英文:

I am trying to compile a Maven project named web-server which is dependent on search-client within the specified dependency version range [2.0,3.0). The compile fails however due to a "No versions available for > com.test.search:search-client:jar:[2.0,3.0) within specified range" in the repository.

These are the steps I am following:

  1. Make my changes and build search-client locally

This builds a 2.0-SNAPSHOT jar for this client pom in my local m2 repository.

  1. Try to build web-server which is dependent on the above

This does not compile giving the following error:

> [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 Server POM:

&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
&lt;project xmlns=&quot;http://maven.apache.org/POM/4.0.0&quot; xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot; xsi:schemaLocation=&quot;http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd&quot;&gt;
&lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
&lt;parent&gt;
&lt;artifactId&gt;web-parent&lt;/artifactId&gt;
&lt;groupId&gt;com.test.web&lt;/groupId&gt;
&lt;version&gt;2.0-SNAPSHOT&lt;/version&gt;
&lt;/parent&gt;
&lt;artifactId&gt;common&lt;/artifactId&gt;
&lt;packaging&gt;jar&lt;/packaging&gt;
&lt;properties&gt;
&lt;kotlin.version&gt;1.3.61&lt;/kotlin.version&gt;
&lt;/properties&gt;
&lt;dependencies&gt;
&lt;dependency&gt;
&lt;groupId&gt;com.test.search&lt;/groupId&gt;
&lt;artifactId&gt;search-client&lt;/artifactId&gt;
&lt;version&gt;[2.0,3.0)&lt;/version&gt;
&lt;/dependency&gt;
.
.
.
//Many More Dependencies
&lt;/dependencies&gt;
&lt;build&gt;
&lt;sourceDirectory&gt;src/main/kotlin&lt;/sourceDirectory&gt;
&lt;testSourceDirectory&gt;src/test/kotlin&lt;/testSourceDirectory&gt;
&lt;!--&lt;testSourceDirectory&gt;src/test/kotlin&lt;/testSourceDirectory&gt;--&gt;
&lt;plugins&gt;
&lt;plugin&gt;
&lt;artifactId&gt;maven-compiler-plugin&lt;/artifactId&gt;
&lt;/plugin&gt;
&lt;plugin&gt;
&lt;artifactId&gt;maven-source-plugin&lt;/artifactId&gt;
&lt;/plugin&gt;
&lt;plugin&gt;
&lt;artifactId&gt;maven-javadoc-plugin&lt;/artifactId&gt;
&lt;/plugin&gt;
&lt;plugin&gt;
&lt;groupId&gt;org.jetbrains.kotlin&lt;/groupId&gt;
&lt;artifactId&gt;kotlin-maven-plugin&lt;/artifactId&gt;
&lt;version&gt;${kotlin.version}&lt;/version&gt;
&lt;executions&gt;
&lt;execution&gt;
&lt;id&gt;compile&lt;/id&gt;
&lt;phase&gt;compile&lt;/phase&gt;
&lt;goals&gt;
&lt;goal&gt;compile&lt;/goal&gt;
&lt;/goals&gt;
&lt;/execution&gt;
&lt;execution&gt;
&lt;id&gt;test-compile&lt;/id&gt;
&lt;phase&gt;test-compile&lt;/phase&gt;
&lt;goals&gt;
&lt;goal&gt;test-compile&lt;/goal&gt;
&lt;/goals&gt;
&lt;/execution&gt;
&lt;/executions&gt;
&lt;configuration&gt;
&lt;jvmTarget&gt;1.8&lt;/jvmTarget&gt;
&lt;/configuration&gt;
&lt;/plugin&gt;
&lt;/plugins&gt;
&lt;/build&gt;
&lt;reporting&gt;
&lt;plugins&gt;
&lt;plugin&gt;
&lt;artifactId&gt;maven-javadoc-plugin&lt;/artifactId&gt;
&lt;/plugin&gt;
&lt;/plugins&gt;
&lt;/reporting&gt;
&lt;/project&gt;

search-client POM:

&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
&lt;project xmlns=&quot;http://maven.apache.org/POM/4.0.0&quot; xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot; xsi:schemaLocation=&quot;http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd&quot;&gt;
&lt;parent&gt;
&lt;artifactId&gt;search-parent&lt;/artifactId&gt;
&lt;groupId&gt;com.test.search&lt;/groupId&gt;
&lt;version&gt;2.0-SNAPSHOT&lt;/version&gt;
&lt;/parent&gt;
&lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
&lt;artifactId&gt;search-client&lt;/artifactId&gt;
&lt;packaging&gt;jar&lt;/packaging&gt;
&lt;name&gt;test Search Client&lt;/name&gt;
&lt;dependencies&gt;
&lt;!-- test Search --&gt;
&lt;dependency&gt;
&lt;groupId&gt;com.test.search&lt;/groupId&gt;
&lt;artifactId&gt;search-api&lt;/artifactId&gt;
&lt;version&gt;${project.parent.version}&lt;/version&gt;
&lt;/dependency&gt;
&lt;!-- test --&gt;
&lt;dependency&gt;
&lt;groupId&gt;com.test.common&lt;/groupId&gt;
&lt;artifactId&gt;common-client&lt;/artifactId&gt;
&lt;/dependency&gt;
&lt;!-- Languages &amp; Frameworks --&gt;
&lt;dependency&gt;
&lt;groupId&gt;org.jetbrains.kotlin&lt;/groupId&gt;
&lt;artifactId&gt;kotlin-stdlib&lt;/artifactId&gt;
&lt;/dependency&gt;
&lt;!-- Utils --&gt;
&lt;dependency&gt;
&lt;groupId&gt;org.projectlombok&lt;/groupId&gt;
&lt;artifactId&gt;lombok&lt;/artifactId&gt;
&lt;scope&gt;provided&lt;/scope&gt;
&lt;/dependency&gt;
&lt;!-- Testing --&gt;
&lt;dependency&gt;
&lt;groupId&gt;junit&lt;/groupId&gt;
&lt;artifactId&gt;junit&lt;/artifactId&gt;
&lt;scope&gt;test&lt;/scope&gt;
&lt;/dependency&gt;
&lt;dependency&gt;
&lt;groupId&gt;org.jetbrains.kotlin&lt;/groupId&gt;
&lt;artifactId&gt;kotlin-test-junit&lt;/artifactId&gt;
&lt;scope&gt;test&lt;/scope&gt;
&lt;/dependency&gt;
&lt;!-- Codecs --&gt;
&lt;dependency&gt;
&lt;groupId&gt;com.fasterxml.jackson.core&lt;/groupId&gt;
&lt;artifactId&gt;jackson-core&lt;/artifactId&gt;
&lt;/dependency&gt;
&lt;dependency&gt;
&lt;groupId&gt;com.fasterxml.jackson.module&lt;/groupId&gt;
&lt;artifactId&gt;jackson-module-kotlin&lt;/artifactId&gt;
&lt;/dependency&gt;
&lt;/dependencies&gt;
&lt;build&gt;
&lt;plugins&gt;
&lt;plugin&gt;
&lt;groupId&gt;org.xolstice.maven.plugins&lt;/groupId&gt;
&lt;artifactId&gt;protobuf-maven-plugin&lt;/artifactId&gt;
&lt;/plugin&gt;
&lt;plugin&gt;
&lt;artifactId&gt;kotlin-maven-plugin&lt;/artifactId&gt;
&lt;groupId&gt;org.jetbrains.kotlin&lt;/groupId&gt;
&lt;/plugin&gt;
&lt;plugin&gt;
&lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
&lt;artifactId&gt;maven-source-plugin&lt;/artifactId&gt;
&lt;/plugin&gt;
&lt;/plugins&gt;
&lt;/build&gt;
&lt;/project&gt;

Does 2.0-SNAPSHOT not lie in [2.0,3.0)? I have been strictly asked not to increase the version. Also, how can I go about local development in such maven dependency design?

Please help, I am stuck!

Many thanks in advance Maven – 无法在本地解析Maven依赖项的版本范围

答案1

得分: 5

根据POM参考,版本顺序规范

> "1-snapshot" < "1" < "1-sp"(资格填充)

2.0-SNAPSHOT小于2.0,这一直都是Maven中的情况:快照版本是下一个发布版本的预版本。

所以,2.0-SNAPSHOT不在[2.0,3.0)范围内(2.0 <= x < 3.0)。(1,3.0)(1 < x < 3.0)应该可以。

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

            &lt;version&gt;_____3,0)&lt;/version&gt;
英文:

According to POM Reference, Version Order Specification:

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

2.0-SNAPSHOT is less than 2.0, which always was in Maven: snapshot versions are the pre-versions of the next release version.

So, no, 2.0-SNAPSHOT does not lie in [2.0,3.0) (2.0 <= x < 3.0). (1,3.0) (1 < x < 3.0) should do it.

And, there's a typo in your Web Server POM:

            &lt;version&gt;_____3,0)&lt;/version&gt;

huangapple
  • 本文由 发表于 2020年8月10日 03:14:03
  • 转载请务必保留本文链接:https://go.coder-hub.com/63330353.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定