ปลั๊กอิน Maven ที่ห่อหุ้ม 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 สำหรับประเภทรายงานที่รองรับ
< 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 สำหรับข้อมูลเพิ่มเติมเกี่ยวกับการสร้าง baselines ให้ดู 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. {พารามิเตอร์}
ตัวอย่าง
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. {พารามิเตอร์} โดยค่าเริ่มต้นไฟล์ที่เรียกว่า 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