【问题标题】:Artifactory virtual repository cannot resolve the Gradle-Artifactory pluginArtifactory 虚拟仓库无法解析 Gradle-Artifactory 插件
【发布时间】:2013-07-08 02:10:21
【问题描述】:

所以,我想尽办法让 build-info-extractor-gradle 插件正常工作……抱歉发泄了。 ;-)

我正在使用 gradle 包装器,指定 gradle 1.6、artifactory 3.0.0,并尝试指定对 build-info-extractor-gradle 插件 2.1.x-SNAPSHOT 的依赖,因为这是 specified version for gradle 1.5 及以上。

我试图关注这个tutorial video,但它必须是过时的,因为它仍然引用 gradle 1.0 并指定不包含插件 2.x 版本的 jfrog 存储库路径。


工件设置

  • 本地仓库 - “gradle-release-local” - 布局设置为 gradle-default
  • 远程仓库 - “gradle-plugins” - 从 jfrog 导入略微修改 - 例如http://repo.jfrog.org/artifactory/gradle-plugins-snapshots
  • 虚拟仓库 - “gradle” - “gradle-release-local” 和 “gradle-plugins”

Gradle 设置

settings.gradle(从工件生成)

buildscript {
    repositories {
        maven {
            url 'http://artifactory.build.somewhere.com:8081/artifactory/gradle'
            credentials {
                username = "${artifactory_user}"
                password = "${artifactory_password}"
            }
        }

    }
    dependencies {
        classpath 'org.jfrog.buildinfo:build-info-extractor-gradle:2.1.x-SNAPSHOT'
    }
}

allprojects {
    apply plugin: 'artifactory'
}

artifactory {
    contextUrl = "${artifactory_contextUrl}"   //The base Artifactory URL if not overridden by the publisher/resolver
    publish {
        repository {
            repoKey = 'gradle-release-local'
            username = "${artifactory_user}"
            password = "${artifactory_password}"
            maven = true
            ivy {
                ivyLayout = '[organization]/[module]/ivy-[revision].xml'
                artifactLayout = '[organization]/[module]/[revision]/[module]-[revision](-[classifier]).[ext]'
                mavenCompatible = false
            }
        }
    }
    resolve {
        repository {
            repoKey = 'gradle'
            username = "${artifactory_user}"
            password = "${artifactory_password}"
            maven = true

        }
    }
}

如果我在本地上传 jar,我的存储库配置确实有效,例如这就是我下载 build-info-extractor-gradle jar 的方式。但是,所有依赖项都失败了,如您所见:

    $ gradlew tasks

    FAILURE: Build failed with an exception.

    * What went wrong:
    Could not resolve all dependencies for configuration 'classpath'.
    > Could not find commons-io:commons-io:2.0.1.
      Required by:
          unspecified:unspecified:unspecified > org.jfrog.buildinfo:build-info-extractor-gradle:2.1.x-SNAPSHOT
    > Could not find org.apache.ivy:ivy:2.2.0.
      Required by:
          unspecified:unspecified:unspecified > org.jfrog.buildinfo:build-info-extractor-
...
    * Try:
    Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

    BUILD FAILED

关于我的 gradle 配置或我的工件 repo 配置有什么问题的任何想法?为什么它不能解决来自远程存储库的外部依赖关系?我应该只添加 mavenCentral 吗?


更新

我将 mavenCentral() 添加到存储库中,只是为了看看会发生什么并得到:

$ gradlew tasks
Download http://repo1.maven.org/maven2/commons-io/commons-io/2.0.1/commons-io-2.0.1.pom
Download http://repo1.maven.org/maven2/org/apache/commons/commons-parent/15/commons-parent-15.pom
Download http://repo1.maven.org/maven2/org/apache/ivy/ivy/2.2.0/ivy-2.2.0.pom
Download http://repo1.maven.org/maven2/commons-logging/commons-logging/1.1.1/commons-logging-1.1.1.pom
Download http://repo1.maven.org/maven2/org/apache/commons/commons-parent/5/commons-parent-5.pom
Download http://repo1.maven.org/maven2/javax/annotation/jsr250-api/1.0/jsr250-api-1.0.pom

FAILURE: Build failed with an exception.

* What went wrong:
Could not resolve all dependencies for configuration 'classpath'.
> Could not find org.jfrog.buildinfo:build-info-extractor:2.1.x-SNAPSHOT.
  Required by:
      unspecified:unspecified:unspecified > org.jfrog.buildinfo:build-info-extractor-gradle:2.1.x-SNAPSHOT

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

BUILD FAILED

更新 #2

