Class CpdPlugin

java.lang.Object
de.aaschmid.gradle.plugins.cpd.CpdPlugin
All Implemented Interfaces:
org.gradle.api.Plugin<org.gradle.api.Project>

@Incubating public class CpdPlugin extends Object implements org.gradle.api.Plugin<org.gradle.api.Project>
A plugin for the finding duplicate code using CPD source code analyzer (which is a part of PMD).

Creates and registers a cpd extension with the default task options for every task of type Cpd.

Declares a cpd configuration which needs to be configured with the PMD library containing the CPD library to be used.

A Cpd task named cpd is created and configured with default options. It can be further configured to analyze the source code you want, e.g. source = project.files('src').

The created Cpd task is added to the check lifecycle task of LifecycleBasePlugin if it is also applied, e.g. using JavaPlugin.

Sample:

 apply plugin: 'cpd'

 repositories{
     mavenCentral()
 }

 cpd {
     minimumTokenCount = 25
     // As PMD was split with v5.2.0 and CPD has moved to 'pmd-core', 'toolVersion' is just available for 5.2.0 and higher
     toolVersion = 5.2.1
 }

 tasks.cpd {
     allprojects.findAll{ p -> p.hasProperty('sourceSets') }.each{ p ->
         p.sourceSets.all{ sourceSet -> source sourceSet.allJava }
     }
 }
 
See Also:
  • Constructor Details

    • CpdPlugin

      public CpdPlugin()
  • Method Details

    • apply

      public void apply(org.gradle.api.Project project)
      Specified by:
      apply in interface org.gradle.api.Plugin<org.gradle.api.Project>