将gradle与本地神器库一起使用

时间:2015-07-13 18:40:22

标签: gradle ivy 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

乌拉!或者,我想。

因为一旦这个结束了,我想,"现在我怎么把这个文件拿出来。"我看了上面的链接,他们就在那里,但我看不出这是一个jar文件。我尝试在我的树浏览器中查看libs-release-local,但它显示了0个工件。

这是我在build下的构建信息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
    }
  }
}

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

1 个答案:

答案 0 :(得分:1)

好的,看了之后:https://docs.gradle.org/current/userguide/publishing_ivy.htmlhttps://docs.gradle.org/current/userguide/artifact_management.html,最后,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'
}

现在我知道该出版物工作正常,我应该可以毫无问题地使用存储库。