简体   繁体   中英

Gradle: resolve SNAPSHOT-dependency based on most recent version in either Maven Local or Remote repository

I want to have gradle intelligently use the most recent SNAPSHOT for a given dependency which is available.

Assuming i have a build file like this:

mavenCentral()
//    if (gradle.startParameter.refreshDependencies == false) {
    mavenLocal()
//   }
    maven {
      url "my_local_repo.com
   }
}

With a dependency listed like this:

compile (group: 'com.mystuff', name: 'my-library', version: '1.0.0-SNAPSHOT', changing: 'true')

Which may exist both in Maven Local and in the Remote repo "my_local_repo.com" how do I ensure that Gradle always compiles with the most recent snapshot?

My reading here:

http://www.gradle.org/docs/current/userguide/artifact_dependencies_tutorial.html

Specifically point 8.5:

A project can have multiple repositories. Gradle will look for a dependency in each repository in the order they are specified, stopping at the first repository that contains the requested module.

makes me believe that the mavneLocal version will always be preferred, however my reading of

51.7 here:

http://www.gradle.org/docs/current/userguide/dependency_management.html#sec:repositories

Given a required dependency, Gradle first attempts to resolve the module for that dependency. Each repository is inspected in order, searching first for a module descriptor file (POM or Ivy file) that indicates the presence of that module. If no module descriptor is found, Gradle will search for the presence of the primary module artifact file indicating that the module exists in the repository. ... Once each repository has been inspected for the module, Gradle will choose the 'best' one to use. This is done using the following criteria:

and 51.2.4

Alternatively, sometimes the module you request can change over time, even for the same version. An example of this type of changing module is a Maven SNAPSHOT module, which always points at the latest artifact published. In other words, a standard Maven snapshot is a module that never stands still so to speak, it is a “changing module”.

Muddies that substantially. It appears to say that all repo's are checked and the "best" choice is made (in this case presumably the most recent).

The bit I think you forgot to highlight from section 51.7 is this:

When the dependency is declared by a static version and a module descriptor file is found in a repository, there is no need to continue searching later repositories and the remainder of the process is short-circuited.

Which aligns with what is stated in section 8.5. But yes, for changing modules (ie. snapshots), Gradle will check every repo to find the latest artifact. For static modules, it will simply take the first one it finds.

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