David M. Karr
David M. Karr

Reputation: 15225

Maven Checkstyle and Eclipse Checkstyle report similar but different results using the same config file

I have an Eclipse plugin codebase that builds with Tycho. It uses a parent POM defined in a dependent artifact that specifies the name of the Checkstyle configuration.

I've also checked out the parent pom with the checkstyle config. I've configured Eclipse to use the same config file as the Maven build.

I'm finding that the Maven report lists one other violation that the Eclipse report doesn't mention.

In the particular Java source file I'm looking at, the Maven report produces this list:

3: warning: Empty line should be followed by <p> tag on the next line.
8: warning: 'package' should be separated from previous statement.
26: warning: First sentence should be present.
31: warning: First sentence should be present.
34: warning: First sentence should be present.
48: warning: First sentence should be present.

For the same source file, using the same Checkstyle config file, Eclipse reports all but the first warning.

If it matters, here is the first few lines of the file, including line 3:

/*******************************************************************************
 * Copyright (c) 2014, 2015 Cisco Systems, Inc. and others.  All rights reserved.
 * // line 3
 * This program and the accompanying materials are made available under the
 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
 * and is available at http://www.eclipse.org/legal/epl-v10.html
 *******************************************************************************/

Ironically, I can't "fix" this warning, because our project currently specifies a specific format for the license file, and adding the "p" on the next line violates that format.

In any case, my issue is not fixing the warning, it's understanding why Eclipse and Maven are differing in what violations they're reporting, using the same Checkstyle config file.

From what I understand, the category associated with this violation is "JavadocParagraph". My Checkstyle config file includes this category, but it does not override the "allowNewlineParagraph" property. Supposedly, the default value for this property is true. That means to me that Maven is somehow deciding that this property is set to "false", but Eclpse still sees the default unspecified value of "true".

Upvotes: 4

Views: 595

Answers (1)

barfuin
barfuin

Reputation: 17474

It seems you have run into a version conflict. The Maven Checkstyle Plugin 2.16 is based on Checkstyle 6.2, whereas your Eclipse plugin is the latest, using Checkstyle 6.16.1 (source).

There have been some changes to the JavadocParagraph check (such as this one in 6.2), which would be present in the Eclipse plugin, but not in the Maven version.

So, you have 3 options to resolve this:

  1. Upgrade the Maven plugin to 2.17 - This seems to be the easiest, but you will still be on different versions so you may run into other problems in the future.
  2. Downgrade the Eclipse plugin to a version 6.2.x - this would work, but leave you with a rather old version of Checkstyle.
  3. Specify the Checkstyle version explicitly (recommended). So you would keep using the newest Checkstyle plugin for Eclipse, but configure Maven to use the same version of Checkstyle (instructions).

Upvotes: 2

Related Questions