重新开始。删除了 mavenCentral() 和本地上传的 jar 和 pom,然后使用 --info 和 --refresh-dependencies 运行:

$ gradlew --refresh-dependencies -i tasks
Starting Build
Settings evaluated using empty settings script.
Projects loaded. Root project using build file 'D:\repos\some_build\build.gradle'.
Included projects: [root project 'some_build']
Evaluating root project 'some_build' using build file 'D:\repos\some_build\build.gradle'.
Compiling build file 'D:\repos\some_build\build.gradle' using BuildScriptClasspathScriptTransformer.
Resource missing. [HTTP GET: http://artifactory.build.somewhere.com:8081/artifactory/gradle/org/jfrog/buildinfo/build-info-extractor-gradle/2.1.0/build-info-extractor-gradle-2.1.0.pom]
Resource missing. [HTTP HEAD: http://artifactory.build.somewhere.com:8081/artifactory/gradle/org/jfrog/buildinfo/build-info-extractor-gradle/2.1.0/build-info-extractor-gradle-2.1.0.jar]

FAILURE: Build failed with an exception.

所以,很明显,我的虚拟“gradle”存储库没有找到工件。如何判断它是否正在搜索远程“gradle-plugins”存储库?

【问题讨论】:

    标签: gradle artifactory gradlew


    【解决方案1】:

    哇!原来有两个非常重要的配置选项,disable远程仓库解析,这是默认选中的(我不记得勾选/取消勾选这些?)。

    无论如何,这就是我所做的,为了最终让gradle-artifactory plugin 工作,通过我的虚拟回购解决:

    • 禁用全局离线模式
      1. 转至:Admin -> Configuration -> General
      2. 确保取消选择全局离线模式。您将在General Settings 中看到此选项
      3. 保存
    • 为您的虚拟存储库启用远程工件解析
      1. 转到: Admin -> Configuration -> Repositories -> {Edit the virtual repo} -> Advanced Settings
      2. 确保虚拟存储库已选择Artifactory Requests Can Retrieve Remote Artifacts
      3. 保存
    • gradle-plugins 远程仓库添加到您的虚拟仓库
      1. 在远程存储库中选择New
      2. 为您的远程仓库命名,例如jfrog-gradle-plugins
      3. URL 设置为http://repo.jfrog.org/artifactory/gradle-plugins
      4. 保存
      5. 使用Edit 选项将jfrog-gradle-plugins 远程存储库添加到您的虚拟存储库的Selected Repositories
      6. 保存

    将以下内容添加到build.gradle

    buildscript {
        repositories {
            maven {
                url "${repositoryUrl}/libs-release"
            }
        }
        dependencies {
            classpath( group: 'org.jfrog.buildinfo',
                       name: 'build-info-extractor-gradle',
                       version: '2.2.2')
        }
    }
    

    添加关注gradle.properties:

    repositoryUrl = http://my.artifactory.server:8081/artifactory
    repositoryUser = me
    repositoryPassword = thisIsAPasswordStoredInMyUserDirectory
    

    希望能帮助任何在开始集成 ArtifactoryGradle 时遇到困难的人。

    在 Artifactory 中调试工件分辨率的有用提示

    使用trace REST API 选项。例如:

    http://repo.jfrog.org/artifactory/gradle-plugins/org/jfrog/buildinfo/build-info-extractor-gradle/2.2.2/build-info-extractor-gradle-2.2.2?trace

    【讨论】:

    • 请注意,与我的原始帖子相比,我现在使用的设置非常不同。确实是我自己的配置问题,在 Artifactory 中阻碍了我。
    【解决方案2】:

    看起来文档具有误导性 :( 对此感到抱歉。我现在添加一个澄清说明。

    您正在查看的页面是一个全新(不同且更好)artifactory-publish 插件的文档,但在代码中您使用的是经典的 artifactory 插件(这也很好)。

    请查看this page 获取artifactory 插件的文档。

    附:非常欢迎您试用 artifactory-publish 插件,它很棒。

    【讨论】:

    • 对不起,我认为“人工”错误是生成构建脚本时的复制和粘贴错误。我确实注意到有一个更新版本的插件(或者可能是一个完全不同的插件?),我打算使用“artifactory-publish”。感谢您澄清这一点并在文档中注明。
    • 关于虚拟gradle repo - 只需在设置中添加gradle-plugins即可。
    • 关于生成的脚本与artifactory - jfrog.com/jira/browse/RTFACT-5800
    猜你喜欢
    • 2015-08-08
    • 1970-01-01
    • 1970-01-01
    • 2015-02-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多