JavaDoc + + Eclipse + Maven + Checkstyle = ?

Posted on 2011-03-18
Last Modified: 2012-05-11
I am upgrading my project from using Checkstyle 4.4 to 5.3 and while I am at it, updating my packages to include for package annotation support. My project is built with Maven and am using M2Eclipse plugin for Eclipse. The suggested Maven project structure has my main java classes and test classes under different files but with the same package names.

Eclipse gives a compile error "The type package-info is already defined" if I add the to both main and test packages. And Checkstyle will complain if I do not have it in both.

What is the best practice here? I do not want to have to configure any special filters in my Eclipse build source, because we are relying on M2Eclipse to import the existing Maven projects out of the box. I do not want to disable the checkstyle rule because it needs to be checked. And I would rather not keep using the old 1.4 convention.
Question by:Uncle_J
  • 4
  • 3
LVL 92

Expert Comment

ID: 35170387
does checkstyle need to be accessing your test classes? would think you would only run it on your main classes
and why do you have a test class for package-info

Author Comment

ID: 35182260
Why would I not want our test classes to conform to the same coding style as production code? Also, I do not have a test class for package-info. Checkstyle does not seem to be aware that already exists, just under a different file path (maven convention). I cannot be the first person to have this question. I am assuming there is a common solution to this.
LVL 92

Expert Comment

ID: 35185133
>  if I add the to both main and test packages.

>  Also, I do not have a test class for package-info.

Am confused by these two. Do you have a copy of package-info in your test directory?

Author Comment

ID: 35190942
Here is the setup

src/main/java/com/domain/my/ ( package main)
src/test/java/com/domain/my/ ( package test)

both src/main/java and src/test/java are in the Eclipse build path, but with different output dirs for the compiled classes (target/classes and target/test-classes). Yet, Eclipse shows a compiler error if I have in both of these dirs. And if I dont have in both, Checkstyle complains that I am missing the in the one without. Its a catch 22.
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

LVL 92

Expert Comment

ID: 35194835
> Yet, Eclipse shows a compiler error if I have in both of these dirs.

which is expected, you can't have two classes with the same name and package

>  Checkstyle complains that I am missing the in the one without

Whats it complaining about exactly?

Author Comment

ID: 35199839
The Package Javadoc module for Checkstyle will complain "Missing file". I have attached an example project. Enable Checkstyle in Eclipse using the standard sun checks and notice the warning.
Note: change the classpath.txt and project.txt to .classpath and .project to import into eclipse.
LVL 35

Accepted Solution

mccarl earned 500 total points
ID: 35202704
It seems that the JavadocPackage check doesn't have any properties that will allow you to exclude the test packages, however, you should be able to setup the suppression filter to exclude those errors. (

I would say that your suppressions XML document would need to look something like this... (you may need to tweak the regexp in the 'files' attribute)

<?xml version="1.0"?>

<!DOCTYPE suppressions PUBLIC
    "-//Puppy Crawl//DTD Suppressions 1.1//EN"

    <suppress checks="JavadocPackage"

Open in new window


Author Closing Comment

ID: 35418020
That works. Thank you

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:

706 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now