-
Notifications
You must be signed in to change notification settings - Fork 12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Configuring CPD #9
Comments
Currently the DSL provides no extra configuration for CPD. By default, CPD will run once per module, including all sources; ignoring both literals and identifiers; with language defined to 'java'. You can however re-configure CPD tasks manually through the defined task properties For instance, you could do something such as:
I there anything in particular you would like to configure? Maybe you are hitting a use case I wasn't considering and should extend the current DSL. |
Well, my original assumption was that all of the CPD parameters as described here would be somehow available directly within the DSL similarly to how PMD and Checkstyle configuration is made available. Manually reconfiguring the task as you described may actually be sufficient, I'd have to check. Personally, I'd still prefer exposed options, though, if only for consistency's sake. |
PMD and Checkstyle tasks are implemented by Gradle itself. CPD is not, so we defined it ourselves. We can however map other options to it. We just didn't because we weren't using them ATM. Feel free to submit a PR 'though! As for the DSL, we are not currently exposing all properties from the tasks, only rule config / suppression filters, and whether to fail or not on errors. We are favoring sane defaults for everything else (files to analyze, the version of each tool, report location, etc.). We may add cpd configuration through the DSL, 'though I'm not sure when in our roadmap. If you are eager to get it, feel free to send a PR for review! |
Okay, just checked … your initial solution appears to work, however, not all of the options described in the CPD documentation are available to be set/modified using the task. |
Similarly, is it possible for an option for an xslt file as per the documentation for html output? |
@XVicarious the XSLT transform is not a standard part of CPD, but used as a separate ant task (the xsl file itself is shipped with PMD, but no logic to apply it). That's why the documentation only mentions it for Ant. It would technically be possible to replicate this (as Gradle can run arbitrary ant tasks), but most probably this is better off as a feature request for PMD itself; since that request exceeds this plugin. PMD has a long-standing tech debt regarding CPD report rendering (PMD itself is good), as shown on pmd/pmd#198 Adding report formats for CPD would be much easier if both reporting systems are merged (disclaimer, I'm a PMD maintainer myself). |
I attempted to follow your example for customizing the task, using it to exclude tests, but it does not work: tasks.withType(com.monits.gradle.sca.task.CPDTask).all {
FileTree srcDir = project.fileTree("$project.projectDir/src/")
srcDir.include '**/*.java'
srcDir.exclude '**/test/**'
it.inputFiles = srcDir
} Any suggestions? |
@LethiferousMoose my guess is that you have an issue with the order in which configurations are applied…
static-code-analysis-plugin/src/main/groovy/com/monits/gradle/sca/config/CpdConfigurator.groovy Lines 45 to 57 in 7534d28
the task is created and THEN it's configured. It seems your configuration is applied as soon as the task is created and added to the task container; and then the default configuration overrides it. Try doing this after applying the plugin: plugins {
id 'com.monits.staticCodeAnalysis' version '2.6.9' // it's important to apply the plugin first!
}
afterEvaluate {
tasks.withType(com.monits.gradle.sca.task.CPDTask).all {
FileTree srcDir = project.fileTree("$project.projectDir/src/")
srcDir.include '**/*.java'
srcDir.exclude '**/test/**'
it.inputFiles = srcDir
}
} |
@jsotuyod That seems to have fixed my issue, thanks! I do have a followup question though. I'm currently using this soley for CPD in gradle, we use our own versions for pmd, spotbugs, checkstyle, etc. If I have those turned off via the DSL, does the plugin still try to get the artifacts for your versions? I don't want to encounter any weird dependency issues. |
@LethiferousMoose no, the dependencies are only added / tasks defined if a given tool is enabled. Moreover, even if CPD and PMD are bundled together in the same artifacts ( Non the less, I'm curious as to why use custom versions for PMD / Checkstyle (Spotbugs is not currently supported), as the plugin will always try and use the latest known version to be compatible with your setup (Java version + Gradle version)… is there a use-case I'm missing? |
@jsotuyod I was digging through your code, and it looked like you had everything hard-coded in |
@LethiferousMoose I do manually raise the used version to latest on each release. Using dynamic dependencies hurts configuration time, and Checkstyle is not even using semantic versioning, so I can't rely on a future release working without actually testing it. I'm about ready to make a new release, I should update to PMD 6.13.0 (due this weekend) for it. |
So, the usage explanation shows how to configure everything but CPD. How do I pass custom configuration to the CPD task?
The text was updated successfully, but these errors were encountered: