云客户?
免费开始>
在MyJFrog >中升级
云有什么新>







概述

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

下载及安装

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

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

页面内容



配置

使用Artifactory Plugin DSL

Gradle Artifactory插件是使用它自己的Convention DSL在build.gradle根项目的脚本。

约定DSL的语法描述如下:

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

相关上下文中的必填项前缀为“+”。所有其他项目都是可选的。

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

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

工件和BuildInfo发布
artifactory {+contextUrl = 'http://repo.myorg.com/artifactory' //基本artifactory URL如果没有被发布者/resolver publish覆盖{contextUrl = 'http://repo.myorg.com/artifactory' //发布者的基本artifactory URL //定义发布信息存储库的closure {+repoKey = 'integration-libs' //要发布到的artifactory存储库密钥+username = 'deployer' //发布者用户名密码= '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.setEnvVarsExcludePatterns而且clientConfig.setEnvVarsIncludePatterns.这些调用使用一个参数指定应分别排除或包括哪些环境变量,该参数是一个以逗号分隔的表达式列表。表达式可以使用一个星号('*')通配符,用于指定多个环境变量。

使用旧的Gradle发布机制?
如果你使用的是旧的Gradle发布机制,你需要用下面的闭包替换上面的默认闭包:defaults{//这个闭包为所有项目的'artifactoryPublish'任务定义了默认值,插件应用到publishConfigs ('a','b','foo') //可选的配置列表(名称或对象)来发布。mavenDescriptor = '/home/froggy/projects/ project -a/fly-1.0. '/home/froggy/projects/ project -a/fly-1.0. 'pom' //发布pom的可选备选路径(可以是相对于项目baseDir的)ivyDescriptor = 'fly-1.0-ivy.xml' //发布ivy文件的可选备选路径(可以是相对于项目baseDir的)properties = ['qa. pom'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项目发布任务

Artifactory发布插件创建了一个artifactoryPublishGradle任务为每个项目的插件应用。命令配置该任务发布插件闭包。

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

artifactoryPublish {skip = false //跳过构建信息分析和发布(默认为false) contextUrl = 'http://repo.myorg.com/artifactory' publications ('a','b','c') properties = ['qa. 'level': 'basic', 'q.os': 'win32, deb, osx']属性{c' **:**:**:*@*', cProperty: 'only in c'} clientConfig.publisher.repoKey = ' integri -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以避免将过滤后的工件添加到build-info中。//插件执行校验和部署优化的最小文件大小(单位:KB)默认值:10。设置为0将禁用上传在Artifactory中已经存在的带有校验和的文件。minchecksumdeploysizekb = 10}

控制子项目的发布

Gradle Artifactory Plugin允许你这样做为子项目定义不同的发布配置。属性,也可以为整个项目定义一次配置artifactory只在根项目中使用闭包。该插件还允许您禁用子模块的发布。

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

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

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

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

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

控制生成名称和编号

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

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

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

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

使用HTTP代理

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

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

Artifactory Gradle插件不干涉Gradle依赖项解析过程。因此,要解析Gradle依赖项,请使用常规的Gradle代理配置gradle.properties文件。

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



例子

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

  • 没有标签
版权所有©2023 JFrog Ltd。