How to run maven checkstyle plugin on incremental code only - maven

I want to add auto code review feature to our application. Currently we use maven to do builds. I came across maven checkstyle plugin but want this to run it only on incremental code that gets added and not on older one.
Can i achieve this using this plugin? If yes then please provide pointers on how to do it?

Checkstyle plugin has no idea what files are modified or new.
The only way of incrementally adding checkstyle to a project would be using includes configuration, manually putting new files/packages etc. It's a comma separated list of patterns.
<executions>
<execution>
<id>checkstyle-verify</id>
<phase>verify</phase>
<goals>
<goal>check</goal>
</goals>
<configuration>
<includes>NewClass.java,AnotherClass.java</includes>
</configuration>
</execution>
</executions>

Related

Can Sonar Scan be triggered as part of regular maven Build command like " mvn build"?

Im looking to see any maven configuration which will enable me to run Sonar Scan on my code for every maven build. I dont want to use a separate goal but somehow enforce it as part of users regular build commands.
You can attach Sonar to a phase (e.g. verify) like this:
<plugin>
<groupId>org.sonarsource.scanner.maven</groupId>
<artifactId>sonar-maven-plugin</artifactId>
<version>3.5.0.1254</version>
<executions>
<execution>
<id>verify-sonar</id>
<phase>verify</phase>
<goals>
<goal>sonar</goal>
</goals>
</execution>
</executions>
</plugin>
This also works with other phases like compile or package.

Are directions available for the maven plugin com.alexnederlof jasperreports-plugin?

I have read up on the limited information regarding com.alexnederlof jasperreports-plugin and I'm looking to convert my current ant build to use this maven plugin, but there doesn't seem to be any documentation available.
My biggest concern is run-time: If I use this plugin at build-time, what version of jasper-reports do I need to use at run-time?
Am I missing a reference somewhere? As the old adage goes, "If there isn't any documentation, then I guess I'll have to write it."
I am not sure of what you are after but, I am using this plugin in maven to generate the source .jrxml files to .jasper files and the configuration in pom goes like this:
<plugin>
<groupId>com.alexnederlof</groupId>
<artifactId>jasperreports-plugin</artifactId>
<version>2.3</version>
<executions>
<execution>
<phase>process-sources</phase>
<goals>
<goal>jasper</goal>
</goals>
</execution>
</executions>
<configuration>
<!-- These are the default configurations: -->
<compiler>net.sf.jasperreports.engine.design.JRJdtCompiler</compiler>
<sourceDirectory>src/main/jasperreports</sourceDirectory>
<outputDirectory>${basedir}/src/main/webapp</outputDirectory>
<outputFileExt>.jasper</outputFileExt>
<xmlValidation>true</xmlValidation>
<verbose>false</verbose>
<numberOfThreads>4</numberOfThreads>
<failOnMissingSourceDirectory>true</failOnMissingSourceDirectory>
<sourceScanner>
org.codehaus.plexus.compiler.util.scan.StaleSourceScanner
</sourceScanner>
</configuration>
</plugin>
Hope this helps

How do I know what are different goals available for plug-in in maven?

I recently started using maven. so this question might sound basic.
This question came up when I was browsing through some code using cargo plug-in.
In the following snippet of maven plugin in pom.xml, that i extracted from here,
my understanding is as follows:
<plugin>
<groupId>org.codehaus.cargo</groupId>
<artifactId>cargo-maven2-plugin</artifactId>
<executions>
<execution>
<id>start-container</id>
<phase>pre-integration-test</phase>
<goals>
<goal>start</goal>
</goals>
</execution>
<execution>
<id>stop-container</id>
<phase>post-integration-test</phase>
<goals>
<goal>stop</goal>
</goals>
</execution>
</executions>
<configuration>
[Cargo plugin configuration goes in here]
</configuration>
</plugin>
This plug in bound to pre-integration-test and post-integration-test phase of build LifeCycle, which also means when I run mvn install this will be executed.
The goals (start and stop) of this plug-in gets executed during these phases respectively
Q1:: Does the <id>start-container</id> has any relevance? what's its purpose & importance?
Q2:: How do I know what are the different goals available for a plug-in. In this case for cargo plug-in I see in one of the codes in my work, <goal>redeploy</goal> is used. so I am wondering how to find information on these specific goals and other goals available. I did look at online documentation. I did not find any. possible that I did not search in the right place.
A1: the id doesn't change how the execution works, it's just a way of giving it a name.
A2: The best way is to read the documentation. Maven3 is also considerably better than maven2 in this aspect. If you call a plugin with an invalid goal, it will print out all the valid goals, but it won't print what are the different parameters that can be passed to the plugin (and some plugins use different parameter names for command line and pom parameters)
The documentation of cargo is a bit odd, most other plugins have their documentation set up in a different way, which makes it easier to find the goals and the parameters that can be set.
By the way, both your points 1 and 2 are correct.

