Solved

JavaDoc + Package-info.java + Eclipse + Maven + Checkstyle = ?

Posted on 2011-03-18
8
3,584 Views
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 Package-info.java 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 Package-info.java 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.
0
Comment
Question by:Uncle_J
  • 4
  • 3
8 Comments
 
LVL 92

Expert Comment

by:objects
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
0
 

Author Comment

by:Uncle_J
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 package-info.java 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.
0
 
LVL 92

Expert Comment

by:objects
ID: 35185133
>  if I add the Package-info.java 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?
0
Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

 

Author Comment

by:Uncle_J
ID: 35190942
Here is the setup

src/main/java/com/domain/my/ (com.domain.my package main)
...
src/test/java/com/domain/my/ (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 package-info.java in both of these dirs. And if I dont have in both, Checkstyle complains that I am missing the package-info.java in the one without. Its a catch 22.
0
 
LVL 92

Expert Comment

by:objects
ID: 35194835
> Yet, Eclipse shows a compiler error if I have package-info.java 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 package-info.java in the one without

Whats it complaining about exactly?
0
 

Author Comment

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

Accepted Solution

by:
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. (http://checkstyle.sourceforge.net/config.html#SuppressionFilter

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"
    "http://www.puppycrawl.com/dtds/suppressions_1_1.dtd">

<suppressions>
    <suppress checks="JavadocPackage"
              files="src/test/java"/>
</suppressions>

Open in new window

0
 

Author Closing Comment

by:Uncle_J
ID: 35418020
That works. Thank you
0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
starter POM and spring-boot-starter,  spring-boot-web 2 54
Java - Why doesn't this JFrame work 3 59
Way to decrease size of apk file 9 66
runtime exception 2 28
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

776 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