How to fully disable javadoc checking with checkstyle maven plugin - maven

i want to use the Maven Checkstyle plugin with a custom configuration that tells Checkstyle to not warn or error on missing Javadoc. Is there a way to do this?

Just found it myself. To fully ignore all javadoc checking for everthing, add this to your checkstyle configuration:
<!-- No need for Javadoc -->
<module name="JavadocType">
<property name="severity" value="ignore"/>
</module>
<module name="JavadocMethod">
<property name="severity" value="ignore"/>
</module>
<module name="JavadocVariable">
<property name="severity" value="ignore"/>
</module>

One good option would be configuring a suppressions filter.
Plugin configuration:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<!-- ... -->
<build>
<plugins>
<!-- ... -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>2.17</version>
<executions>
<execution>
<id>verify</id>
<phase>verify</phase>
<configuration>
<encoding>UTF-8</encoding>
<consoleOutput>true</consoleOutput>
<failsOnError>true</failsOnError>
<linkXRef>false</linkXRef>
<suppressionsLocation>
checkstyle-suppressions.xml
</suppressionsLocation>
<suppressionsFileExpression>
checkstyle.suppressions.file
</suppressionsFileExpression>
</configuration>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<!-- ... -->
</project>
checkstyle-suppressions.xml file:
<?xml version="1.0"?>
<!DOCTYPE suppressions PUBLIC
"-//Puppy Crawl//DTD Suppressions 1.0//EN"
"http://www.puppycrawl.com/dtds/suppressions_1_0.dtd">
<suppressions>
<suppress checks="Javadoc" files="."/>
</suppressions>
Then running
$ mvn verify
Does not output any Javadoc-related Checkstyle errors.
Many other examples on suppressions filters may be found in checkstyle repository.

Below is the example with the Gradle 7.3.2 setup.
build.gradle
plugins {
id 'checkstyle'
}
Folder structure (root level).
├── config
   └── checkstyle
   ├── checkstyle.xml
   └── suppressions.xml
Below is the entry in checkstyle.xml to include suppressions.xml
<module name="SuppressionFilter">
<property name="file" value="${config_loc}/suppressions.xml" />
</module>
And now you can have the suppressions in the suppressions.xml file to ignore a particular type of check.
for e.g. Below code base will ignore the mentioned checks for all files (regex can be applied to ignore particular matching set of files.)
<suppressions>
<suppress files="." checks="JavadocMethod"/>
<suppress files="." checks="JavadocPackage"/>
<suppress files="." checks="JavadocVariable"/>
<suppress files="." checks="MissingJavadocMethod"/>
<suppress files="." checks="JavadocPackage"/>
</suppressions>
Now execute the Checkstyle task on consolidated project files by
gradle check
If specific execution is needed then use checkstyleMain or checkStyleTest to execute checkstyle report on Source files or test files respectively.

Related

Properties defined in the properties section of the POM are not seen in external ant build file

I'm using maven-antrun-plugin in my pom.xml with external ant file.
It's said in plugin's document:
All of the properties available to Maven are also available in the
target configuration. However, you may want to call an external Ant
build script using the ant task. To avoid name conflicts, only a
subset of the properties are passed to the external Ant build. These
include all properties defined in the properties section of the POM.
It also includes prefixed versions of some of the commonly used Maven
properties.
So here's my pom, where I define "test.prop" property:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>testant</groupId>
<artifactId>testant</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<test.prop>TestPropValue</test.prop>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<dependencies>
<dependency>
<groupId>ant</groupId>
<artifactId>optional</artifactId>
<version>1.5.4</version>
</dependency>
</dependencies>
<executions>
<execution>
<id>generate-index-properties</id>
<phase>install</phase>
<configuration>
<tasks>
<!--<property name="test.prop" value="${test.prop}"/>-->
<ant antfile="build.xml">
<target name="echo-prop"/>
</ant>
</tasks>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
And just trying to echo this property in build.xml:
<project default="test">
<target name="echo-prop">
<echo>${test.prop}</echo>
</target>
</project>
This is what I get:
echo-prop:
[echo] ${test.prop}
So property is not resolved as it should, according to the doc.
And it works fine only in case if I uncomment line with explicit property declaration under "tasks" tag.
Could you please help me in understanding, what am I doing wrong?
Thank you!
You should specify a version for the antrun-plugin:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.8</version><!--$NO-MVN-MAN-VER$-->
(...)
</plugin>
ant by default passes all properties of the parent to an underlying "ant"-call. Unless you define inheritAll=false, all properties are passed.
In this case, you should have a look at the effective pom. There a very ancient version of the antrun-plugin is defined.
As soon as you switch to a recent one, the example code works.

