Issue with Checkstyle Maven plugin

1,658 views
Skip to first unread message

Daniil Yaroslavtsev

unread,
Nov 26, 2014, 10:18:05 AM11/26/14
to checksty...@googlegroups.com
I have created the simple project for testing checkstyle on sources: https://github.com/daniilyar/checkstyle-tester

But I have noticed a problem with it.

My project launches Checkstyle Maven plugin's 'checkstyle-aggregate' goal (http://maven.apache.org/plugins/maven-checkstyle-plugin/checkstyle-aggregate-mojo.html) which should generate html report.
But it does not generate html report and generates xml report instead.

Steps to reproduce:

git clone g...@github.com:daniilyar/checkstyle-tester.git
cd checkstyle-tester
./launch.sh

Expected: Checkstyle html report should appear in target folder
Actual: Checkstyle xml report apears in 'target' folder.

If nobody could explain that, I'll create an issue over Checkstyle Maven plugin.

Roman Ivanov

unread,
Nov 29, 2014, 12:53:05 AM11/29/14
to checksty...@googlegroups.com
Hi Daniil,

I do not see how you insert maven-checkstyle-plugin information(in build and reporting tags) in tested project ?
you even do not embrace all your projects as modules to our pom.xml to do it only ones.

why you expect that html report should be generated ?
send me links to lines in your pom.xml or launch.sh that do that.

thanks,
Roman Ivanov

Daniil Yaroslavtsev

unread,
Nov 30, 2014, 3:53:20 PM11/30/14
to checksty...@googlegroups.com
I am trying to introduce semi-automated checkstyle checker which would allow us to build html reports on projects without editing their pom files manualy each by each.
I am doing this in order to:
- improve and automate process of checking if Checkstyle version X.Y.Z (or just a specific check) works properly on exemplar huge opensource projects. I think even about adding such a check as part of our Travis build or etc in future.
- let any team having git repo on which Checkstyle fails for any reason provide us a prove link in a maximum simple manner. In ideal case anybody will be able to just put erroneous source to github, fork checkstyle-tester project and send us a link to it for farther investigation.

So I've written the script (launch.sh) which clones several projects with git into src/main/java folder and launches checkstyle-aggregate goal with fake pom file including expected Checkstyle and Sevntu-checkstyle versions as dependencies. Here is how I configure maven-checkstyle plugin in that pom file: https://github.com/daniilyar/checkstyle-tester/blob/master/pom.xml#L18 (see line 18).


