build.gradle文件中编写注释的语法是什么?

220

查看这个build.gradle文件

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'
}

如果我想在为什么选择这个库来做这个项目上写评论,

build.gradle文件中编写评论的语法是什么?


对于Kotlin脚本(*.kts*文件),其注释方式与普通的Kotlin文件相同:使用//表示单行注释,使用/* */表示多行注释,使用/** */表示KDoc注释。 - Mahozad
2个回答

342

简单:

// Single line comment

/*
 Multi
 line
 comment
*/

32

使用 ///* */ 进行注释。

例如:

        // 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 : ""
}

嗯,这很奇怪,我的Android Studio在重启之前无法识别注释行。有趣的是,在网上找不到任何答案。 - Machado

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接