IntelliJ IDEA not "hyperlinking" to source files in Maven Run tool window

I have been using intellij for 2 years now and love it. however after updating to 2016.3.4 it stopped highlighting path locations in the run window.
I used to be able to just click on the highlighted path and it would jump to the file and line.
example of output from maven-checkstyle-plugin which should be "clickable" :
[ERROR] C:\Users\userName\Documents\project.main\src\main\java\MyClass.java:36: Only one statement per line allowed. [OneStatementPerLine]
This is extremely frustrating and any idea of how to get intellij to do this again would be fantastic.
Minimal, Complete, and Verifiable example
To Replicate this Create a project in IntelliJ IDEA called "bug"
IntelliJ IDEA 2016.3.4
Build #IU-163.12024.16, built on January 31, 2017
Create a folder
bug->CodeStyle
and a file in this folder
"checkstyle.xml"
<?xml version="1.0"?>
<!DOCTYPE module PUBLIC
"-//Puppy Crawl//DTD Check Configuration 1.3//EN"
"http://www.puppycrawl.com/dtds/configuration_1_3.dtd">
<module name="Checker">
<property name="charset" value="UTF-8"/>
<property name="severity" value="error"/>
<property name="fileExtensions" value="java,"/>
<module name="FileTabCharacter"/>
<module name="TreeWalker">
<module name="RegexpSinglelineJava">
<property name="format" value="System\.(out|err).*?$"/>
<property name="ignoreComments" value="true"/>
</module>
</module>
</module>
the pom
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>bugExample</groupId>
<artifactId>bug</artifactId>
<version>1.0-SNAPSHOT</version>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>2.17</version>
<executions>
<execution>
<id>validate</id>
<phase>validate</phase>
<configuration>
<configLocation>CodeStyle/checkstyle.xml</configLocation>
<consoleOutput>true</consoleOutput>
<failsOnError>true</failsOnError>
<includeTestSourceDirectory>true</includeTestSourceDirectory>
</configuration>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>com.puppycrawl.tools</groupId>
<artifactId>checkstyle</artifactId>
<version>6.18</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
</project>
and a Class Example.java
public class Example {
public Example() {
System.out.println("This is not allowed");
}
}
And now in the maven project Tool Click life-cycle, and then Validate.
The outputs in the "run terminal" :
[INFO] Starting audit...
[ERROR] C:\Users\Username\bug\src\main\java\Example.java:7: Line matches the illegal pattern 'System\.(out|err).*?$'. [RegexpSinglelineJava]
Audit done.
So the problem is that Example.java is Not "Clickable", it has been in the past.
Thanks for the example, I've reported a bug for IntelliJ IDEA Maven integration, feel free to vote:
IDEA-169034 File paths are not clickable in the Maven tool output

How can I force the Maven EAR plugin to use a context root variable within application.xml?

