I configured my build.gradle file for the Android library, which compiled the aar file, can be downloaded in different repositories, depending on the type of assembly.
For example, you want to publish debug artifacts to the libs-debug-local repository and release the artifacts to the libs-release-local repository.
//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'] } } }
It's all. Now if you run the command
Win: gradlew assembleRelease artifactoryPublish Mac: ./ gradlew assembleRelease artifactoryPublish
The aar file will be uploaded to the 'libs-release-local' repository.
And if you run
Win: gradlew assembleDebug artifactoryPublish Mac: ./ gradlew assembleDebug artifactoryPublish
it will be uploaded to the 'libs-debug-local' repository
One minus of this configuration is that you should always run the artifactoryPublish task with assembleDebug / Release tasks
cooperok
source share