I tried adding the maven-checkstyle-plugin to my project, but it does not produce any results:
<project>
....
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>3.2.0</version>
<configuration>
<configLocation>google_checks.xml</configLocation>
</configuration>
</plugin>
</plugins>
</build>
</project>
mvn checkstyle:checkstyle or mvn checkstyle:check results in:
[INFO] You have 0 Checkstyle violations.
Which is essentially not true, because I added violations explicit in my code.
So my guess is that checkstyle is not running the analyser properly over my code (that resides just normal in /src/main/resources).
What could I do?
Would I maybe have to add the google_checks.xml file explicit to my classpath??
Related
I have problems setting up my project for testng usage.
Background is that I want to execute my test.xml with maven command line.
I use this plugin within the build section of my pom.xml:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M5</version>
<configuration>
<suiteXmlFiles>
<suiteXmlFile>test.xml</suiteXmlFile>
</suiteXmlFiles>
</configuration>
</plugin>
However... when I call mvn clean test -DxmlSuiteFile=test.xml
all my unit tests are executed but the test.xml is untouched.
when I change the version of surefire to 2.22.2 everything works fine.
BUT I get the message: testSuiteXmlFiles0 has null value
when running only mvn test
I am confused how to get that to run with the surefire 3.0.0-M5 ?
-DxmlSuiteFile=test.xml is not required if it already defined in pom.xml.
Try to define surefire testNG provider explicitly:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M5</version>
<configuration>
<suiteXmlFiles>
<suiteXmlFile>test.xml</suiteXmlFile>
</suiteXmlFiles>
</configuration>
<dependencies>
<dependency>
<groupId>org.apache.maven.surefire</groupId>
<artifactId>surefire-testng</artifactId>
<version>3.0.0-M5</version>
</dependency>
</dependencies>
</plugin>
test.xml file should be in the project root.
See also:
https://maven.apache.org/surefire/maven-surefire-plugin/examples/providers.html
I am trying to run some vulnerability scans(Veracode) on a spring boot application. However, the scan provider suggests running the scans with binaries compiled in debug mode using the following in pom.xml file.
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<debug>true</debug>
<debuglevel>lines,vars,source</debuglevel>
</configuration>
</plugin>
</plugins>
</build>
However, we use the same pom.xml for production deployment where we don't want debug level jars.
Is there a way to create debug jars by passing some argument to the mvn command?
You can use profiles.
<profiles>
<profile>
<id>debug</id>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<debug>true</debug>
<debuglevel>lines,vars,source</debuglevel>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profile>
Profiles are activated in the mvn command, e.g., mvn ... -Pdebug.
I think it is possible to set the arguments in the command line with -D like this:
mvn compile -Dmaven.compiler.debug=true -Dmaven.compiler.debuglevel=lines,vars,source
My project is consisted of two modules, one is common, the other let's call it X.
When using maven to "clean install" module X, it complained:
You have 50 Checkstyle violations.
Looking into the pom.xml I didn't see any checkstyle maven plugin, but in the "common" module I did find it in "common"'s pom.xml:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>2.9.1</version>
</plugin>
Since module X depends on module "common", I updated common's checkstyle plugin in pom.xml like this:
<configuration>
<skip>true</skip>
</configuration>
and rebuilt the common module before I ran the "clean install" on X module.
To play safe, I added one more setting on the mvn command when running X module:
mvn clean install -DskipTests -Dcheckstyle.skip
However, it looks that neitherthe change in "common"'s pom.xml w.r.t checkstyle plugin nor the additional setting on mvn command had any effect on the running - it still complained the same.
I tried with, pluginManagment and it works fine. You need to add this in your parent pom file.
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>2.9.1</version>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
</plugins>
</pluginManagement>
It turned out that there are two places in the pom.xml that involve checkstyle plugin: one is under the tag
<pluginManagement>
, in which I added:
<skip>true</skip>
However it's not sufficient (at least in my case), I found the checkstyle was also registered under:
<build><plugins>
it looks like:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<dependencies>
<dependency>
<groupId>com.puppycrawl.tools</groupId>
<artifactId>checkstyle</artifactId>
<version>6.1.1</version>
</dependency>
</dependencies>
<configuration>
<skip>true</skip>
....
</configuration>
<plugin>
Now after I added skip being true to both places and rebuilt the project modules, the errors were gone.
I’m using javancss maven plugin for measuring lines of codes and cyclomatic complexity.
I can not find the way of configuring the plugin in order to analyze test code as well.
This is a fragment of pom.xml file:
<reporting>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jxr-plugin</artifactId>
<version>2.5</version>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>javancss-maven-plugin</artifactId>
<version>2.1</version>
<configuration>
<includes>
<include>**/Exam.java</include>
<include>**/Topic.java</include>
<include>**/TopicSequenceTest.java</include>
<include>**/TestWithMockObjects.java</include>
</includes>
</configuration>
</plugin>
</plugins>
</reporting>
This is the project structure:
src
main
...
test
...
This is the way I use it:
mvn javadoc:javadoc javancss:report jxr:jxr jxr:test-jxr
I think it doesn’t work because ** is representing src/main, then it can not include any java file under src/test
But I cannot find the solution.
Thank you in advance
I am attempting to build a full site for my multi-module project in one command that I can execute in Jenkins. However when I build it, the submodule javadocs appear in the site root (site/apidocs instead of site/submodule/apidocs). All the links from the parent to submodule are broken as well.
Organization is the standard
pom.xml
submodule/pom.xml
Parent POM contains:
<build>
<pluginManagement>
<plugins>
... Various unrelated plugins ...
</plugins>
</pluginManagement>
</build>
<profiles>
<profile>
<id>complete-build</id>
<build>
<plugins>
<!--JavaDoc setup for Jars-->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.9.1</version>
<configuration>
<defaultAuthor>Leon Blakey</defaultAuthor>
<defaultVersion>${project.version}</defaultVersion>
<sourcepath>target/delombok</sourcepath>
</configuration>
</plugin>
<!--Deploy site with Mercurial (Hg)-->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-site-plugin</artifactId>
<version>3.3</version>
<dependencies>
<dependency><!-- add support for scm -->
<groupId>org.apache.maven.wagon</groupId>
<artifactId>wagon-scm</artifactId>
<version>2.4</version>
</dependency>
<dependency>
<groupId>org.apache.maven.scm</groupId>
<artifactId>maven-scm-provider-hg</artifactId>
<version>1.8.1</version>
</dependency>
</dependencies>
<configuration>
<reportPlugins>
<!--JavaDoc setup for Site-->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.9.1</version>
<configuration>
<defaultAuthor>Leon Blakey</defaultAuthor>
<defaultVersion>${project.version}</defaultVersion>
<sourcepath>target/delombok</sourcepath>
<show>public</show>
</configuration>
</plugin>
... Checkstyle, PMD, Findbugs, etc ...
</reportPlugins>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
The submodule POM just contains the skeleton plugin definitions for pluginManagement.
When I try to build a site (both on my local machine and Jenkins) I run from the parent
mvn clean install site-deploy -Pcomplete-build
With the above setup, what would cause a submodule to dump its site files in the site root (site/) instead of the submodule directory (site/submodule)? Do I need to use the stanging commands (which I'm avoiding since it breaks the release process)? Is it simply impossible to build a multi-module site in one command?
Use the maven-reactor-plugin to trigger building at the submodule level.