تنظيم صفحاتك في مجموعات
يمكنك حفظ المحتوى وتصنيفه حسب إعداداتك المفضّلة.
تتيح لك أداة Kapt (أداة معالجة التعليقات التوضيحية في Kotlin) استخدام
معالجات التعليقات التوضيحية في Java مع رمز Kotlin، حتى إذا لم تكن هذه المعالجات متوفّرة
مع Kotlin. ويتم ذلك من خلال إنشاء نماذج Java منملفاتك
Kotlin التي يمكن للمعالجات قراءتها بعد ذلك. إنّ إنشاء هذه العناصر المصغّرة عملية
مكلفة ولها تأثير كبير في سرعة الإنشاء.
يمكنك تشغيل kapt وKSP جنبًا إلى جنب في مشروعك أثناء عملية نقل البيانات، ويمكن إجراء عملية النقل وحدة تلو الأخرى ومكتبة تلو الأخرى.
في ما يلي نظرة عامة على خطوات نقل البيانات:
التحقّق من المكتبات التي تستخدمها لمعرفة ما إذا كانت متوافقة مع KSP
إضافة مكوّن KSP الإضافي إلى مشروعك
استبدال معالجات التعليقات التوضيحية بـ KSP
إزالة المكوّن الإضافي kapt
التحقّق من المكتبات التي تستخدمها لمعرفة ما إذا كانت متوافقة مع KSP
للبدء، تحقَّق مما إذا كانت المكتبات التي تستخدمها مع kapt متوافقة مع KSP. وينطبق ذلك على العديد من المكتبات الشائعة (بما في ذلك
Dagger وGlide وRoom وMoshi)، وتعمل مكتبات أخرى على توفير هذه الميزة.
يمكنك الاطّلاع على قائمة المكتبات المتوافقة في مستندات المساعدة، أو الرجوع إلى مستندات المكتبات التي تستخدمها ونظام تتبُّع المشاكل فيها.
إضافة مكوّن KSP الإضافي إلى مشروعك
أولاً، عليك الإفصاح عن المكوّن الإضافي KSP في ملف build.gradle.kts ذي المستوى الأعلى.
احرص على اختيار إصدار KSP متوافق مع إصدار Kotlin
في مشروعك. يمكنك العثور على قائمة بالإصدارات على صفحة GitHub الخاصة بـ KSP.
بعد ذلك، فعِّل KSP في ملف build.gradle.kts على مستوى الوحدة:
Kotlin
plugins{id("com.google.devtools.ksp")}
رائع
plugins{id'com.google.devtools.ksp'}
استبدال معالجات التعليقات التوضيحية بـ KSP
بعد تفعيل KSP، يمكنك بدء استبدال استخدامات kapt بـ KSP. بالنسبة إلى
الغالبية العظمى من المكتبات، لا يتطلّب ذلك سوى تغيير kapt إلى ksp في بيان
التبعية، لأنّها تُرسِل معالج التعليقات التوضيحية ومعالج KSP في
العنصر نفسه.
بعد الانتقال إلى KSP، يمكنك مزامنة مشروعك وإنشاءه لمعرفة ما إذا كان لا يزال يعمل بشكلٍ
صحيح.
في ما يلي بعض المشاكل الشائعة التي يجب الانتباه إليها:
لا توفّر بعض المكتبات مجموعة الميزات نفسها تمامًا باستخدام kapt وKSP.
إذا تعطّلت رمزك البرمجي بعد نقل البيانات، راجِع مستندات المكتبة.
تتضمّن أداة KSP معلومات أكثر دقة عن أنواع Kotlin مقارنةً بأداة kapt (على سبيل المثال، معلومات عن
عدم قابلية القيمة للعدم)، ما يعني أنّ معالجات KSP يمكن أن تكون أكثر دقة بشأن متطلبات
الأنواع. قد يتطلّب ذلك أيضًا إجراء بعض الإصلاحات في رمز المصدر، بالإضافة إلى تعديل ملفات التصميم.
إذا كنت تُدخل في السابق مَعلمات إلى معالج التعليقات التوضيحية،
من المرجّح أن تحتاج إلى إدخال هذه المَعلمات إلى KSP الآن. يُرجى العلم أنّ تنسيق
الوسيطات قد يختلف بين kapt وKSP. اطّلِع على مستندات واجهة برمجة التطبيقات لخدمات سحابة الخدمات (KSP) وراجع مستندات المكتبة
التي تستخدمها للاطّلاع على مزيد من المعلومات.
إزالة المكوّن الإضافي kapt
عند عدم توفّر أيّ تبعيات مضمّنة مع kapt في وحدتك بعد الآن،
أزِل المكوّن الإضافي kapt.
إذا تم الإعلان عنه في مجموعة مكوّنات إضافية:
Kotlin
plugins{id("org.jetbrains.kotlin.kapt")}
رائع
plugins{id'org.jetbrains.kotlin.kapt'}
إذا كان يستخدم بنية تطبيق المكوّن الإضافي باستخدام Groovy:
apply plugin: 'kotlin-kapt'
عليك أيضًا إزالة أي إعدادات متبقية مرتبطة بـ kapt، مثل:
يخضع كل من المحتوى وعيّنات التعليمات البرمجية في هذه الصفحة للتراخيص الموضحّة في ترخيص استخدام المحتوى. إنّ Java وOpenJDK هما علامتان تجاريتان مسجَّلتان لشركة Oracle و/أو الشركات التابعة لها.
تاريخ التعديل الأخير: 2025-07-27 (حسب التوقيت العالمي المتفَّق عليه)
[[["يسهُل فهم المحتوى.","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 (حسب التوقيت العالمي المتفَّق عليه)"],[],[],null,["# Migrate from kapt to KSP\n\n| **Note:** Kapt is now in maintenance mode, and we recommend that you migrate from kapt to KSP for all processors that support it. In most cases, this migration only requires changes to your project's build configuration.\n\n[Kapt (the Kotlin Annotation Processing Tool)](https://kotlinlang.org/docs/kapt.html) lets you use\nJava annotation processors with Kotlin code, even if those processors don't have\nspecific support for Kotlin. This is done by generating Java stubs from your\nKotlin files that the processors can then read. This stub generation is an\nexpensive operation and has a significant impact on build speed.\n\n[KSP (Kotlin Symbol Processing)](https://github.com/google/ksp) is a Kotlin-first alternative to\nkapt. KSP analyzes Kotlin code directly, which is [up to 2x\nfaster](https://android-developers.googleblog.com/2021/09/accelerated-kotlin-build-times-with.html). It also has a better understanding of Kotlin\nlanguage constructs.\n\nYou can run kapt and KSP alongside each other in your project while you're\nmigrating, and the migration can be done module by module, library by library.\n| **Note:** If a module has any kapt processors remaining, stubs are still generated in that module. This means that the majority of performance improvement will occur only when all usages of kapt are removed from the module.\n\nHere's an overview of the migration steps:\n\n1. Check the libraries you use for KSP support\n2. Add the KSP plugin to your project\n3. Replace annotation processors with KSP\n4. Remove the kapt plugin\n\nCheck the libraries you use for KSP support\n-------------------------------------------\n\nTo get started, check if the libraries you're using with kapt already have KSP\nsupport. This is the case for many popular libraries (including\n[Dagger](https://github.com/google/dagger/issues/2349), [Glide](https://bumptech.github.io/glide/doc/download-setup.html#kotlin---ksp), [Room](/jetpack/androidx/releases/room#declaring_dependencies),\nand [Moshi](https://github.com/square/moshi#codegen)), and others are adding support.\n\nYou can check the [list of supported libraries](https://kotlinlang.org/docs/ksp-overview.html#supported-libraries) in the\ndocumentation, or refer to the documentation and issue tracker of the libraries\nyou're using.\n| **Note:** While not a traditionally-included library dependency, [Data Binding](/topic/libraries/data-binding) also uses an annotation processor to provide its functionality, and [KSP support\n| for Data Binding is not planned](https://issuetracker.google.com/issues/173030256#comment10). You can mitigate the impact of kapt on your build by isolating the usages of Data Binding to separate modules.\n\nAdd the KSP plugin to your project\n----------------------------------\n\nFirst, declare the KSP plugin in your top level `build.gradle.kts` file.\nMake sure that you choose a KSP version aligned with your project's Kotlin\nversion. You can find a list of releases on the [KSP GitHub\npage](https://github.com/google/ksp/releases).\n**Note:** The first part of the KSP version must match the version of Kotlin being used in your build. For example, if you're using Kotlin `2.0.21`, the KSP version must be one of the `2.0.21-x.y.z` releases. \n\n### Kotlin\n\n```kotlin\nplugins {\n id(\"com.google.devtools.ksp\") version \"2.0.21-1.0.27\" apply false\n}\n```\n\n### Groovy\n\n```groovy\nplugins {\n id 'com.google.devtools.ksp' version '2.0.21-1.0.27' apply false\n}\n```\n\nThen, enable KSP in your module-level `build.gradle.kts` file: \n\n### Kotlin\n\n```kotlin\nplugins {\n id(\"com.google.devtools.ksp\")\n}\n```\n\n### Groovy\n\n```groovy\nplugins {\n id 'com.google.devtools.ksp'\n}\n```\n\nReplace annotation processors with KSP\n--------------------------------------\n\nWith KSP enabled, you can start replacing usages of kapt with KSP. For a vast\nmajority of libraries, this just requires changing kapt to ksp at the dependency\ndeclaration, as they ship their annotation processor and KSP processor in the\nsame artifact.\n**Note:** Some libraries (such as [Glide](https://bumptech.github.io/glide/doc/download-setup.html#kotlin---ksp)) might require you to change the dependency to a different artifact as well. Make sure to consult their documentation. \n\n### Kotlin\n\n```kotlin\ndependencies {\n kapt(\"androidx.room:room-compiler:2.5.0\")\n ksp(\"androidx.room:room-compiler:2.5.0\")\n}\n```\n\n### Groovy\n\n```groovy\ndependencies {\n kapt 'androidx.room:room-compiler:2.5.0'\n ksp 'androidx.room:room-compiler:2.5.0'\n}\n```\n\nAfter moving to KSP, sync and build your project to see if it still works\ncorrectly.\n\nSome common issues to look out for:\n\n- Some libraries don't support the exact same set of features with kapt and KSP. If your code breaks after migrating, check the library's documentation.\n- KSP has more accurate Kotlin type information than kapt (for example, about nullability), which means that KSP processors can be more precise about type requirements. This might require some fixes in your source code as well, in addition to updating your build files.\n- If you were previously passing in arguments to the annotation processor, you'll likely need to pass in those arguments to KSP now. Note that the format of the arguments might differ between kapt and KSP. See the [KSP\n documentation](https://kotlinlang.org/docs/ksp-quickstart.html#pass-options-to-processors) and consult the documentation of the library you're using to learn more.\n\nRemove the kapt plugin\n----------------------\n\nWhen you have no dependencies included with `kapt` in your module anymore,\nremove the kapt plugin.\n| **Note:** [Data Binding](/topic/libraries/data-binding) also requires kapt to be enabled in the module. In modules where Data Binding is used, kapt can't be removed.\n\nIf it was declared in a plugins block: \n\n### Kotlin\n\n```kotlin\nplugins {\n id(\"org.jetbrains.kotlin.kapt\")\n}\n```\n\n### Groovy\n\n```groovy\nplugins {\n id 'org.jetbrains.kotlin.kapt'\n}\n```\n\nIf it was using the apply plugin syntax using Groovy: \n\n```\napply plugin: 'kotlin-kapt'\n```\n\nYou should also remove any leftover configuration related to kapt, such as: \n\n### Kotlin\n\n```kotlin\n\nkapt {\n correctErrorTypes = true\n useBuildCache = true\n}\n```\n\n### Groovy\n\n```groovy\n\nkapt {\n correctErrorTypes true\n useBuildCache true\n}\n```\n\nAdditional resources\n--------------------\n\n- [KSP documentation on Kotlinlang.org](https://kotlinlang.org/docs/ksp-overview.html)\n- [KSP on GitHub](https://github.com/google/ksp)\n- [kapt on Kotlinlang.org](https://kotlinlang.org/docs/kapt.html) --\\\u003e"]]