Gradle:转移到多项目结构 - 无法解析存储库

时间:2017-02-02 10:46:45

标签: gradle build.gradle artifactory gradlew

我有一个项目依赖于几个依赖项的本地神经。

Gradle build on this project工作正常,存储库的设置正确:

buildscript {
    repositories {
        maven {
            url "${artifactoryUrl}/libs-release"
        }
    }
    dependencies {
        classpath 'org.jfrog.buildinfo:build-info-extractor-gradle:4.4.10'
   }
}

repositories {
    maven {
        url "${artifactoryUrl}/repo"
    }
}

artifactory {
    contextUrl = "${artifactoryUrl}"
    publish {
        repository {
            repoKey = 'libs-snapshot-local' // The Artifactory repository key to publish to
            username = "${artifactoryUser}" // The publisher user name
            password = "${artifactoryPassword}" // The publisher password
        }
        defaults {
            // Reference to Gradle publications defined in the build script.
            // This is how we tell the Artifactory Plugin which artifacts should be
            // published to Artifactory.
            publications('mavenJava')
            publishArtifacts = true
            // Properties to be attached to the published artifacts.
            properties = ['qa.level': 'basic', 'dev.team' : 'core']
        }
    }
    resolve {
        repoKey = 'repo'
    }
}

我遵循了关于多项目结构的gradle教程。看起来我可以将“存储库”部分移动到根gradle.build文件。但是,当我运行gradle构建时,我收到了来自artifactory的所有依赖项的错误:

  

无法解决外部依赖

注意:我还在根目录中添加了gradle.properties文件,其中包含所有变量(artifactoryUrl等)。

因此,子项目似乎无法“看到”根gradle.build文件中定义的存储库。有什么建议吗?

更新

根目录上的build.gradle现在看起来像这样:

allprojects {
}

subprojects {
    buildscript {
        repositories {
            maven {
                url "${artifactoryUrl}/libs-release"
            }
        }
        dependencies {
            classpath 'org.jfrog.buildinfo:build-info-extractor-gradle:4.4.10'
       }
    }

    repositories {
        maven {
            url "${artifactoryUrl}/repo"
        }
    }

    artifactory {
        contextUrl = "${artifactoryUrl}"
        publish {
            repository {
                repoKey = 'libs-snapshot-local' // The Artifactory repository key to publish to
                username = "${artifactoryUser}" // The publisher user name
                password = "${artifactoryPassword}" // The publisher password
            }
            defaults {
                // Reference to Gradle publications defined in the build script.
                // This is how we tell the Artifactory Plugin which artifacts should be
                // published to Artifactory.
                publications('mavenJava')
                publishArtifacts = true
                // Properties to be attached to the published artifacts.
                properties = ['qa.level': 'basic', 'dev.team' : 'core']
            }
        }
        resolve {
            repoKey = 'repo'
        }
    }
}

2 个答案:

答案 0 :(得分:0)

您需要将repository(和artifactory)块放在subprojectsallprojects块中。就这样:

subprojects {
  repositories {
    maven {
        url "${artifactoryUrl}/repo"
    }
  }
  ...
}

这将确保根build.gradle将配置下推到每个子项目的配置中。

另外,对于神器,不要忘记将神器插件应用于所有子项目:

subprojects {
  apply plugin: "com.jfrog.artifactory"

  ...
}

答案 1 :(得分:0)

所以在看了一些例子之后,我意识到pBar.setProgress(ProgBarCount);部分应该在buildscript部分之外,而不是在里面。并且subprojects也应该在子项目部分中添加。

apply plugin: 'com.jfrog.artifactory'