如何使用 Gradle 1.12 版发布(部署)本地(.war .jar)文件到 Artifactory?

Posted

技术标签:

【中文标题】如何使用 Gradle 1.12 版发布(部署)本地(.war .jar)文件到 Artifactory?【英文标题】:How to Publish (deploy) local (.war .jar) files to Artifactory using Gradle version 1.12? 【发布时间】:2015-02-11 14:02:48 【问题描述】:

如何使用 Gradle 1.12 版将本地 (.war .jar) 文件发布(部署)到 Artifactory?

亲爱的

我很难做到这一点,因为我无法更改旧版本的 Gradle,因为规范,如果有人可以帮助我处理此代码,我将不胜感激。

到目前为止我做了什么:

   buildscript 
        repositories 
            maven  url 'http://jcenter.bintray.com' 
        
        dependencies 
            classpath(group: 'org.jfrog.buildinfo', name: 'build-info-extractor-gradle', version: '3.0.1')
        
    
    apply plugin: com.jfrog.artifactory-upload'
    artifactory 
        contextUrl = 'http://my.domain.com/artifactory/'  
        resolve 
            repository 
                repoKey = 'remote-deploy'
                maven = true
            
        
    

NOTE: I don't know how to set my the local files to be uploaded but I read that I can use something like this "$rootDir\build\lib\buildProject.war"
With the suggestions I made this changes in my code:

应用插件:'com.jfrog.artifactory-upload' 应用插件:'maven-publish' 应用插件:'maven' 应用插件:'分发'

buildscript 
    repositories 
        maven  url 'http://jcenter.bintray.com' 
    
    dependencies 
        classpath(group: 'org.jfrog.buildinfo', name: 'build-info-extractor-gradle', version: '2.2.5')
    
    configurations 
        published
    


artifactoryPublish.skip = true
task sourceJar(type: Jar)
    from file("build/libs/"+project.archivesBaseName2+".jar")
    classifier = 'sources'

artifacts
    archives sourceJar
    published sourceJar

artifactory 
    contextUrl = 'http://www site com/artifactory/'
    publish 
        contextUrl = 'http://www site com/artifactory/'   //The base Artifactory URL for the publisher
        //A closure defining publishing information
        repository 
            repoKey = 'jarDeploy'
            username = 'user'
            password = 'pass'
        
        defaults
        //This closure defines defaults for all 'artifactoryPublish' tasks of all projects the plugin is applied to

            properties
                //Optional closure to attach properties to artifacts based on a list of artifact patterns per project publication
                mavenJava 'org.jfrog:*:*:*@*', key1: 'val1'

                publicationName 'group:module:version:classifier@type', key1:'value1', key2:'value2'
            
            publishBuildInfo = true   //Publish build-info to Artifactory (true by default)
            publishArtifacts = true   //Publish artifacts to Artifactory (true by default)
            publishPom = true   //Publish generated POM files to Artifactory (true by default).
            publishIvy = false   //Publish generated Ivy descriptor files to Artifactory (true by default).
        
    
    resolve
        contextUrl = 'http://www site com/artifactory/'   //The base Artifactory URL for the resolver
        repository
            repoKey = 'jarDeploy'  //The Artifactory (preferably virtual) repository key to resolve from
            username = 'user'       //Optional resolver user name (leave out to use anonymous resolution)
            password = 'pass'   //The resolver password
            maven = true                //Resolve Maven-style artifacts and descriptors (true by default)
        
    

现在我在 Arctifactory 上看到 Build 出版物,但没有文件可供下载

[buildinfo] Properties file path was not found! (Relevant only for builds running on a CI Server)
Creating properties on demand (a.k.a. dynamic properties) has been deprecated and is scheduled to be removed
 in Gradle 2.0. Please read http://gradle.org/docs/current/dsl/org.gradle.api.plugins.ExtraPropertiesExtensi
on.html for information on the replacement for dynamic properties.
Deprecated dynamic property: "publishPom" on "task ':api:artifactoryPublish'", value: "true".
Deprecated dynamic property: "publishIvy" on "task ':api:artifactoryPublish'", value: "false".
Deprecated dynamic property "publishPom" created in multiple locations.
Deprecated dynamic property "publishIvy" created in multiple locations.
:webapp:artifactoryPublish                
Deploying build info to: http://www site com/artifactory/api/build
Build successfully deployed. Browse it in Artifactory under http://tc-scm.bitnamiapp.com/artifactory/webapp/
builds/leadgnome-services/1423748387989/2015-02-12T09:39:45.642-0400/

BUILD SUCCESSFUL

【问题讨论】:

我按照你的 git 示例更新了代码,现在我可以看到 Build in Artifactory 但里面没有文件。这是 gradle artifactorybuild 的结果 【参考方案1】:

Artifactory 插件上传由另一个插件准备的文件集。考虑到您的 Gradle 版本,这可能是 maven 插件。

maven 插件创建并填充一个包含它构建的文件的configuration(通常称为archives)。这个配置需要在artifactory闭包中指定。

你可以看到here的例子数量。

附:该插件的 3.0.1 版本可能无法与此类旧 Gradle 一起使用。兼容性矩阵请查看the docs。

【讨论】:

非常感谢您,但我还没有运气,我按照您的指示尝试使用 github 中的示例,但我仍然无法在 Artifactory 中上传任何文件。该插件似乎适用于 3.0.1 和 2.2.5 版本,但我不能发布任何我不确定的东西。 您是否在闭包中添加了configuration?如果是这样,请使用相关代码更新问题。 [code]buildscript repositories maven url 'jcenter.bintray.com' 依赖项 classpath 'com.github.dcendents:android-maven-plugin:1.0' classpath(group: 'org. jfrog.buildinfo',名称:'build-info-extractor-gradle',版本:'2.2.5') artifacts homeDir = file('c:/file.war') 归档 homeDir [/code] 请更新问题。注释不是粘贴代码块的地方。 谢谢你,但现在我看不到任何上传到 Artifactory Build 的文件,只是如上图所示的出版物

以上是关于如何使用 Gradle 1.12 版发布(部署)本地(.war .jar)文件到 Artifactory?的主要内容,如果未能解决你的问题,请参考以下文章

Gradle 1.12用户指南翻译——第四十七章. Build Init 插件

使用 gradle 运行并行测试任务

Spring新版本抛弃JVM,可独立部署,网友:要自立门户???

比拼Mesos/Marathon?基于Docker 1.12 Swarm集群管理深度实践

Gradle Spring Intellij Idea下热部署实现“敏捷”开发 | TW洞见

1.12 处理异常