Using CodeNarc with Maven

I am trying to integrate CodeNarc with a Maven-based Groovy project. The documentation on the site for the CodeNarc Maven plugin is minimal. The usage aspects I am trying to understand are:
How to point to the custom rule sets and where in the project to place them?
How to fail the Jenkins build if any of the rules are violated.
Currently I am able to run CodeNarc using command
mvn codenarc:codenarc
When I add the 'reporting' section to the POM file (as described at http://www.mojohaus.org/codenarc-maven-plugin/usage.html) and run
mvn site
no CodeNarc report is generated. I get this warning
[WARNING] No URL defined for the project - decoration links will not
be resolved
but it is not clear where it is related to CodeNarc.
What is the proper way of using CodeNarc with Maven?
I just did it, in case you still need the tip. You can hook the execution of the plugin by creating a "plugin" entry under "build"->"plugins"->"plugin". Here is what I have.
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>codenarc-maven-plugin</artifactId>
<version>0.18-1</version>
<configuration>
<sourceDirectory>${project.basedir}/src/main/groovy</sourceDirectory>
<maxPriority1Violations>0</maxPriority1Violations>
<maxPriority2Violations>0</maxPriority2Violations>
<maxPriority3Violations>0</maxPriority3Violations>
</configuration>
<executions>
<execution>
<phase>prepare-package</phase>
<goals>
<goal>codenarc</goal>
</goals>
</execution>
</executions>
</plugin>
...
</plugins>
</build>
Note the "maxPriority_Violations" values. This is what makes the build fail in case of violations.
I dont use any custom rules, but it seems you can define your own rules by setting the "rulesetfiles" configuration option. See configuration options here: http://www.mojohaus.org/codenarc-maven-plugin/codenarc-mojo.html
Example of project with this configuration: https://github.com/tveronezi/faceid/tree/master/faceid-web

Deploy additional jars to repo using maven-release-plugin

I'm using zi and maven-release-plugin to generate jar files which I'm attempting to submit to the maven central repo. One of the requirements for inclusion in the central repo is that the artifact have a -javadoc.jar file that contains the generated javadocs. If that's not possible they require that you have an empty -javadoc.jar file in order to pass the automated tests.
I'm generating the empty jar file using exec-maven-plugin and I'm placing it in the correct location, but it's being ignored by maven-release-plugin. As a result it's not being signed by my GPG key and it's not being deployed to the repo.
Is it possible to generate an empty javadoc jar file using the javadoc plugin?
If the javadoc plugin won't generate an empty jar file how do I get the maven-release-plugin to recognize, sign and deploy the jar file which is being generated by my shell script?
Is there some other option that I'm overlooking?
You should try to add the jar-source via the build-helper-maven-plugin which can be used attach artifacts to the cycles.
are you using clojure to write a maven plugin or creating a project written in Clojure?
clojure-maven is a tool for writing maven plugins using clojure:
Maven components to allow the use of clojure when writing maven plugins.
If you are creating a project in Clojure, the zi plugin which was designed for creating clojure projects that are compatible with central, may be what you are after. It's written by the same author (Hugo Duncan).
So I figured it out. Instead of creating the empty jar file via the shell script directly you need to create target/apidocs using the exec-maven-plugin plugin as part of the compile phase.
<plugin>
<artifactId>exec-maven-plugin</artifactId>
<groupId>org.codehaus.mojo</groupId>
<executions>
<execution>
<id>Generate Empty Javadoc</id>
<phase>compile</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<executable>${basedir}/scripts/emtpy-apidocs.sh</executable>
<arguments>
<argument>${project.build.directory}/apidocs</argument>
</arguments>
</configuration>
</execution>
</executions>
</plugin>
Then during package phase you use the javadoc plugin to create the jar. The resulting jar will now be picked up by the release plugin.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.8.1</version>
<executions>
<execution>
<id>attach-javadocs</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>

Resources