我正在对android库进行版本控制。以下是定义的构建类型:
buildTypes {
debug{
versionNameSuffix "-DEBUG"
}
dev{
versionNameSuffix "-RC"
}
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
//define code for appending the versionname suffix for the plugin
}
// need the versionNameSuffix from the runtime buildvariant selected
version "1.1.0-${versionNameSuffix}"
group 'com.mylib.android-libs'
根据运行时选择的构建变体,maven存储库文件夹和文件中 Artifact 的名称需要附加上面定义的相应的versionNameSuffix,从而在发布时在存储库中具有以下结构。
mylibrary
|_ 1.1.0
|__mylibrary-1.1.0-sources.jar
|__mylibrary-1.1.0.aar
|__mylibrary-1.1.0.pom
|_ 1.1.0-DEBUG
|__mylibrary-1.1.0-DEBUG-sources.jar
|__mylibrary-1.1.0-DEBUG.aar
|__mylibrary-1.1.0-DEBUG.pom
|_ 1.1.0-RC
|__mylibrary-1.1.0-RC-sources.jar
|__mylibrary-1.1.0-RC.aar
|__mylibrary-1.1.0-RC.pom
这是构件块:
artifactory {
contextUrl = "${artifactoryUrl}"
publish {
repository {
repoKey = 'maven-local'
username = "${user}"
password = "${password}"
maven = true
}
defaults {
publishConfigs('archives', 'published')
properties = ['build.status': "$it.project.status".toString()]
publishPom = true //Publish generated POM files to Artifactory (true by default)
publishIvy = false //Publish generated Ivy descriptor files to Artifactory (true by default)
}
}
resolve {
repository {
repoKey = 'repo'
username = "${user}"
password = "${password}"
maven = true
}
}
}
最佳答案
您的编辑完全改变了您的问题!这是我的新答案:
首先,您需要将publishNonDefault true
添加到android
部分:
android {
...
publishNonDefault true
...
}
然后修改您的uploadArchives部分,以使用addFilter从项目中上传多个文件。 See section 31.6.4.1 here。
uploadArchives {
repositories {
mavenDeployer {
repository(url: "file://${System.properties['user.home']}/.m2/repository")
// addfilter for multiple pom upload
addFilter('debug') { artifact, file ->
artifact.attributes.classifier.equals("debug")
}
addFilter('dev') { artifact, file ->
artifact.attributes.classifier.equals("dev")
}
addFilter('release') { artifact, file ->
artifact.attributes.classifier.equals("release")
}
pom('debug').version = project.version + "-DEBUG"
pom('dev').version = project.version + "-RC"
pom('release').version = project.version
}
}
}
运行uploadArchives会导致:
├───1.1.0
│ mylibrary-1.1.0-release.aar
│ mylibrary-1.1.0-release.aar.md5
│ mylibrary-1.1.0-release.aar.sha1
│ mylibrary-1.1.0.pom
│ mylibrary-1.1.0.pom.md5
│ mylibrary-1.1.0.pom.sha1
│
├───1.1.0-DEBUG
│ mylibrary-1.1.0-DEBUG-debug.aar
│ mylibrary-1.1.0-DEBUG-debug.aar.md5
│ mylibrary-1.1.0-DEBUG-debug.aar.sha1
│ mylibrary-1.1.0-DEBUG.pom
│ mylibrary-1.1.0-DEBUG.pom.md5
│ mylibrary-1.1.0-DEBUG.pom.sha1
│
└───1.1.0-RC
mylibrary-1.1.0-RC-dev.aar
mylibrary-1.1.0-RC-dev.aar.md5
mylibrary-1.1.0-RC-dev.aar.sha1
mylibrary-1.1.0-RC.pom
mylibrary-1.1.0-RC.pom.md5
mylibrary-1.1.0-RC.pom.sha1
repository
可以是任何Maven存储库。我尚未使用Artifactory上传进行测试,但我了解 Artifact 应从Maven插件配置中获取配置。