> why you expect that html report should be generated ?
I am running goal checkstyle-aggregate (see line 36 at https://github.com/daniilyar/checkstyle-tester/blob/master/launch.sh#L36) which, by goal docs, should generate an html report.

Here is how I am running it:

./launch.sh -X

where -X parameter goes to Maven parameters list. Example launch debug log is below:

[DEBUG] Configuring mojo 'org.apache.maven.plugins:maven-checkstyle-plugin:2.13:checkstyle-aggregate' with basic configurator -->
[DEBUG]   (f) cacheFile = /home/dyaroslavtsev/Desktop/Code/checkstyle-tester/target/checkstyle-cachefile
[DEBUG]   (f) configLocation = google_checks.xml
[DEBUG]   (f) consoleOutput = false
[DEBUG]   (f) enableFilesSummary = true
[DEBUG]   (f) enableRSS = true
[DEBUG]   (f) enableRulesSummary = true
[DEBUG]   (f) enableSeveritySummary = true
[DEBUG]   (f) encoding = UTF-8
[DEBUG]   (f) failsOnError = false
[DEBUG]   (f) headerLocation = LICENSE.txt
[DEBUG]   (f) includeResources = true
[DEBUG]   (f) includeTestResources = true
[DEBUG]   (f) includeTestSourceDirectory = false
[DEBUG]   (f) includes = **\/*.java
[DEBUG]   (f) inputEncoding = UTF-8
[DEBUG]   (f) linkXRef = true
[DEBUG]   (f) mojoExecution = org.apache.maven.plugins:maven-checkstyle-plugin:2.13:checkstyle-aggregate {execution: default-cli}
[DEBUG]   (f) outputDirectory = /home/dyaroslavtsev/Desktop/Code/checkstyle-tester/target/site
[DEBUG]   (f) outputFile = /home/dyaroslavtsev/Desktop/Code/checkstyle-tester/target/checkstyle-result.xml
[DEBUG]   (f) outputFileFormat = xml
[DEBUG]   (f) plugin = Component Descriptor: role: 'org.apache.maven.plugin.Mojo', implementation: 'org.apache.maven.plugin.checkstyle.CheckstyleReport', role hint: 'org.apache.maven.plugins:maven-checkstyle-plugin:2.13:checkstyle'
role: 'org.apache.maven.plugin.Mojo', implementation: 'org.apache.maven.plugin.checkstyle.CheckstyleViolationCheckMojo', role hint: 'org.apache.maven.plugins:maven-checkstyle-plugin:2.13:check'
role: 'org.apache.maven.plugin.Mojo', implementation: 'org.apache.maven.plugin.checkstyle.CheckstyleAggregateReport', role hint: 'org.apache.maven.plugins:maven-checkstyle-plugin:2.13:checkstyle-aggregate'
role: 'org.apache.maven.plugin.Mojo', implementation: 'org.apache.maven.plugin.checkstyle.HelpMojo', role hint: 'org.apache.maven.plugins:maven-checkstyle-plugin:2.13:help'
---
[DEBUG]   (f) project = MavenProject: com.github.sevntu.checkstyle:sample:0.0.1-SNAPSHOT @ /home/dyaroslavtsev/Desktop/Code/checkstyle-tester/pom.xml
[DEBUG]   (f) reactorProjects = [MavenProject: com.github.sevntu.checkstyle:sample:0.0.1-SNAPSHOT @ /home/dyaroslavtsev/Desktop/Code/checkstyle-tester/pom.xml]
[DEBUG]   (f) resourceIncludes = **/*.properties
[DEBUG]   (f) resources = [Resource {targetPath: null, filtering: false, FileSet {directory: /home/dyaroslavtsev/Desktop/Code/checkstyle-tester/src/main/resources, PatternSet [includes: {}, excludes: {}]}}]
[DEBUG]   (f) skip = false
[DEBUG]   (f) sourceDirectories = [/home/dyaroslavtsev/Desktop/Code/checkstyle-tester/src/main/java]
[DEBUG]   (f) suppressionsFileExpression = checkstyle.suppressions.file
[DEBUG]   (f) testResources = [Resource {targetPath: null, filtering: false, FileSet {directory: /home/dyaroslavtsev/Desktop/Code/checkstyle-tester/src/test/resources, PatternSet [includes: {}, excludes: {}]}}]
[DEBUG]   (f) testSourceDirectories = [/home/dyaroslavtsev/Desktop/Code/checkstyle-tester/src/test/java]
[DEBUG]   (f) xrefLocation = /home/dyaroslavtsev/Desktop/Code/checkstyle-tester/target/site/xref
[DEBUG] -- end configuration --

For some weird reason xml report is generated no matter that 'checkstyle-aggregate' goal docs says that it is a goal for generating HTML report.
Xml is not html so I am searching for truth and it seems that Maven Checkstyle Plugin docs are wrong and all goals at Maven Checkstyle Plugin could only produce XML reports.

Daniil Yaroslavtsev

unread,
Nov 30, 2014, 4:05:08 PM11/30/14
to checksty...@googlegroups.com
I am trying to make things work with checkstyle:checkstyle-aggregate goal because checkstyle:checkstyle goal has the same problem and also because I've found that checkstyle:checkstyle-aggregate goal checks sources properly no matter if I add subfolders in src/main/java as modules, or not. The only problem that both checkstyle:checkstyle and checkstyle:checkstyle-aggregate goals does not generate HTML report while both them in my case generates valid XML report.

If I to update my launch script to launch checkstyle:checkstyle goal instead of checkstyle:checkstyle-aggregate it generates xml report, too, no matter that docs for checkstyle:checkstyle MOJO (http://maven.apache.org/plugins/maven-checkstyle-plugin/checkstyle-mojo.html) says that is generates HTML report.


Daniil Yaroslavtsev

unread,
Nov 30, 2014, 4:37:33 PM11/30/14
to checksty...@googlegroups.com
If I specify checkstyle.output.format=html option, e.g.:

./launch.sh -X -Dcheckstyle.output.format=html

Maven build fails with:

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-checkstyle-plugin:2.13:checkstyle (default-cli) on project sample: An error has occurred in Checkstyle report generation. Invalid output file format: (html). Must be 'plain' or 'xml'. -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.apache.maven.plugins:maven-checkstyle-plugin:2.13:checkstyle (default-cli) on project sample: An error has occurred in Checkstyle report generation.
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:216)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:116)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:80)
    at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:51)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:120)
    at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:347)
    at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:154)
    at org.apache.maven.cli.MavenCli.execute(MavenCli.java:584)
    at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:213)
    at org.apache.maven.cli.MavenCli.main(MavenCli.java:157)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)
