이 페이지에는 주석을 추가하고 구성하는 방법에 대한 자세한 안내가 포함되어 있습니다.
프로세서를 프로젝트 종속 항목으로 사용합니다 주석 프로세서에 관해 자세히 알아보려면
자세한 내용은
종속 항목을 구성합니다.
컴파일 클래스 경로에 주석 프로세서를 추가하면 다음과 유사한 오류 메시지가 표시됩니다.
Error: Annotation processors must be explicitly declared now.
이 오류를 해결하려면 아래와 같이 annotationProcessor를 사용하여 종속 항목을 구성하고 프로젝트에 주석 프로세서를 추가하세요.
Kotlin
dependencies{// Adds libraries defining annotations to only the compile classpath.compileOnly("com.google.dagger:dagger:version-number")// Adds the annotation processor dependency to the annotation processor classpath.annotationProcessor("com.google.dagger:dagger-compiler:version-number")}
Groovy
dependencies{// Adds libraries defining annotations to only the compile classpath.compileOnly'com.google.dagger:dagger:version-number'// Adds the annotation processor dependency to the annotation processor classpath.annotationProcessor'com.google.dagger:dagger-compiler:version-number'}
참고:Gradle용 Android 플러그인 3.0.0 이상에서는 더 이상 android-apt 플러그인이 지원되지 않습니다.
주석 프로세서에 인수 전달
주석 프로세서에 인수를 전달해야 하는 경우 모듈의 빌드 구성에서 AnnotationProcessorOptions 블록을 사용하여 전달하면 됩니다. 예를 들어 프리미티브 데이터 유형을 키-값 쌍으로 전달하려면 아래와 같이 argument 속성을 사용하면 됩니다.
그러나 Android Gradle 플러그인 3.2.0 이상을 사용하는 경우 Gradle의 CommandLineArgumentProvider 인터페이스를 사용하여 파일이나 디렉터리를 나타내는 프로세서 인수를 전달해야 합니다.
CommandLineArgumentProvider를 사용하면
주석 프로세서 작성자의 정확성과 성능을
증분 빌드 속성 유형을 적용하여 증분 및 캐시된 클린 빌드
주석
사용할 수 있습니다.
예를 들어 아래의 클래스에는 CommandLineArgumentProvider를 구현하고 프로세서의 각 인수에 주석을 추가합니다.
Kotlin
classMyArgsProvider(// Annotates each directory as either an input or output for the// annotation processor.@get:InputFiles// Using this annotation helps Gradle determine which part of the file path// should be considered during up-to-date checks.@get:PathSensitive(PathSensitivity.RELATIVE)valinputDir:FileCollection,@get:OutputDirectoryvaloutputDir:File):CommandLineArgumentProvider{// Specifies each directory as a command line argument for the processor.// The Android plugin uses this method to pass the arguments to the// annotation processor.overridefunasArguments():Iterable<String>{// Use the form '-Akey[=value]' to pass your options to the Java compiler.returnlistOf("-AinputDir=${inputDir.singleFile.absolutePath}","-AoutputDir=${outputDir.absolutePath}")}}android{...}
Groovy
classMyArgsProviderimplementsCommandLineArgumentProvider{// Annotates each directory as either an input or output for the// annotation processor.@InputFiles// Using this annotation helps Gradle determine which part of the file path// should be considered during up-to-date checks.@PathSensitive(PathSensitivity.RELATIVE)FileCollectioninputDir@OutputDirectoryFileoutputDir// The class constructor sets the paths for the input and output directories.MyArgsProvider(FileCollectioninput,Fileoutput){inputDir=inputoutputDir=output}// Specifies each directory as a command line argument for the processor.// The Android plugin uses this method to pass the arguments to the// annotation processor.@OverrideIterable<String>asArguments(){// Use the form '-Akey[=value]' to pass your options to the Java compiler.["-AinputDir=${inputDir.singleFile.absolutePath}","-AoutputDir=${outputDir.absolutePath}"]}}android{...}
// This is in your module's build.gradle file.android{defaultConfig{javaCompileOptions{annotationProcessorOptions{// Creates a new MyArgsProvider object, specifies the input and// output paths for the constructor, and passes the object// to the Android plugin.compilerArgumentProvider(MyArgsProvider(files("input/path"),file("output/path")))}}}}
Groovy
// This is in your module's build.gradle file.android{defaultConfig{javaCompileOptions{annotationProcessorOptions{// Creates a new MyArgsProvider object, specifies the input and// output paths for the constructor, and passes the object// to the Android plugin.compilerArgumentProvidernewMyArgsProvider(files("input/path"),newFile("output/path"))}}}}
CommandLineArgumentProvider 구현을 통해 빌드 성능을 개선하는 방법에 관한 자세한 내용은 자바 프로젝트 캐싱을 참고하세요.
주석 프로세서 오류 검사 중지
불필요한 주석 프로세서가 포함된 종속 항목이 컴파일 클래스 경로에 있는 경우 다음을 build.gradle.kts 파일에 추가하여 오류 검사를 중지할 수 있습니다. 컴파일 클래스 경로에 주석 프로세서를 추가해도 프로세서 클래스 경로에는 추가되지 않습니다.
프로젝트의 주석 프로세서를 프로세서 클래스 경로로 이전한 후 문제가 발생하면 includeCompileClasspath를 true로 설정하여 컴파일 클래스 경로의 주석 프로세서를 허용할 수 있습니다. 그러나 이 속성을 true로 설정하는 것은 권장되지 않으며 이렇게 하는 옵션은 향후 Android 플러그인 업데이트에서 삭제될 예정입니다.
이 페이지에 나와 있는 콘텐츠와 코드 샘플에는 콘텐츠 라이선스에서 설명하는 라이선스가 적용됩니다. 자바 및 OpenJDK는 Oracle 및 Oracle 계열사의 상표 또는 등록 상표입니다.
최종 업데이트: 2025-07-27(UTC)
[[["이해하기 쉬움","easyToUnderstand","thumb-up"],["문제가 해결됨","solvedMyProblem","thumb-up"],["기타","otherUp","thumb-up"]],[["필요한 정보가 없음","missingTheInformationINeed","thumb-down"],["너무 복잡함/단계 수가 너무 많음","tooComplicatedTooManySteps","thumb-down"],["오래됨","outOfDate","thumb-down"],["번역 문제","translationIssue","thumb-down"],["샘플/코드 문제","samplesCodeIssue","thumb-down"],["기타","otherDown","thumb-down"]],["최종 업데이트: 2025-07-27(UTC)"],[],[],null,["# Add annotation processors\n\nThis page includes detailed guidance on how to add and configure annotation\nprocessors as project dependencies. To learn more about annotation processors,\nsee the entry in\n[Configure dependencies](/build/dependencies#dependency_configurations).\n\nIf you add annotation processors to your compile classpath, you'll see\nan error message similar to the following: \n\n```\nError: Annotation processors must be explicitly declared now.\n```\n\nTo resolve this error, add annotation processors to your project by configuring\nyour dependency using `annotationProcessor` as shown below: \n\n### Kotlin\n\n```kotlin\ndependencies {\n // Adds libraries defining annotations to only the compile classpath.\n compileOnly(\"com.google.dagger:dagger:\u003cvar translate=\"no\"\u003eversion-number\u003c/var\u003e\")\n // Adds the annotation processor dependency to the annotation processor classpath.\n annotationProcessor(\"com.google.dagger:dagger-compiler:\u003cvar translate=\"no\"\u003eversion-number\u003c/var\u003e\")\n}\n```\n\n### Groovy\n\n```groovy\ndependencies {\n // Adds libraries defining annotations to only the compile classpath.\n compileOnly 'com.google.dagger:dagger:\u003cvar translate=\"no\"\u003eversion-number\u003c/var\u003e'\n // Adds the annotation processor dependency to the annotation processor classpath.\n annotationProcessor 'com.google.dagger:dagger-compiler:\u003cvar translate=\"no\"\u003eversion-number\u003c/var\u003e'\n}\n```\n\n**Note:** Android plugin for Gradle 3.0.0+ no longer\nsupports [`android-apt` plugin.](https://github.com/littlerobots/android-apt)\n\nPass arguments to annotation processors\n---------------------------------------\n\nIf you need to pass arguments to an annotation processor, you can do so using\nthe [`AnnotationProcessorOptions`](/reference/tools/gradle-api/current/com/android/build/api/dsl/AnnotationProcessorOptions)\nblock in your module's build configuration. For example, if you want to pass\nprimitive data types as key-value pairs, you can use the `argument` property,\nas shown below: \n\n### Kotlin\n\n```kotlin\nandroid {\n ...\n defaultConfig {\n ...\n javaCompileOptions {\n annotationProcessorOptions {\n arguments += mapOf(\"key1\" to \"value1\",\n \"key2\" to \"value2\")\n }\n }\n }\n}\n```\n\n### Groovy\n\n```groovy\nandroid {\n ...\n defaultConfig {\n ...\n javaCompileOptions {\n annotationProcessorOptions {\n argument 'key1', 'value1'\n argument 'key2', 'value2'\n }\n }\n }\n}\n```\n\nHowever, when using Android Gradle plugin 3.2.0 and higher, you need to\npass processor arguments that represent files or directories using Gradle's\n[`CommandLineArgumentProvider`](https://docs.gradle.org/current/javadoc/org/gradle/process/CommandLineArgumentProvider.html) interface.\n\nUsing `CommandLineArgumentProvider` allows you or the\nannotation processor author to improve the correctness and performance of\nincremental and cached clean builds by applying [incremental build property type\nannotations](https://docs.gradle.org/current/userguide/more_about_tasks.html#sec:up_to_date_checks)\nto each argument.\n\nFor example, the class below implements `CommandLineArgumentProvider` and\nannotates each argument for the processor.\n**Note:** Typically, annotation processor authors provide either this class or instructions on how to write such a class. That's because each argument needs to specify the correct build property type annotation in order to work as intended. \n\n### Kotlin\n\n```kotlin\nclass MyArgsProvider(\n // Annotates each directory as either an input or output for the\n // annotation processor.\n @get:InputFiles\n // Using this annotation helps Gradle determine which part of the file path\n // should be considered during up-to-date checks.\n @get:PathSensitive(PathSensitivity.RELATIVE)\n val inputDir: FileCollection,\n\n @get:OutputDirectory\n val outputDir: File\n) : CommandLineArgumentProvider {\n // Specifies each directory as a command line argument for the processor.\n // The Android plugin uses this method to pass the arguments to the\n // annotation processor.\n\n override fun asArguments(): Iterable\u003cString\u003e {\n // Use the form '-Akey[=value]' to pass your options to the Java compiler.\n return listOf(\"-AinputDir=${inputDir.singleFile.absolutePath}\",\n \"-AoutputDir=${outputDir.absolutePath}\")\n }\n}\n\nandroid {...}\n```\n\n### Groovy\n\n```groovy\nclass MyArgsProvider implements CommandLineArgumentProvider {\n\n // Annotates each directory as either an input or output for the\n // annotation processor.\n @InputFiles\n // Using this annotation helps Gradle determine which part of the file path\n // should be considered during up-to-date checks.\n @PathSensitive(PathSensitivity.RELATIVE)\n FileCollection inputDir\n\n @OutputDirectory\n File outputDir\n\n // The class constructor sets the paths for the input and output directories.\n MyArgsProvider(FileCollection input, File output) {\n inputDir = input\n outputDir = output\n }\n\n // Specifies each directory as a command line argument for the processor.\n // The Android plugin uses this method to pass the arguments to the\n // annotation processor.\n @Override\n Iterable\u003cString\u003e asArguments() {\n // Use the form '-Akey[=value]' to pass your options to the Java compiler.\n [\"-AinputDir=${inputDir.singleFile.absolutePath}\",\n \"-AoutputDir=${outputDir.absolutePath}\"]\n }\n}\n\nandroid {...}\n```\n\nAfter you define a class that implements `CommandLineArgumentProvider`, you need\nto create an instance and pass it to the Android plugin using the\n[`annotationProcessorOptions.compilerArgumentProvider`](/reference/tools/gradle-api/current/com/android/build/api/dsl/AnnotationProcessorOptions#compilerArgumentProvider(org.gradle.process.CommandLineArgumentProvider))\nmethod, as shown below. \n\n### Kotlin\n\n```kotlin\n// This is in your module's build.gradle file.\nandroid {\n defaultConfig {\n javaCompileOptions {\n annotationProcessorOptions {\n // Creates a new MyArgsProvider object, specifies the input and\n // output paths for the constructor, and passes the object\n // to the Android plugin.\n compilerArgumentProvider(MyArgsProvider(files(\"input/path\"),\n file(\"output/path\")))\n }\n }\n }\n}\n```\n\n### Groovy\n\n```groovy\n// This is in your module's build.gradle file.\nandroid {\n defaultConfig {\n javaCompileOptions {\n annotationProcessorOptions {\n // Creates a new MyArgsProvider object, specifies the input and\n // output paths for the constructor, and passes the object\n // to the Android plugin.\n compilerArgumentProvider new MyArgsProvider(files(\"input/path\"),\n new File(\"output/path\"))\n }\n }\n }\n}\n```\n\nTo learn more about how implementing `CommandLineArgumentProvider` helps\nimprove build performance, read\n[Caching Java projects](https://docs.gradle.org/current/userguide/build_cache_use_cases.html).\n\nDisable the annotation processor error check\n--------------------------------------------\n\nIf you have dependencies on the compile classpath that include annotation\nprocessors you don't need, you can disable the error check by adding\nthe following to your `build.gradle.kts` file. Keep in mind, the annotation\nprocessors you add to the compile classpath are still not added to the\nprocessor classpath. \n\n### Kotlin\n\n```kotlin\nandroid {\n ...\n defaultConfig {\n ...\n javaCompileOptions {\n annotationProcessorOptions {\n argument(\"includeCompileClasspath\", \"false\")\n }\n }\n }\n}\n```\n\n### Groovy\n\n```groovy\nandroid {\n ...\n defaultConfig {\n ...\n javaCompileOptions {\n annotationProcessorOptions {\n includeCompileClasspath false\n }\n }\n }\n}\n```\n\nIf you use Kotlin and [kapt](https://kotlinlang.org/docs/kapt.html): \n\n### Kotlin\n\n```kotlin\nandroid {\n ...\n defaultConfig {\n ...\n kapt {\n includeCompileClasspath = false\n }\n }\n}\n```\n\n### Groovy\n\n```groovy\nandroid {\n ...\n defaultConfig {\n ...\n kapt {\n includeCompileClasspath false\n }\n }\n}\n```\n\nIf you experience issues after migrating your project's annotation processors to\nthe processor classpath, you can allow annotation processors on the compile\nclasspath by setting `includeCompileClasspath` to `true`. However, setting this\nproperty to `true` is not recommended, and the option to do so will be removed\nin a future update of the Android plugin."]]