How to configure PMD violation threshold in Jenkins - jenkins

I have created a jenkins job and below is the pom file.
1. Can you please suggest a way to ignore a certain 'X' number of PMD violations?
2. Is this setup correct to generate PMD reports? Goal in Jenkins is clean install pmd:check site
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-pmd-plugin</artifactId>
<version>2.7.1</version>
<configuration>
<linkXRef>false</linkXRef>
<!--<targetJdk>1.6</targetJdk>-->
<failOnViolation>true</failOnViolation>
</configuration>
<executions>
<execution>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<reporting>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-pmd-plugin</artifactId>
<version>2.7.1</version>
<configuration>
<linkXRef>false</linkXRef>
<!--<targetJdk>1.6</targetJdk>-->
<failurePriority>5</failurePriority>
<failOnViolation>true</failOnViolation>
<targetDirectory>./pmdOutput</targetDirectory>
<rulesets>
<ruleset>/rulesets/basic.xml</ruleset>
</rulesets>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jxr-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
</plugin>
</plugins>
</reporting>

The PMD Maven plugin doesn't allow to setup thresholds on number of violations, it either fails at the first violation of the given priority, or it doesn't.
What I would probably do is not run the pmd:check target, but have maven generate the reports, and use the Jenkins' PMD plugin to parse the report xml and fail the build if needed.
The PMD plugin for Jenkins does allow more flexible threshold configuration.

Since version 3.10.0, PMD has configuration option maxAllowedViolations:
https://maven.apache.org/plugins/maven-pmd-plugin/cpd-check-mojo.html#maxAllowedViolations
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<configuration>
<maxAllowedViolations>180</maxAllowedViolations>
</configuration>
</plugin>

Related

maven-dependency-plugin:unpack Error