I'm using the Maven EAR plugin to generate the application.xml of my EAR, which contains a WAR.
I want the contextRoot of that WAR to be determined at runtime (this works thanks to JBoss AS 7), so the application.xml should contain something like this:
<module>
<web>
<web-uri>my.war</web-uri>
<context-root>${my.context.root}</context-root>
</web>
</module>
This works by setting the System Property my.context.root within JBoss AS 7 and configuring JBoss to replace variables within XML descriptor files:
<system-properties>
<property name="my.context.root" value="/foo"/>
</system-properties>
<subsystem xmlns="urn:jboss:domain:ee:1.1">
<spec-descriptor-property-replacement>true</spec-descriptor-property-replacement>
<jboss-descriptor-property-replacement>true</jboss-descriptor-property-replacement>
</subsystem>
If I do this by editing the generated application.xml in the EAR, it works.
However, I can't get Maven to write ${my.context.root} into the context root within application.xml.
I tried this first (since nothing is filtered, it should work):
<configuration>
<modules>
<webModule>
<groupId>my.group</groupId>
<artifactId>my-war</artifactId>
<contextRoot>${my.context.root}</contextRoot>
</webModule>
</modules>
</configuration>
Apparently, even though filtering defaults to false, Maven still thinks it should use this as Maven property. The result is that the EAR plugin just puts in the WAR's name:
<module>
<web>
<web-uri>my-war.war</web-uri>
<context-root>/my-war</context-root>
</web>
</module>
So I tried escaping:
<configuration>
<modules>
<webModule>
<groupId>my.group</groupId>
<artifactId>my-war</artifactId>
<contextRoot>\${my.context.root}</contextRoot>
</webModule>
</modules>
</configuration>
This is then taken literally:
<module>
<web>
<web-uri>my-war.war</web-uri>
<context-root>\${my.context.root}</context-root>
</web>
</module>
How can I get Maven to do what I want? (Of course, I could try to hack application.xml by using the Maven replacer plugin, but that's ugly...)
Thanks for any hints!
Well, since nobody knows a better answer, here's how I hacked application.xml into shape:
<plugin>
<groupId>com.google.code.maven-replacer-plugin</groupId>
<artifactId>replacer</artifactId>
<executions>
<execution>
<id>replace-escaped-context-root</id>
<phase>process-resources</phase>
<goals>
<goal>replace</goal>
</goals>
<configuration>
<file>${project.build.directory}/${project.build.finalName}/META-INF/application.xml</file>
<regex>false</regex>
<token>\${</token>
<value>${</value>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-ear-plugin</artifactId>
<configuration>
<modules>
<webModule>
<groupId>my.group</groupId>
<artifactId>my-war</artifactId>
<contextRoot>\${my.context.root}</contextRoot>
</webModule>
</modules>
</configuration>
</plugin>

Maven Update changes .classpath failing build while war packaging

I've a Spring Maven webapp project which is to be deployed in Tomcat.
I want to package my project to .war for which I've my POM.xml as follows.
<!-- Other settings -->
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.4</version>
</plugin>
</plugins>
</build>
<!-- other settings -->
With this setting, when I do Maven -> Update from m2eclipse and Run as -> Run on Server, it gives ClassNotFoundException for ContextLoaderListener.
But when I add Maven Dependencies to my java build path from Deployment Assembly from project properties as described in https://stackoverflow.com/a/15780350/1433665 , the project runs fine. But again when I do Maven Update, same problem persists.
How can I configure my pom.xml such that I don't have to edit Deployment Assembly settings everytime I do Maven -> Update ?
Also, only file that is changed after Maven -> Update is .classpath in which
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
<attributes>
<attribute name="maven.pomderived" value="true"/>
<attribute name="org.eclipse.jst.component.dependency" value="/WEB-INF/lib"/>
</attributes>
</classpathentry>
is updated to
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>

Maven unpack dependencies from Ant plugin mojo

I have a Maven ant plugin that bundles up a library of Ant tasks. One of them has a lot of CI tasks.
I have the plugin working and can hit the task by running
mvn -U ci:options
This brings up a menu for the different operations.
The issue i'm having is that I need to resolve dependencies in the pom before the task is executed.
From reading up I would have thought that I could add
<execution>
<goal>dependency:unpack-dependencies</goal>
</execution>
To the pluginMetaData xml file that defines the mojo, though this doesn't seem to do anything
ci.mojos.xml
<pluginMetadata xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/plugin-metadata-1.0.0.xsd">
<mojos>
<mojo>
<!-- target name to call in ant script -->
<call>run</call>
<!-- mojo goal name -->
<goal>options</goal>
<execution>
<goal>dependency:unpack-dependencies</goal>
</execution>
<parameters>
<parameter>
<name>artifactId</name>
<property>artifactId</property>
<required>true</required>
<readonly>true</readonly>
<type>java.lang.String</type>
<defaultValue>${project.artifactId}</defaultValue>
<description>Project Artifact Id</description>
</parameter>
....
ci.build.xml
<property name="project.home" location="."/>
<property name="target.dir" value="${project.home}/target"/>
<property name="build.dir" value="${target.dir}/build"/>
<property name="dependency.dir" value="${target.dir}/dependency"/>
<!-- Add contrib to the classpath -->
<taskdef resource="net/sf/antcontrib/antlib.xml"/>
<!-- Include ant utils from the shared resource -->
<include file="${dependency.dir}/shared_ant/build.xml"/>
<!-- Continuous Integration Options -->
<target name="run" description="Continuous Integration Options">
<ci.options/>
</target>
</project>
Any help greatly appreciated.
James

Resources