How do I tell Maven to use the latest version of a dependency?

前端 未结 12 728
慢半拍i
慢半拍i 2020-11-21 11:37

In Maven, dependencies are usually set up like this:


  wonderful-inc

        
相关标签:
12条回答
  • 2020-11-21 12:24

    The truth is even in 3.x it still works, surprisingly the projects builds and deploys. But the LATEST/RELEASE keyword causing problems in m2e and eclipse all over the place, ALSO projects depends on the dependency which deployed through the LATEST/RELEASE fail to recognize the version.

    It will also causing problem if you are try to define the version as property, and reference it else where.

    So the conclusion is use the versions-maven-plugin if you can.

    0 讨论(0)
  • 2020-11-21 12:25

    The dependencies syntax is located at the Dependency Version Requirement Specification documentation. Here it is is for completeness:

    Dependencies' version element define version requirements, used to compute effective dependency version. Version requirements have the following syntax:

    • 1.0: "Soft" requirement on 1.0 (just a recommendation, if it matches all other ranges for the dependency)
    • [1.0]: "Hard" requirement on 1.0
    • (,1.0]: x <= 1.0
    • [1.2,1.3]: 1.2 <= x <= 1.3
    • [1.0,2.0): 1.0 <= x < 2.0
    • [1.5,): x >= 1.5
    • (,1.0],[1.2,): x <= 1.0 or x >= 1.2; multiple sets are comma-separated
    • (,1.1),(1.1,): this excludes 1.1 (for example if it is known not to work in combination with this library)

    In your case, you could do something like <version>[1.2.3,)</version>

    0 讨论(0)
  • 2020-11-21 12:26

    MY solution in maven 3.5.4 ,use nexus, in eclipse:

    <dependency>
        <groupId>yilin.sheng</groupId>
        <artifactId>webspherecore</artifactId>
        <version>LATEST</version> 
    </dependency>
    

    then in eclipse: atl + F5, and choose the force update of snapshots/release

    it works for me.

    0 讨论(0)
  • 2020-11-21 12:30

    Please take a look at this page (section "Dependency Version Ranges"). What you might want to do is something like

    <version>[1.2.3,)</version>
    

    These version ranges are implemented in Maven2.

    0 讨论(0)
  • 2020-11-21 12:32

    Are you possibly depending on development versions that obviously change a lot during development?

    Instead of incrementing the version of development releases, you could just use a snapshot version that you overwrite when necessary, which means you wouldn't have to change the version tag on every minor change. Something like 1.0-SNAPSHOT...

    But maybe you are trying to achieve something else ;)

    0 讨论(0)
  • 2020-11-21 12:32

    Sometimes you don't want to use version ranges, because it seems that they are "slow" to resolve your dependencies, especially when there is continuous delivery in place and there are tons of versions - mainly during heavy development.

    One workaround would be to use the versions-maven-plugin. For example, you can declare a property:

    <properties>
        <myname.version>1.1.1</myname.version>
    </properties>
    

    and add the versions-maven-plugin to your pom file:

    <build>
        <plugins>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>versions-maven-plugin</artifactId>
                <version>2.3</version>
                <configuration>
                    <properties>
                        <property>
                            <name>myname.version</name>
                            <dependencies>
                                <dependency>
                                    <groupId>group-id</groupId>
                                    <artifactId>artifact-id</artifactId>
                                    <version>latest</version>
                                </dependency>
                            </dependencies>
                        </property>
                    </properties>
                </configuration>
            </plugin>
        </plugins>
    </build>
    

    Then, in order to update the dependency, you have to execute the goals:

    mvn versions:update-properties validate
    

    If there is a version newer than 1.1.1, it will tell you:

    [INFO] Updated ${myname.version} from 1.1.1 to 1.3.2
    
    0 讨论(0)
提交回复
热议问题