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

时间:2015-10-05 22:30:35

标签: maven gradle gradlew springfox

我正在尝试使用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遵守我使用带有-SNAPSHOT工件的本地maven repo的请求。

这是顶级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"
}

1 个答案:

答案 0 :(得分:0)

因此顶级build.gradle似乎可以有多个repositories{}块。我已正确地将mavenLocal()添加到一个,但错过了另一个。将mavenLocal()添加到第二个块后,一切运行良好。