简体   繁体   中英

Maven - Unable to resolve maven dependency locally for version range

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:

<?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>

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>

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:)

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:

            <version>_____3,0)</version>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM