【问题标题】:Gradle: moving to multi project structure - cannot resolve repositoryGradle:移动到多项目结构 - 无法解析存储库
【发布时间】:2017-02-02 21:32:00
【问题描述】:

我有一个项目依赖于本地工件的几个依赖项。

此项目的 Gradle 构建工作正常,存储库设置正确:

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 build 时,我在工件的所有依赖项上都出现错误:

无法解析外部依赖

注意:我还在根目录中添加了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'
        }
    }
}

【问题讨论】:

  • 使用-i-d 标志运行会得到什么?那里应该有线索。
  • 我在id 看到的唯一相关消息是“在设置文件中未定义本地存储库。使用默认路径:/home/elad/.m2/repository”
  • 我认为你错过了apply plugin:,请参阅我的更新答案

标签: gradle build.gradle artifactory gradlew


【解决方案1】:

您需要将repository(和artifactory)块放入subprojectsallprojects 块中。因此:

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

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

同样对于artifactory,别忘了将artifactory插件应用到所有子项目中:

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

  ...
}

【讨论】:

  • 我做到了。使用完整的根 build.gradle 文件更新了问题。请查看。
【解决方案2】:

所以看了一些例子之后,我意识到buildscript 部分应该在subprojects 部分之外,而不是在里面。并且 apply plugin: 'com.jfrog.artifactory' 也应该添加到子项目部分中。

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

subprojects {
    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'
        }
    }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-03-05
    • 1970-01-01
    • 2021-11-24
    • 2017-12-03
    • 2013-06-10
    • 2018-09-12
    • 1970-01-01
    • 2013-07-06
    相关资源
    最近更新 更多