云客户?
免费开始>
在MyJFrog中升级>
云的新功能>





概述

Gradle Artifactory Plugin允许您将构建工件和构建信息部署到Artifactory,还可以从Artifactory解析构建依赖项。支持的Gradle最低版本是4.10。

下载及安装

构建脚本片段,用于所有Gradle版本
buildscript {repositories {mavenCentral()} dependencies {classpath "org.jfrog.buildinfo:build-info-extractor-gradle:最新的。发布"}}应用插件:"com.jfrog.artifactory"
构建用于Gradle 2.1及以上版本的脚本片段
//将替换为Gradle Artifactory plugin的版本。插件{id "com.jfrog。artifactory" version "" }

目前,“plugins”符号不能用于在子项目中应用插件,当从根构建脚本中使用时

页面内容



配置

使用Artifactory插件DSL

Gradle Artifactory插件使用它自己的约定DSL来配置build.gradle根项目的脚本。

约定DSL的语法描述如下:

我们强烈建议也使用我们的例子作为在构建脚本中配置DSL时的参考。

相关上下文中的强制性条目以“+”为前缀。所有其他项目都是可选的。

依赖项决议
repositories {mavenCentral() maven {+url "http://repo.myorg.com/artifactory/libs-releases" //从凭证中解析的Artifactory(最好是虚拟的)存储库{//可选解析器凭证(省略使用匿名解析)username = "resolver" // Artifactory用户名密码= "resolverPaS*" //密码或API Key}} ivy {+url "http://localhost:8081/artifactory/ivy-releases" layout "pattern",{//可选配置ivy风格解析的部分。Ivy "[organization]/[module]/[revision]/ Ivy .xml" artifact "[organization]/[module]/[revision]/[module]-[revision](-[classifier])。[ext]" m2compatible = true //将[organization]布局值中的任何点转换为路径分隔符,类似于Maven的groupid到path转换。如果未指定,则为False。}}

遵循这个文档以获取配置存储库的不同方法。

工件和建筑出版物
artifactory {+contextUrl = 'http://repo.myorg.com/artifactory' //基本artifactory URL如果没有被发布者/解析器覆盖publish {contextUrl = 'http://repo.myorg.com/artifactory' //发布者的基本artifactory URL //定义发布信息存储库的闭包{+repoKey = 'integration-libs' //发布到的artifactory存储库密钥+username = 'deployer' //发布者用户名password = 'deployerPaS*' //发布者密码或API密钥ivy{//可选section for configuring Ivy publication. Assumes Maven repo layout if not specified ivyLayout = '[organization]/[module]/[revision]/[type]s/ivy-[revision].xml' artifactLayout = '[organization]/[module]/[revision]/[module]-[revision](-[classifier]).[ext]' mavenCompatible = true //Convert any dots in an [organization] layout value to path separators, similar to Maven's groupId-to-path conversion. True if not specified } } defaults { //List of Gradle Publications (names or objects) from which to collect the list of artifacts to be deployed to Artifactory. //If you'd like to deploy the artifacts from all the publications defined in the Gradle script, you can set the 'ALL_PUBLICATIONS' string, instead of the publication names. publications ('ivyJava','mavenJava','foo') //List of Gradle Configurations (names or objects) from which to collect the list of artifacts to be deployed to Artifactory. publishConfigs('archives', 'published') properties = ['qa.level': 'basic', 'q.os': 'win32, deb, osx'] //Optional map of properties to attach to all published artifacts /* The properties closure in the "defaults" task uses the following syntax: properties { publicationName 'group:module:version:classifier@type', key1:'value1', key2:'value2', ... } publicationName: A valid name for a publication of the project. You can use all to apply the properties to all publications. group:module:version:classifier@type: A filter that specifies the artifacts to which properties should be attached. The filter may contain wildcards: * for all characters or ? for a single character. key:'value': A list of key/value properties that will be attached to to the published artifacts matching the filter. */ properties { //Optional closure to attach properties to artifacts based on a list of artifact patterns per project publication foo '*:*:*:*@*', platform: 'linux', 'win64' //The property platform=linux,win64 will be set on all artifacts in foo publication mavenJava 'org.jfrog:*:*:*@*', key1: 'val1' //The property key1=val1 will be set on all artifacts part of the mavenJava publication and with group org.jfrog all 'org.jfrog:shared:1.?:*@*', key2: 'val2', key3: 'val3' //The properties key2 and key3 will be set on all published artifacts (all publications) with group:artifact:version //equal to org.jfrog:shared:1.? } 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 = true //Publish generated Ivy descriptor files to Artifactory (true by default). } } // Redefine basic properties of the build info object clientConfig.setIncludeEnvVars(true) clientConfig.setEnvVarsExcludePatterns('*password*,*secret*') clientConfig.setEnvVarsIncludePatterns('*not-secret*') clientConfig.info.addEnvironmentProperty('test.adding.dynVar',new java.util.Date().toString()) clientConfig.info.setBuildName('new-strange-name') clientConfig.info.setBuildNumber('' + new java.util.Random(System.currentTimeMillis()).nextInt(20000)) clientConfig.info.setProject('project-key') clientConfig.timeout = 600 // Artifactory connection timeout (in seconds). The default timeout is 300 seconds. clientConfig.setInsecureTls(false) // Set to true to skip TLS certificates verification (false by default). }

控制环境变量的公开方式

如上面的示例所示,您可以控制在其中公开哪些环境变量clientConfig.setIncludeEnvVars使用clientConfig.setEnvVarsExcludePatternsclientConfig.setEnvVarsIncludePatterns。这些调用使用参数指定应该分别排除或包含哪些环境变量,参数是要排除或包含的逗号分隔的表达式列表。这些表达式可以使用一个星号('*')通配符,用于指定多个环境变量。

使用旧的Gradle发布机制?
如果你正在使用旧的Gradle发布机制,你需要用下面的闭包替换上面的默认闭包:defaults{//这个闭包定义了所有项目的'artifactoryPublish'任务的默认值,该插件应用于publishConfigs ('a','b','foo') //可选的要发布的配置(名称或对象)列表。//如果'archives'配置存在并且没有指定配置,则使用'archives'配置。mavenDescriptor = '/home/frog /projects/ project -a/fly-1.0。//要发布的pom的可选替代路径(可以相对于项目baseDir) ivyDescriptor = 'fly-1.0-ivy.xml' //要发布的ivy文件的可选替代路径(可以相对于项目baseDir) properties = ['qa。level': 'basic', 'q.os': 'win32, deb, osx'] //附加到所有已发布工件的属性的可选映射/* "defaults"任务中的属性闭包使用以下语法:properties {configuration 'group:module:version:classifier@type', key1:'value1', key2:'value2',…} configuration:项目配置的有效名称的配置。可以使用all将属性应用于所有配置。group:module:version:classifier@type:一个工件规范过滤器,用于匹配应该附加属性的工件。过滤器可能包含通配符:*用于所有字符或?对于单个字符。key:'value':键/值属性的列表,这些属性附加到与过滤器匹配的已发布工件上。 */ properties { //Optional closure to attach properties to artifacts based on a list of artifact patterns per project configuration foo '*:*:*:*@*', platform: 'linux', 'win64' //The property platform=linux,win64 will be set on all artifacts in foo configuration archives 'org.jfrog:*:*:*@*', key1: 'val1' //The property key1=val1 will be set on all artifacts part of the archives configuration and with group org.jfrog all 'org.jfrog:shared:1.?:*@*', key2: 'val2', key3: 'val3' //The properties key2 and key3 will be set on all published artifacts (all configurations) with group:artifact:version //equal to org.jfrog:shared:1.? } 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 (false by default) }

工件项目发布任务

Artifactory发布插件创建一个artifactoryPublish每个项目的Gradle任务。任务由发布关闭插件。

可以直接使用任务的属性配置项目级任务artifactoryPublish闭包,它使用与插件相同的语法publish.defaults关闭。

artifactoryPublish {skip = false //跳过构建信息分析和发布(默认为false) contextUrl = 'http://repo.myorg.com/artifactory' publications ('a','b','c') properties = ['qa. properties]level': 'basic', 'q.os': 'win32, deb, osx'] properties {c' **:**:*@*', cProperty: 'only in c'} clientConfig.publisher.repoKey = 'integration-libs' clientConfig.publisher.username = 'deployer' clientConfig.publisher.password = 'deployerPaS' clientConfig.publisher.setExcludePatterns("*artifacts-to-exclude-1*,*artifacts-to-exclude-2*") //以逗号分隔的排除模式列表。与其中一个模式匹配的工件将不会被部署。clientConfig.publisher.setFilterExcludedArtifactsFromBuild(true) //设置为true以避免将过滤的工件添加到构建信息中。//插件执行校验和部署优化的最小文件大小(KB)。默认值:10。设置为0将禁止上传已存在于Artifactory中的校验和文件。clientConfig.publisher.minChecksumDeploySizeKb = 10}

控制子项目中的发布

Gradle Artifactory Plugin允许你为子项目定义不同的发布配置。也可以为整个项目定义一次配置,方法是定义artifactory只在根项目中关闭。该插件还允许您禁用子模块的发布。

  • 当在层次结构中的任何位置定义配置时,它下面的所有子项目都继承该配置,并且可以覆盖它,无论它是在根目录中还是在子项目中定义的。
  • 每个子项目都可以覆盖发布闭包或存储库闭包,或者两者都有。

    仅覆盖发布的示例
    artifactory {publish {contextUrl = 'http://localhost:8081/artifactory' repository {repoKey = "lib -snapshot-local"用户名= "user"密码= "pass"}}

  • 要发布buildInfo,必须在根项目中定义发布闭包。

  • 使用artifactoryPublish.skip禁用分析和发布的标志。
  • 激活相应的artifactoryPublishGradle任务手动为每个项目,你希望应用插件。例如在我们的Gradle项目示例你可以运行:

    手动激活插件
    ./gradlew clean api:artifactoryPublish共享:artifactoryPublish

控制生成名称和编号

默认情况下,发布BuildInfo时使用由根项目的名称构造的构建名和作为构建开始日期的构建号。

您可以通过分别指定以下属性来控制生成名称和编号值:

指定生成名称和编号
buildInfo.build.name = my-super-cool-build buildInfo.build.number = r9001

上述属性应该添加到项目的gradle中。属性文件。

使用HTTP代理

对于部署,将以下字段添加到Artifactory关闭build.gradle

人工{…clientConfig.proxy.host = 'www.somehost.org' clientConfig.proxy.port = '8080' clientConfig.proxy.username = 'userid' clientConfig.proxy.password = 'password'}

Artifactory Gradle插件不会介入Gradle的依赖解析过程。因此,要解析Gradle依赖项,请使用regularGradle代理配置gradle.properties文件。

systemProp.http systemProp.http.proxyHost = www.somehost.org。proxyPort = 8080 systemProp.http。proxyUser = userid systemProp.http.proxyPassword =密码



例子

使用Gradle Artifactory Plugin的项目示例是可用的在这里

  • 没有标签
版权所有©2022 JFrog Ltd.