225

Looking down this build.gradle file

apply plugin: 'com.android.application'

android {
    compileSdkVersion 21
    buildToolsVersion "21.1.2"

    defaultConfig {
        applicationId "package.myapp"
        minSdkVersion 19
        targetSdkVersion 21
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.nineoldandroids:library:2.4.0'
}

What if I would like to write a comment on why did I chose this library for this project,

what is the syntax for writing comments in build.gradle file?

1
  • For Kotlin scripts (.kts files), it is the same as the regular Kotlin files: // for single-line comment and /* */ for multi-line comments and /** */ for KDoc comments.
    – Mahozad
    Commented Jan 25, 2022 at 17:25

2 Answers 2

346

Easy:

// Single line comment

/*
 Multi
 line
 comment
*/
33

Use the // or /* */

For example:

        // Top-level build file where you can add configuration options common to all sub-projects/modules.

    buildscript {
        repositories {
            jcenter()
        }
        dependencies {
            classpath 'com.android.tools.build:gradle:1.2.3'

            // NOTE: Do not place your application dependencies here; they belong
            // in the individual module build.gradle files
        }
    }

/**
 * Returns the credential username used by Namirial Maven repository
 * Set this value in your ~/.gradle/gradle.properties with CREDENTIALS_USERNAME key
 * @return
 */
def getCredentialsMavenUsername() {
    return hasProperty('CREDENTIALS_USERNAME') ? CREDENTIALS_USERNAME : ""
}
1
  • Well that was quite odd, my Android Studio was not recognizing comment lines until I restarted it. Funny thing though it does not have any answers on the web.
    – Machado
    Commented Sep 14, 2015 at 16:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.