GradlepluginthatconfiguresErrorProne,Checkstyle,PMD,CPD,Lint,Detekt&Ktlint.Allofthesetoolsarealsoautomaticallyhookedintothecheckgradletask.Below,I'llgomoreintodepthhoweachofthosepluginsareconfigured.
ThispluginrequiresGradle5.0orlater.
Setuproot/build.gradle
buildscript{repositories{mavenCentral()google()gradlePluginPortal()//RequiredfortheErrorproneGradlePlugin.}dependencies{classpath"com.vanniktech:gradle-code-quality-tools-plugin:0.20.0"}}applyplugin:"com.vanniktech.code.quality.tools"Information:ThispluginisalsoavailableonGradleplugins
Snapshotbuildscript{repositories{maven{url"https://oss.sonatype.org/content/repositories/snapshots"}}dependencies{classpath"com.vanniktech:gradle-code-quality-tools-plugin:0.21.0-SNAPSHOT"}}applyplugin:"com.vanniktech.code.quality.tools"ConfigurationThephilosophyofthispluginistofailearly.Thismeanshavingzerowarnings/errorsreportedfromanytools.Ifyou'rejustgettingstartedwiththisinalargecodebaseyoumightnotbeabletoachievethisrightawayinwhichcaseyoumightwanttosetfailEarlytofalseandthenapplyatafinermoregranularscopehoweachtoolshouldbehavee.g.checkstyle{ignoreFailures=false}.
Thosearealltheavailableconfigurations-shownwithdefaultvaluesandtheirtypes.MoreinformationcanbefoundintheKotlinDocumentationoftheExtensionandtherespectiveextensionsfordesignatedintegrations.
codeQualityTools{booleanfailEarly=truebooleanxmlReports=truebooleanhtmlReports=falsebooleantextReports=falseString[]ignoreProjects=[]checkstyle{booleanenabled=trueStringtoolVersion='8.6'StringconfigFile='code_quality_tools/checkstyle.xml'BooleanignoreFailures=nullBooleanshowViolations=nullStringsource='src'List<String>include=['**/*.java']List<String>exclude=['**/gen/**']}pmd{booleanenabled=trueStringtoolVersion='6.0.0'StringruleSetFile='code_quality_tools/pmd.xml'BooleanignoreFailures=nullStringsource='src'List<String>include=['**/*.java']List<String>exclude=['**/gen/**']}lint{booleanenabled=trueBooleantextReport=nullStringtextOutput='stdout'BooleanabortOnError=nullBooleanwarningsAsErrors=nullBooleancheckAllWarnings=nullStringbaselineFileName=nullBooleanabsolutePaths=nullFilelintConfig=nullBooleancheckReleaseBuilds=falseBooleancheckTestSources=nullBooleancheckDependencies=null}ktlint{booleanenabled=trueStringtoolVersion='0.32.0'booleanexperimental=false}detekt{booleanenabled=trueStringtoolVersion='1.0.0'Stringconfig='code_quality_tools/detekt.yml'StringbaselineFileName=nullbooleanfailFast=true}cpd{booleanenabled=trueStringsource='src'Stringlanguage='java'BooleanignoreFailures=nullintminimumTokenCount=50}errorProne{booleanenabled=trueStringtoolVersion='2.1.3'}kotlin{booleanallWarningsAsErrors=true}}ToolsHereI'llgiveabitmoreinformationabouthoweachofthetoolswillbeapplied.Ifthere'saGradletaskthatthispluginwillgenerateitwillalsobehookedupintothecheckGradletask.Thismeansthatwhenyouexecutecheckalloftheroolswillberunningforyou.
ErrorProneIt'llapplytheErrorProneGradlePluginwhichwillruntogetherwithassemble.There'snoreportgeneratedforthisbutyou'llgetcompilewarnings&errors.
CheckstyleIt'llapplytheCheckstylePluginandgeneratethecheckstyletaskthatwillexecutecheckstyle.TheconfigurationpropertiesofcodeQualityTools->checkstylemirrorthepropertiesfromtheplugin.
PMDIt'llapplythePMDPluginandgeneratethepmdtaskthatwillexecutepmd.TheconfigurationpropertiesofcodeQualityTools->pmdmirrorthepropertiesfromtheplugin.
CPDIt'llapplytheCPDPluginandgeneratethecpdChecktaskthatwillexecutecpd.TheconfigurationpropertiesofcodeQualityTools->cpdmirrorthepropertiesfromtheplugin.
LintThiswillonlyworkwhenoneoftheAndroidPlugins(com.android.application,com.android.library,etc.)areapplied.TheconfigurationpropertiesofcodeQualityTools->lintmirrorthepropertiesfromthelintOptions.
DetektIt'llusethespecifieddetektversionandgeneratethedetektChecktaskwhichwillrundetektonyourcodebase.
KtlintIt'llusethespecifiedktlintversionandthengeneratetwotasks.ktlintwhichwillrunktlintoveryourcodeandflagissues.ktlintFormatwillreformatyourcode.
Note:TheremightbesomeconfigurationpropertiesthatarenotmirroredinwhichcasefeelfreetoopenaPR.Personally,Idon'thavetheneedforallofthem.
LicenseCopyright(C)2016Vanniktech-NiklasBaudy
LicensedundertheApacheLicense,Version2.0
评论