配置
使用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。}}}
遵循这个文档获取配置存储库的不同方法。
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
.这些调用使用一个参数指定应分别排除或包括哪些环境变量,该参数是一个以逗号分隔的表达式列表。表达式可以使用一个星号('*')通配符,用于指定多个环境变量。
Artifactory项目发布任务
Artifactory发布插件创建了一个artifactoryPublish
Gradle任务为每个项目的插件应用。命令配置该任务发布
插件闭包。
您可以直接配置项目级任务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
标志,以禁用分析和发布。 激活相应的
artifactoryPublish
Gradle任务手动为每个项目,你希望应用插件。例如,在我们的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的项目示例是可用的在这里.