مكون مافن يلف detekt cli. وهو يدعم نفس المعلمات مثل Detekt CLI.
انظر أدناه كيفية التنفيذ بعد التكوين.
< build >
< plugins >
< plugin >
< groupId >com.github.ozsie</ groupId >
< artifactId >detekt-maven-plugin</ artifactId >
< version >1.23.7</ version >
< executions >
< execution >
< phase >verify</ phase >
< goals >< goal >check</ goal ></ goals >
</ execution >
</ executions >
</ plugin >
</ plugins >
</ build > باستخدام التكوين أعلاه ، سيقوم Detekt بمسح ملفات المصدر في ${basedir}/src وإخراج النتائج في ${basedir}/detekt .
يمكن تكوين جميع المعلمات المتاحة لـ Detekt الإصدار 1.23.7 في البرنامج المساعد.
يدعم البرنامج المساعد الملفات المحلية كتكوين ليتم نقله إلى Detekt.
< build >
< plugins >
< plugin >
< groupId >com.github.ozsie</ groupId >
< artifactId >detekt-maven-plugin</ artifactId >
< version >1.23.7</ version >
< executions >
< execution >
< phase >verify</ phase >
< goals >< goal >check</ goal ></ goals >
< configuration >
< config >config/detekt/detekt.yml</ config >
</ configuration >
</ execution >
</ executions >
</ plugin >
</ plugins >
</ build > يمكن إدراج ملفات متعددة مع ; فاصل.
يدعم البرنامج المساعد التكوين عن بُعد عبر HTTP و HTTPS.
< build >
< plugins >
< plugin >
< groupId >com.github.ozsie</ groupId >
< artifactId >detekt-maven-plugin</ artifactId >
< version >1.23.7</ version >
< executions >
< execution >
< phase >verify</ phase >
< goals >< goal >check</ goal ></ goals >
< configuration >
< config >https://raw.githubusercontent.com/Ozsie/detekt-maven-plugin/fd0de6d59e6ae1e062a9d2b030a171da1d3225ab/src/test/resources/resolve-config/remote/remote-config.yml</ config >
</ configuration >
</ execution >
</ executions >
</ plugin >
</ plugins >
</ build >يدعم Detekt قواعد المجموعات والمعالجات والتقارير ، إلخ. تم تعبئتها في المكونات الإضافية Detekt.
انظر Detekt Marketplace للحصول على قائمة الإضافات المعروفة.
< build >
< plugins >
< plugin >
< groupId >com.github.ozsie</ groupId >
< artifactId >detekt-maven-plugin</ artifactId >
< version >1.23.7</ version >
< executions >
< execution >
< phase >verify</ phase >
< goals >< goal >check</ goal ></ goals >
</ execution >
</ executions >
< dependencies >
<!-- Detekt's first-party unbundled plugin for library authors:
https://detekt.dev/docs/next/rules/libraries -->
< dependency >
< groupId >io.gitlab.arturbosch.detekt</ groupId >
< artifactId >detekt-rules-libraries</ artifactId >
< version >1.23.7</ version >
</ dependency >
</ dependencies >
</ plugin >
</ plugins >
</ build >< build >
< plugins >
< plugin >
< groupId >com.github.ozsie</ groupId >
< artifactId >detekt-maven-plugin</ artifactId >
< version >1.23.7</ version >
< executions >
< execution >
< phase >verify</ phase >
< goals >< goal >check</ goal ></ goals >
< configuration >
< plugins >
< plugin >local/path/to/plugin.jar</ plugin >
</ plugins >
</ configuration >
</ execution >
</ executions >
</ plugin >
</ plugins >
</ build >انظر Detekt Documentation للحصول على أنواع التقارير المدعومة.
< build >
< plugins >
< plugin >
< groupId >com.github.ozsie</ groupId >
< artifactId >detekt-maven-plugin</ artifactId >
< version >1.23.7</ version >
< executions >
< execution >
< phase >verify</ phase >
< goals >< goal >check</ goal ></ goals >
< configuration >
< report >
< report >txt:reports/detekt.txt</ report >
< report >xml:reports/detekt.xml</ report >
</ report >
</ configuration >
</ execution >
</ executions >
</ plugin >
</ plugins >
</ build > بدلاً من ذلك ، يمكن وضع التكوين خارج <executions> . هذا يسمح باستخدام التكوين عند تشغيل الأهداف المستقلة.
< build >
< plugins >
< plugin >
< groupId >com.github.ozsie</ groupId >
< artifactId >detekt-maven-plugin</ artifactId >
< version >1.23.7</ version >
< configuration >
< report >
< report >txt:reports/detekt.txt</ report >
< report >xml:reports/detekt.xml</ report >
</ report >
</ configuration >
< executions >
< execution >
< phase >verify</ phase >
< goals >< goal >check</ goal ></ goals >
</ execution >
</ executions >
</ plugin >
</ plugins >
</ build >أولاً ، يجب إنشاء ملف خط الأساس:
mvn detekt:cb سيؤدي ذلك إلى إنشاء ملف أساسي لكل وحدة اسمها باسم baseline-<module-name>.xml . لمزيد من المعلومات حول إنشاء خطوط الأساس ، راجع Create-Baseline. يمكنك الآن الرجوع إلى ملف خط الأساس في التكوين الخاص بك ، على النحو التالي.
< build >
< plugins >
< plugin >
< groupId >com.github.ozsie</ groupId >
< artifactId >detekt-maven-plugin</ artifactId >
< version >1.23.7</ version >
< configuration >
< baseline >baseline.xml</ baseline >
</ configuration >
< executions >
< execution >
< phase >verify</ phase >
< goals >< goal >check</ goal ></ goals >
</ execution >
</ executions >
</ plugin >
</ plugins >
</ build >انظر العدد رقم 144 للحصول على شرح.
< build >
< plugins >
< plugin >
< groupId >org.apache.maven.plugins</ groupId >
< artifactId >maven-dependency-plugin</ artifactId >
< version >3.2.0</ version >
< executions >
< execution >
< id >generate-classpath-var</ id >
< phase >package</ phase >
< goals >< goal >build-classpath</ goal ></ goals >
< configuration >
< outputProperty >generated.classpath</ outputProperty >
< silent >true</ silent >
</ configuration >
</ execution >
</ executions >
</ plugin >
< plugin >
< groupId >com.github.ozsie</ groupId >
< artifactId >detekt-maven-plugin</ artifactId >
< version >1.23.7</ version >
< configuration >
< baseline >baseline.xml</ baseline >
< classPath >${generated.classpath}</ classPath >
< jvmTarget >17</ jvmTarget >
</ configuration >
< executions >
< execution >
< phase >verify</ phase >
< goals >< goal >ctr</ goal ></ goals >
</ execution >
</ executions >
</ plugin >
</ plugins >
</ build >checkتستخدم لتشغيل detekt. جميع معلمات CLI ، باستثناء -GC و -CB ، متوفرة باستخدام -ddetekt. {parameter}
أمثلة
mvn detekt:check -Ddetekt.config=detekt.ymlmvn detekt:check -Ddetekt.debug=trueإذا كنت بحاجة إلى دقة النوع ، فاستخدم ما يلي بدلاً من ذلك
mvn detekt:ctr -Ddetekt.config=detekt.ymlmvn detekt:ctr -Ddetekt.debug=truecreate-baselineتستخدم لإنشاء خط الأساس. جميع معلمات CLI ، باستثناء -GC و -CB ، متوفرة باستخدام -ddetekt. {parameter}. بشكل افتراضي ، سيتم إنشاء ملف يسمى baseline-.xml. إذا قمت بتضمين -ddetekt.baseline في المكالمة ، فيمكنك تحديد بعض الأسماء الأخرى للملف الأساسي.
أمثلة
mvn detekt:cb -Ddetekt.config=detekt.ymlmvn detekt:cb -Ddetekt.debug=truemvn detekt:cb -Ddetekt.baseline=some-other-baseline.xmlmvn detekt:create-baseline -Ddetekt.config=detekt.ymlmvn detekt:create-baseline -Ddetekt.debug=truegenerate-configتستخدم لإنشاء ملف تكوين افتراضي.
مثال
mvn detekt:gcmvn detekt:generate-config