I'm trying to extract some .exe files from a dependency jar file and put them under ${project.build.directory}/classes/.
But when I execute:
mvn clean compile dependency:unpack
I get:
Failed to execute goal org.apache.maven.plugins:maven-dependency-plugin:2.10:unpack (default-cli) on project simple: Either artifact or artifactItems is required -> [Help 1
I have verified that the dependencies are available in my local repository.
In my example pom below I've used junit as an example, but no matter which dependency I list, I get the same error.
pom.xml:
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.10</version>
<executions>
<execution>
<id>unpack</id>
<phase>package</phase>
<goals>
<goal>unpack</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.10</version>
<type>jar</type>
<overWrite>false</overWrite>
<outputDirectory>${project.build.directory}/classes/externaltools</outputDirectory>
<includes>**/*.txt</includes>
</artifactItem>
</artifactItems>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</pluginManagement>
</build>
The issue is due to you cannot use mvn clean compile dependency:unpack and <executions> tags together.
In documentation Maven Depdendency Plugin at the bottom part of the page you can read:
If you intend to configure this mojo for execution on the command line using: mvn dependency:unpack you must not put the configuration inside the executions tag. Your configuration should look like this:
<project>
[...]
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.10</version>
<configuration>
<artifactItems>
<artifactItem>
<groupId>[ groupId ]</groupId>
<artifactId>[ artifactId ]</artifactId>
<version>[ version ]</version>
<type>[ packaging ]</type>
<classifier> [classifier - optional] </classifier>
<overWrite>[ true or false ]</overWrite>
<outputDirectory>[ output directory ]</outputDirectory>
<destFileName>[ filename ]</destFileName>
<includes>[ comma separated list of file filters ]</includes>
<excludes>[ comma separated list of file filters ]</excludes>
</artifactItem>
</artifactItems>
<!-- other configurations here -->
</configuration>
</plugin>
</plugins>
</build>
[...]
</project>
I have tried removing the <execution> tags and works perfectly!

maven doesn't recognize tests dependencies in additional test-source directories

I'm trying to separate unit tests and integration tests in the same project. I used the build-helper-maven-plugin to configure my additional sources folders ( for integration tests) as below:
<pluginManagement>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>1.8</version>
<configuration>
<sources>
<source>${integrationSourceDirectory}</source>
</sources>
<resources>
<resource>
<directory>${integrationResourceDirectory}</directory>
<targetPath>${integrationOutputDirectory}</targetPath>
</resource>
</resources>
</configuration>
</plugin>
</plugins>
</pluginManagement>
....
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<executions>
<execution>
<id>add-test-sources</id>
<phase>generate-test-sources</phase>
<goals>
<goal>add-test-source</goal>
</goals>
</execution>
<execution>
<id>add-test-resources</id>
<phase>generate-test-resources</phase>
<goals>
<goal>add-test-resource</goal>
</goals>
</execution>
</executions>
</plugin>
When I open the project in netbeans 7.3.1. the additional source folder is recognized as "generated sources" and my test libraries are not included in the classpath of the classes indluded in this tests folder (ex. arquillian ).
How can I fix that in netbeans ?
Thanks in advance for your help

Maven Javadoc Plugin During Site Goal: javadoc: error - java.lang.OutOfMemoryError: Please increase memory

I have been struggling to increase the memory of my javadoc plugin via my pom file. For some reason my Mac build slave fails during the site goal with an OutOfMemoryError. I tried adjusting the maxmemory of the javadoc plugin via my pluginManagement section of the pom (as per the maven-javadoc-plugin documentation):
...
<build>
...
<pluginManagement>
<plugins>
...
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.8.1</version>
<configuration>
<maxmemory>512m</maxmemory>
</configuration>
</plugin>
</plugins>
<pluginManagement>
...
</build>
...
This didn't seem to help anything, my build still failed with an out of memory error.
So I decided to put this directly in my plugin declaration instead (see the build-plugins-plugin section below:
...
<build>
...
<pluginManagement>
<plugins>
...
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.8.1</version>
</plugin>
...
</plugins>
<pluginManagement>
<plugins>
...
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<configuration>
<maxmemory>512m</maxmemory>
</configuration>
</plugin>
...
</plugins>
...
</build>
...
...and yet this is still not working, the Mac build slave still fails during the site goal.
It turned out I was being an idiot. The site goal uses the plugin defintions declared in the reporting section of the pom. Therefore I had to add my max memory configuration here instead, see below:
...
<build>
...
<pluginManagement>
<plugins>
...
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.8.1</version>
</plugin>
</plugins>
<pluginManagement>
...
</build>
...
<reporting>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.8.1</version>
<configuration>
<maxmemory>512m</maxmemory>
</configuration>
</plugin>
</plugins>
</reporting>
...
Based on this result, it is my assumption that Maven will not pick up configuration details defined in the build-pluginManagement section of the pom for plugins defined in the reporting section. Cheers.

gmaven grails project not using maven-war-plugin

I'm having issues with a filtered context.xml file being packaged in a mvn grails:war execution.
I have it working when you do mvn war:war but doing that doesn't create my grails application war. When running mvn grails:war I don't get the context.xml file. Is this a case of the grails:war target not running the maven-war-plugin? I'm getting no errors. Any help is appreciated. Here are my relevant pom settings:
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.1.1</version>
<configuration>
<webResources>
<resource>
<directory>${basedir}/src/main/webapp/META-INF</directory>
<filtering>true</filtering>
<targetPath>META-INF</targetPath>
<includes>
<include>**/context.xml</include>
</includes>
</resource>
</webResources>
</configuration>
</plugin>
<plugin>
<groupId>org.grails</groupId>
<artifactId>grails-maven-plugin</artifactId>
<version>1.3.4</version>
<extensions>true</extensions>
<executions>
<execution>
<goals>
<goal>init</goal>
<goal>maven-clean</goal>
<goal>validate</goal>
<goal>config-directories</goal>
<goal>maven-compile</goal>
<goal>maven-test</goal>
<goal>maven-war</goal>
<goal>maven-functional-test</goal>
<goal>war</goal>
</goals>
</execution>
</executions>
</plugin>
...
<filters>
<filter>${basedir}/src/main/filters/dev.properties</filter>
</filters>
grails:war uses grails command so generate war, so it will ignore anything you configured in the "maven war plugin". You will have to configure it within grails.

Installing a wsdl file into a Maven repository

I'm trying to install a wsdl file into a remote Maven repository so I can reference it in a CXF project as per this blog post.
I'm sure it could be done manually, but I want an actual maven project so I can make use of the release plugin for tagging etc.
Has anybody got experience with this?
You can use the build helper maven plugin to do this. Here is an indicative code snippet
<build>
...
<plugins>
...
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<executions>
<execution>
<id>attach-artifacts</id>
<phase>package</phase>
<goals>
<goal>attach-artifact</goal>
</goals>
<configuration>
<artifacts>
<artifact>
<file>${wsdlLocation}/project.wsdl</file>
<type>wsdl</type>
</artifact>
</artifacts>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build.

Resources