配置
使用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.setEnvVarsExcludePatterns
和clientConfig.setEnvVarsIncludePatterns
。这些调用使用参数指定应该分别排除或包含哪些环境变量,参数是要排除或包含的逗号分隔的表达式列表。这些表达式可以使用一个星号('*')通配符,用于指定多个环境变量。
工件项目发布任务
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
禁用分析和发布的标志。 激活相应的
artifactoryPublish
Gradle任务手动为每个项目,你希望应用插件。例如在我们的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的项目示例是可用的在这里。