如何配置 Gradle 以查找本地 SNAPSHOT 资源?

How to configure Gradle to find local SNAPSHOT resource?

我正在尝试使用 springfox 项目做一些工作,该项目已分为两个独立的项目:springfox 运行时和一套演示。

为了研究某些配置的行为,我需要更改 springfox/springfox-petstore 中的模块,并将其编译为 springfox-demos/springfox-java-swagger

springfox 中,我构建并发布了 springfox-petstore 的新版本,并验证它在 ~/.m2/repository/io/springfox/springfox-petstore/2.2.2-SNAPSHOT 中正确存在。

接下来,在 springfox-demos 中,我将 mavenLocal() 添加为存储库,并将 springfox-petstore-2.2.2-SNAPSHOT 添加为 changing=true 依赖项。

当我尝试构建 springfox-demos 运行时时,出现以下错误:

* What went wrong:
A problem occurred configuring project ':spring-java-swagger'.
 > Could not resolve all dependencies for configuration ':spring-java-swagger:runtimeCopy'.
   > Could not find io.springfox:springfox-petstore:2.2.2-SNAPSHOT.
     Searched in the following locations:
         https://jcenter.bintray.com/io/springfox/springfox-petstore/2.2.2-SNAPSHOT/maven-metadata.xml
         https://jcenter.bintray.com/io/springfox/springfox-petstore/2.2.2-SNAPSHOT/springfox-petstore-2.2.2-SNAPSHOT.pom
         https://jcenter.bintray.com/io/springfox/springfox-petstore/2.2.2-SNAPSHOT/springfox-petstore-2.2.2-SNAPSHOT.jar
         http://oss.jfrog.org/artifactory/oss-snapshot-local/io/springfox/springfox-petstore/2.2.2-SNAPSHOT/maven-metadata.xml
         http://oss.jfrog.org/artifactory/oss-snapshot-local/io/springfox/springfox-petstore/2.2.2-SNAPSHOT/springfox-petstore-2.2.2-SNAPSHOT.pom
         http://oss.jfrog.org/artifactory/oss-snapshot-local/io/springfox/springfox-petstore/2.2.2-SNAPSHOT/springfox-petstore-2.2.2-SNAPSHOT.jar
     Required by:
         springfox-demos:spring-java-swagger:unspecified

我尝试了构建任务的各种组合,但我似乎无法 Gradle 满足我使用本地 Maven 存储库和 -SNAPSHOT 工件的请求。

这里是顶级build.gradle:

buildscript {
  repositories {
    mavenLocal()
    jcenter()
  }

  dependencies {
    classpath "com.github.adrianbk:gradle-jvmsrc-plugin:0.6.1"
    classpath 'com.ofg:uptodate-gradle-plugin:1.6.0'
  }
}

apply from: "$rootDir/gradle/dependencies.gradle"

subprojects {
  apply plugin: 'com.github.adrianbk.jvmsrc'

  jvmsrc {
    packageName "springfoxdemo"
  }
  apply plugin: 'java'
  apply plugin: 'com.ofg.uptodate'

  repositories {
    jcenter()
    maven { url 'http://oss.jfrog.org/artifactory/oss-snapshot-local/' }
  }


  sourceCompatibility = 1.7
  targetCompatibility = 1.7

  configurations.all {
    //Dont cache snapshots
    resolutionStrategy.cacheChangingModulesFor 0, 'seconds'
  }
}

wrapper {
  gradleVersion = "2.4"
}

所以看起来顶级 build.gradle 可以有多个 repositories{} 块。我已经正确地将 mavenLocal() 添加到其中一个,但错过了另一个。将 mavenLocal() 添加到第二个块后,一切正常。