How do you set the maven artifact ID of a gradle project?

From 36.2.3. Identity values in the generated POM

publishing {
    publications {
        maven(MavenPublication) {
            groupId 'org.gradle.sample'
            artifactId 'project1-sample'
            version '1.1'

            from components.java
        }
    }
}

The artifact ID defaults to the project name configured in settings.gradle, which in turn defaults to the project directory's name.

You'll need the appropriate plugin.

plugins {
    id 'maven-publish'
}

Related to the root settings.gradle file, you can change the name of the root project with:

rootProject.name = 'myproject'

But if you want to change the name of a sub-project (for example, the default "app" sub-project of an AndroidStudio project), you can do something like this, still in the root settings.gradle file:

rootProject.children.each {
    it.name = ('app' == it.name ? 'MyAppName' : it.name)
}

This is the correct answer for the maven-publish plugin. This is intended as the successor for the older maven plugin.

If, as I am, you are stuck with the older plugin, the correct answer to "How do I set the maven artifact id for a gradle project" is:

uploadArchives {
    repositories {
        mavenDeployer {
            pom.artifactId = 'project-sample'
        }
    }
}

If you have a multi-module project, and you want the artifacts' names to differ from the Directory (which is set in the settings.gradle), then I think a better approach is to have a jar block for each sub-project, and there you can write the baseName, which will be the artifact-id. Then, rather than re-writing the publishing/publications block for each sub-project, you write it only once in the main build.gradle this way:

for each sub-project build.gradle:

jar {
    baseName = 'new-artifact-name-A'  //A beacause you also have B, C modules... 
}

in the main build.gradle:

publishing {
    publications {
        mavenJava(MavenPublication) {
           artifactId jar.baseName
           from components.java
        }
    }
}

For building android and publishing to artifactory using jenkins, I configured the settings below in the app modules's build.gradle for configuring group id, artifact id, and version.

apply plugin: 'com.android.application'

android {
    compileSdkVersion 21
    buildToolsVersion "21.1.2"

    group "com.company.division.productgroup" //add group id
    version "8.8.8" //add version

    defaultConfig {

        minSdkVersion 9
        targetSdkVersion 21
        versionCode 32
        versionName "$version"
        archivesBaseName = "android-appname" //add artifact id

    }