将 gradle 与本地工件存储库一起使用

Using gradle with a local artifactory repository

我是 gradle 和 artifactory 的新手。

我想要完成的是拥有单独的项目,每个项目创建一个 jar 文件,该文件将被同一应用程序中的其他项目使用。

例如,我有一个实用程序项目,等等...,实用程序 类。然后我有一个服务项目,没错,服务。这些服务使用实用程序来完成它们的一些工作。

我花了几个小时,终于使用此脚本将实用程序项目提交到我的人工制品存储库:

buildscript {
    repositories {
        mavenLocal()
        ivy {
            url 'http://picard:8080/artifactory/plugins-release'
        }
        jcenter()
    }
    dependencies {
        classpath "org.jfrog.buildinfo:build-info-extractor-gradle:3.1.1"
    }
}

apply plugin: 'java'
apply plugin: "com.jfrog.artifactory"

archivesBaseName = 'heavyweight-software-util'

repositories {
    mavenCentral()
    ivy {
        url 'http://picard:8080/artifactory/plugins-release'
    }
}

dependencies {
    testCompile("junit:junit:4.11")
}

task wrapper(type: Wrapper) {
    gradleVersion = '1.8'
}

artifactory {
    contextUrl = "http://picard:8080/artifactory"   //The base Artifactory URL if not overridden by the publisher/resolver

    publish {
        repository {
            repoKey = 'libs-release-local'
            username = 'xxxx'
            password = "xxxx"
            maven = false
            ivy {
                ivyLayout = '[organization]/[module]/[revision]/[type]s/ivy-[revision].xml'
                artifactLayout = '[organization]/[module]/[revision]/[type]s/[module](-[classifier])-[revision].[ext]'
                mavenCompatible = false
            }
        }
    }

    resolve {
        repository {
            repoKey = 'libs-release'
            username = 'xxxx'
            password = "xxxx"
            maven = false
            ivy {
                ivyLayout = '[organization]/[module]/[revision]/[type]s/ivy-[revision].xml'
                artifactLayout = '[organization]/[module]/[revision]/[type]s/[module](-[classifier])-[revision].[ext]'
                mavenCompatible = false
            }
        }
    }
}

当我 运行 时,我得到以下信息:

C:\Users\thom\git\utility\Utility>gradle artifactoryPublish
[buildinfo] Not using buildInfo properties file for this build.
:artifactoryPublish
Deploying build descriptor to: http://picard:8080/artifactory/api/build
Build successfully deployed. Browse it in Artifactory under http://picard:8080/a
rtifactory/webapp/builds/Utility/1436807848026/2015-07-13T13:17:27.704-0400/

BUILD SUCCESSFUL

Total time: 6.874 secs

万岁!或者,我是这么想的。

因为这一切结束后,我想,"Now how do I get this file out." 我查看了上面的链接,它们就在那里,但我看不出这是一个 jar 文件。我尝试在我的树浏览器中查看 libs-release-local,但它显示 0 个工件。

这是我在构建信息 JSON 下找到的内容:

{
  "version" : "1.0.1",
  "name" : "Utility",
  "number" : "1436807848026",
  "type" : "GRADLE",
  "buildAgent" : {
    "name" : "Gradle",
    "version" : "2.4"
  },
  "agent" : {
    "name" : "Gradle",
    "version" : "2.4"
  },
  "started" : "2015-07-13T13:17:27.704-0400",
  "durationMillis" : 474,
  "principal" : "thom",
  "artifactoryPrincipal" : "admin",
  "licenseControl" : {
    "runChecks" : false,
    "includePublishedArtifacts" : false,
    "autoDiscover" : false,
    "licenseViolationsRecipientsList" : "",
    "scopesList" : ""
  },
  "buildRetention" : {
    "count" : -1,
    "deleteBuildArtifacts" : true,
    "buildNumbersNotToBeDiscarded" : [ ]
  },
  "governance" : {
    "blackDuckProperties" : {
      "runChecks" : false,
      "includePublishedArtifacts" : false,
      "autoCreateMissingComponentRequests" : false,
      "autoDiscardStaleComponentRequests" : false
    }
  }
}

我用谷歌搜索和研究但似乎无法弄清楚如何使用我提交到我的存储库的 jar 文件。

好的,阅读后:https://docs.gradle.org/current/userguide/publishing_ivy.html and https://docs.gradle.org/current/userguide/artifact_management.html and finally, http://forums.jfrog.org/405-HTTP-method-PUT-not-supported-td5786632.html我已经拼凑出了我的问题的答案。我附上了正确执行上传的构建脚本...

buildscript {
    repositories {
        mavenLocal()
        jcenter()
    }
    dependencies {
        classpath "org.jfrog.buildinfo:build-info-extractor-gradle:3.1.1"
    }
}

apply plugin: 'java'
apply plugin: 'ivy-publish'

archivesBaseName = 'heavyweight-software-util'

repositories {
    mavenCentral()
    ivy {
        url 'http://picard:8080/artifactory/plugins-release'
    }
}

dependencies {
    compile group: 'org.slf4j', name: 'slf4j-api', version: '1.7.+'
    compile group: 'ch.qos.logback', name: 'logback-classic', version: '1.+'
    testCompile("junit:junit:4.11")
}

publishing {
    publications {
        ivy(IvyPublication) {
            organisation 'com.heavyweightsoftware'
            module 'heavyweight-util'
            revision '1.0'

            from components.java
        }
    }

    repositories {
        ivy {
            url 'http://picard:8080/artifactory/libs-release-local'
            credentials {
                username "xxxxx"
                password "xxxxx"
            } 
        }
    }
}

task wrapper(type: Wrapper) {
    gradleVersion = '1.8'
}

既然我知道发布工作正常,我应该可以毫无问题地使用存储库。