代码之家  ›  专栏  ›  技术社区  ›  Anders Sandvig

如何告诉Maven使用依赖项的最新版本?

  •  702
  • Anders Sandvig  · 技术社区  · 18 年前

    在Maven中,依赖项通常设置如下:

    <dependency>
      <groupId>wonderful-inc</groupId>
      <artifactId>dream-library</artifactId>
      <version>1.2.3</version>
    </dependency>
    

    现在,如果您正在使用频繁发布的库,那么不断更新<version>标记可能会有点烦人。有没有办法告诉Maven总是使用最新的可用版本(从存储库中)?

    12 回复  |  直到 7 年前
        1
  •  685
  •   Stephan    8 年前

    LATEST RELEASE have been dropped in Maven 3 "for the sake of reproducible builds" Maven 3 compliant solution


    POM Syntax section of the Maven book Dependency Version Ranges

    • [ ]
    • ( )

    <?xml version="1.0" encoding="UTF-8"?><metadata>
      <groupId>com.foo</groupId>
      <artifactId>my-foo</artifactId>
      <version>2.0.0</version>
      <versioning>
        <release>1.1.1</release>
        <versions>
          <version>1.0</version>
          <version>1.0.1</version>
          <version>1.1</version>
          <version>1.1.1</version>
          <version>2.0.0</version>
        </versions>
        <lastUpdated>20090722140000</lastUpdated>
      </versioning>
    </metadata>
    

    version ranges

    <version>[1.0.1]</version>
    

    <version>1.0.1</version>
    

    <version>[1.0.0,2.0.0)</version>
    

    <version>[1.0.0,)</version>
    

    <version>LATEST</version>
    

    <version>RELEASE</version>
    

    Maven super POM


    Tim's answer maven-versions-plugin versions:use-latest-versions versions:use-latest-releases

        2
  •  341
  •   Tim    9 年前
        3
  •  162
  •   Simon Forsberg Kyle Rosendo    10 年前

    this page

    <version>[1.2.3,)</version>
    

        4
  •  75
  •   Adam Gent    9 年前

    mvn clean versions:use-latest-versions scm:checkin deploy -Dmessage="update versions" -DperformRelease=true
    

            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>versions-maven-plugin</artifactId>
                <version>1.2</version>
                <configuration>
                    <includesList>com.snaphop</includesList>
                    <generateBackupPoms>false</generateBackupPoms>
                    <allowSnapshots>true</allowSnapshots>
                </configuration>
            </plugin>
    

        5
  •  29
  •   mkobit    11 年前

    Dependency Version Requirement Specification

    version

    • 1.0
    • [1.0]
    • (,1.0]
    • [1.2,1.3]
    • [1.0,2.0)
    • [1.5,)
    • (,1.0],[1.2,)
    • (,1.1),(1.1,)

    <version>[1.2.3,)</version>

        6
  •  14
  •   Martin Klinke    18 年前

        7
  •  6
  •   trung    11 年前

    mvn -U dependency:copy -Dartifact=com.foo:my-foo:LATEST
    // pull the latest snapshot for my-foo from all repositories
    
        9
  •  4
  •   Verhagen    10 年前
        10
  •  2
  •   Markon    9 年前

    versions-maven-plugin

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

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

    mvn versions:update-properties validate
    

    [INFO] Updated ${myname.version} from 1.1.1 to 1.3.2
    
        11
  •  1
  •   Arayan Singh    8 年前

    Versions Maven Plugin answer

    Pascal Thivent

    <properties>
        <spring.version>3.1.2.RELEASE</spring.version>
    </properties>
    
    <dependencies>
    
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-core</artifactId>
            <version>${spring.version}</version>
        </dependency>
    
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context</artifactId>
            <version>${spring.version}</version>
        </dependency>
    
    </dependencies>
    

        12
  •  1
  •   yilin    7 年前

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

    atl + F5 force update of snapshots/release

    推荐文章