How to use artifactoryPublish to publish release and debug artifacts

Adam Lins

I have Android Studio projects that build AARs or APKs in both release and debug versions. I'd like to publish these to different to different repositories on my Artifactory server. The JFrog examples don't appear to cover this case.

Does this mean that it's considered best practice to simply build either only the release or only the debug version, and choose what and where to upload based on the type of build?

cooperok

I configured my android library build.gradle file that compiled aar file could be uploaded in different repos, dependent on build type.
For example you want to publish debug artifats to 'libs-debug-local' repository and release artifacts to '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']
        }
    }
}

That's all. Now if you run command

Win : gradlew assembleRelease artifactoryPublish Mac : ./gradlew assembleRelease artifactoryPublish

aar file will be uploaded to 'libs-release-local' repository.
And if you ran

Win : gradlew assembleDebug artifactoryPublish Mac : ./gradlew assembleDebug artifactoryPublish

it will be uploaded to 'libs-debug-local' repository

One minus of this configuration is that you should always run artifactoryPublish task with assembleDebug/Release tasks

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How to debug apk signed for release?

How to use build types (debug vs release) to set different styles and app names?

Idiomatic use of sbt to release (tested) artifacts

Gradle Artifactory Plugin - How to publish artifacts from multiple modules in a project?

How to use the Renderscript blurring effect without artifacts?

Use different assets for debug and release

Use Project Reference in Debug and Nuget in Release

Release definition to publish nuget packages for multiple artifacts

Publish debug & release to artifactory

How to use "mapping.txt" file for debug and error-exception handler for Release version in Android

How to use gomobile to release output non debug apk?

Maven: how can I deploy two artifacts with the release plugin?

How to manually publish a file to Azure Artifacts?

How to publish Travis CI artifacts to GitHub Release from several jobs

Maven release plugin - how to publish only a snapshot?

How can I publish a specific subset of artifacts in Gradle

Visual Studio publish uses debug mode instead of release

How to use specific fields for specific application builds (debug/release)?

How to publish custom artifacts to Artifactory from TeamCity?

How to use various connection strings in WPF and DataSet in Debug and Release mode?

How to debug in release mode

How can I deploy a release with multiple artifacts

Publish Artifacts for website goes to PrecompiledWeb

publish artifacts to scp repository if success

gradle artifactorypublish: jenkins pipeline does not publish properties

How to solve the release pipeline deployment issue with the artifacts?

Use DevOps Release Pipeline to Upload Artifacts to a Linux Server

How to publish and download artifacts from multiple jobs into one location on pipeline?

How to publish .NET "Release" artifact?

TOP Ranking

HotTag

Archive