Ada*_*ins 7 android artifactory gradle maven
我有Android Studio项目,可以在发布版本和调试版本中构建AAR或APK.我想将这些发布到我的Artifactory服务器上的不同存储库中.该JFrog例子似乎并没有涵盖这种情况.
这是否意味着仅仅构建版本或仅构建调试版本,并根据构建类型选择上载内容和位置,这被认为是最佳实践?
我配置了我的android库build.gradle文件,编译的aar文件可以上传到不同的repos,具体取决于构建类型.
例如,您希望将调试artifats发布到'libs-debug-local'存储库,并将工件发布到'libs-release-local'存储库.
//First you should configure all artifacts you want to publish
publishing {
publications {
//Iterate all build types to make specific
//artifact for every build type
android.buildTypes.all { variant ->
//it will create different
//publications ('debugAar' and 'releaseAar')
"${variant.name}Aar"(MavenPublication) {
def manifestParser = new com.android.builder.core.DefaultManifestParser()
//Set values from Android manifest file
groupId manifestParser.getPackage(android.sourceSets.main.manifest.srcFile)
version = manifestParser.getVersionName(android.sourceSets.main.manifest.srcFile)
artifactId project.getName()
// Tell maven to prepare the generated "*.aar" file for publishing
artifact("$buildDir/outputs/aar/${project.getName()}-${variant.name}.aar")
}
}
}
}
//After configuring publications you should
//create tasks to set correct repo key
android.buildTypes.all { variant ->
//same publication name as we created above
def publicationName = "${variant.name}Aar"
//new task name
def taskName = "${variant.name}Publication"
//in execution time setting publications and repo key, dependent on build type
tasks."$taskName" << {
artifactoryPublish {
doFirst {
publications(publicationName)
clientConfig.publisher.repoKey = "libs-${variant.name}-local"
}
}
}
//make tasks assembleDebug and assembleRelease dependent on our new tasks
//it helps to set corrent values for every task
tasks."assemble${variant.name.capitalize()}".dependsOn(tasks."$taskName")
}
//Inside artifactory block just set url and credential, without setting repo key and publications
artifactory {
contextUrl = 'http://artifactory.cooperok.com:8081/artifactory'
publish {
repository {
username = "username"
password = "password"
}
defaults {
publishArtifacts = true
// Properties to be attached to the published artifacts.
properties = ['qa.level': 'basic', 'dev.team': 'core']
}
}
}
Run Code Online (Sandbox Code Playgroud)
就这样.现在如果你运行命令
Win:gradlew assembleRelease artifactoryPublish Mac:./ gradlew assembleRelease artifactoryPublish
aar文件将上传到'libs-release-local'存储库.
如果你跑了
Win:gradlew assembleDebug artifactoryPublish Mac:./ gradlew assembleDebug artifactoryPublish
它将被上传到'libs-debug-local'存储库
此配置的一个缺点是您应始终使用assembleDebug/Release任务运行artifactoryPublish任务
| 归档时间: |
|
| 查看次数: |
6880 次 |
| 最近记录: |