Caused by: org.apache.maven.plugin.MojoExecutionException: An error has occurred in Checkstyle report generation.
    at org.apache.maven.reporting.AbstractMavenReport.execute(AbstractMavenReport.java:171)
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:132)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:208)
    ... 19 more
Caused by: org.apache.maven.reporting.MavenReportException: Invalid output file format: (html). Must be 'plain' or 'xml'.
    at org.apache.maven.plugin.checkstyle.AbstractCheckstyleReport.getListener(AbstractCheckstyleReport.java:581)
    at org.apache.maven.plugin.checkstyle.CheckstyleReport.createRequest(CheckstyleReport.java:167)
    at org.apache.maven.plugin.checkstyle.AbstractCheckstyleReport.executeReport(AbstractCheckstyleReport.java:474)
    at org.apache.maven.plugin.checkstyle.CheckstyleReport.executeReport(CheckstyleReport.java:157)
    at org.apache.maven.reporting.AbstractMavenReport.generate(AbstractMavenReport.java:255)
    at org.apache.maven.reporting.AbstractMavenReport.execute(AbstractMavenReport.java:143)
    ... 21 more

So looks like this is just an ugly mistake in maven Checkstyle plugin documentation.

I think that we should also review our Maven sample. I am using udentical pom as in our Maven sample (https://github.com/sevntu-checkstyle/checkstyle-samples/blob/master/maven-project/pom.xml) but it does not work so I think that

Daniil Yaroslavtsev

unread,
Nov 30, 2014, 4:47:46 PM11/30/14
to checksty...@googlegroups.com
After I dropped my .m2 folder and removed 'failOnViolation=false' property from my fake pom it started to generate HTML reports.

But it generates reports with non-clickable line numbers so I cannot use it conveniently for reviews (see example report for sevntu-checkstyle attached).

Roman, could you, please, suggest me how could I configure Maven Checkstyle plugin's checkstyle:checkstyle goal to create html report with clickable line numbers?
E.g. if user clicks at line number, piece of erroneous code appears on the screen opened at the proper line.

Currently, I can see only error counts in my checkstyle:checkstyle reports and in that reports I am not able to navigate into the code containing warning.
site.zip

Daniil Yaroslavtsev

unread,
Dec 2, 2014, 1:28:53 AM12/2/14
to checksty...@googlegroups.com
Ok, I found an answer here: http://roman-ivanov.blogspot.com/2014/10/how-to-use-snapshot-checkstyle-version.html. maven-jxr-plugin should solve my problem.

Roman Ivanov

unread,
Dec 4, 2014, 12:29:59 AM12/4/14
to Daniil Yaroslavtsev, checksty...@googlegroups.com
Hi Daniil,

I already see reports that are done my your tool, there are two problems:
- violations are combined , is not convenient as projects have different level of trust
- we need to find way to make a suppression , see reports for hibernate, non all files are compilable.

For now I do not know how to make that reports without using only maven projects.
I still think that if we should go in following way:
- use stable version of testing projects
- spit projects to maven and groovy projects
- update pom.xml by xls , update groovy project (I do not know how, but believe it is possible, but here smth)
- combine reports by copying in same folder, it is ok to keep two html files to my mind.

thanks,
Roman Ivanov
Reply all
Reply to author
Forward
0 new messages