5

I'm trying to disable execution of maven-pmd-plugin for one of maven project module, but can't find a working solution.
Right now I have the next in the module:

    <properties>
      <cpd.skip>true</cpd.skip>
      <pmd.skip>true</pmd.skip>
      <maven.pmd.enable>false</maven.pmd.enable>
      <maven.pmd.cpd.enable>false</maven.pmd.cpd.enable>
    </properties>

And have the next in the debug output:

[INFO] --- maven-pmd-plugin:3.2:cpd (pmd-cpd) @ module ---
[DEBUG] Configuring mojo org.apache.maven.plugins:maven-pmd-plugin:3.2:cpd from plugin realm ClassRealm[plugin>org.apache.maven.plugins:maven-pmd-plugin:3.2, parent: sun.misc.Launcher$AppClassLoader@6e70c242]
[DEBUG] Configuring mojo 'org.apache.maven.plugins:maven-pmd-plugin:3.2:cpd' with basic configurator -->
[DEBUG]   (f) aggregate = false
[DEBUG]   (f) compileSourceRoots = [/cicd/module/src/main/java]
[DEBUG]   (f) format = xml
[DEBUG]   (f) ignoreIdentifiers = false
[DEBUG]   (f) ignoreLiterals = false
[DEBUG]   (f) includeTests = false
[DEBUG]   (f) includeXmlInSite = false
[DEBUG]   (f) linkXRef = true
[DEBUG]   (f) minimumTokens = 100
[DEBUG]   (f) outputDirectory = /cicd/module/target/site
[DEBUG]   (f) skip = true
[DEBUG]   (f) skipEmptyReport = true
[DEBUG]   (f) targetDirectory = /cicd/module/target
[DEBUG]   (f) testSourceRoots = [/cicd/module/src/test/java]
[DEBUG]   (f) xrefLocation = /cicd/module/target/site/xref
[DEBUG]   (f) xrefTestLocation = /cicd/module/target/site/xref-test
[DEBUG] -- end configuration --
[DEBUG] Exclusions: **/*~,**/#*#,**/.#*,**/%*%,**/._*,**/CVS,**/CVS/**,**/.cvsignore,**/RCS,**/RCS/**,**/SCCS,**/SCCS/**,**/vssver.scc,**/project.pj,**/.svn,**/.svn/**,**/.arch-ids,**/.arch-ids/**,**/.bzr,**/.bzr/**,**/.MySCMServerInfo,**/.DS_Store,**/.metadata,**/.metadata/**,**/.hg,**/.hg/**,**/.git,**/.gitignore,**/.gitattributes,**/.git/**,**/BitKeeper,**/BitKeeper/**,**/ChangeSet,**/ChangeSet/**,**/_darcs,**/_darcs/**,**/.darcsrepo,**/.darcsrepo/**,**/-darcs-backup*,**/.darcs-temp-mail
[DEBUG] Inclusions: **/*.java
[DEBUG] Searching for files in directory /cicd/module/src/main/java
[WARNING] File encoding has not been set, using platform encoding ANSI_X3.4-1968, i.e. build is platform dependent!
[DEBUG] Executing CPD...

I'm wondering why does it execute if skip=true
According to the official FAQ I need to "Simply put maven.pmd.enable=false into your project properties for that one sub-project." Probably I have not correctly put that into the pom. Is it just <properties> in module pom file?

-Dpmd.skip=true -Dcpd.skip=true gives the same result

Anton Balashov
  • 940
  • 1
  • 12
  • 20
  • 1
    No, PMD doesn't use default properties for those values. The default value is a plain "false" not a reference to a property, and `pmd.skip` and `cpd.skip` are User Properties (passed in with `-D`). Those properties will have no effect all by themselves. You should override the configuration of the submodule and set the properties yourself. I'm intrigued non the less you say "-Dpmd.skip=true -Dcpd.skip=true gives the same result", it shouldn't... – Johnco May 16 '18 at 20:33

2 Answers2

5

If you want to disable a maven module, you have configure pmd in that module. And then exclude all. Like this:

   <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-pmd-plugin</artifactId>
    <configuration>
     <analysisCache>true</analysisCache>
     <!-- enable incremental analysis -->
     <excludes>
      <exclude>**/**</exclude>
     </excludes>
    </configuration>
   </plugin>

Maven multimodul-documentation ;hier describes, that configuration in submodules override top level pom definition.

Thomas Michael
  • 153
  • 2
  • 4
1

I found a better solution, look at Disable a Maven plugin defined in a parent POM.

This way you disable the plugin so it is not run at all for the module, so nothing gets generated so this way the build time will also dcrease.

Keyhan
  • 2,370
  • 2
  • 19
  • 22