We are working on some old java project. The code has many warnings but i want to avoid introducing new ones. is there a way to do it with maven, bamboo. we don't have rights to install new plugins on bamboo (corporation) so maven solution is preferred.
-
Related: http://stackoverflow.com/questions/5173455 – Tomasz Nurkiewicz Sep 30 '12 at 16:30
-
to be honest i can't find 'compiler warning' in 'metric' dropdown – piotrek Sep 30 '12 at 17:29
-
4you may be able to use the findbugs or checkstyle plugins and adjust the threshold to your current value, so the build fails if the value increases? – wemu Oct 02 '12 at 09:37
-
@wemu PMD could also be suggested... – sgpalit Oct 05 '12 at 14:11
-
jep! I just focused on findbugs as I use it in the IDE too so the reports show the same thing. But indeed PMD has handy stuff too! – wemu Oct 05 '12 at 14:51
4 Answers
Well, I agree there is no plugin that can do this but you can do this in simple steps with java 1.7.
Use processors at compile time to compile your code and maintain warnings generated in a log file. Every time you will trigger build this will kick off and you can compare old log file with new one.
Note: In jdk 1.6 and 1.5 you can use APT tool for the same.

- 523
- 2
- 13
If you are using eclipse, you can add an annotation (@IgnoreWarnings) to ignore the existing warnings. But you will have to modify the source everywhere there is a warning.
There is maybe a smarter solution using PMD (http://pmd.sourceforge.net/) and/or findbugs (http://findbugs.sourceforge.net/). There are available as plugins for a lot of environments.
You may also decide to fix every warnings you have in classes you modify. Of course, this implies that every developper is inclined to do it...

- 1,258
- 9
- 20
The important word here is "new" -
you are looking for new warnings in your build-log, regardless of their severity or origin.
For that you need to have a "snapshot" of the current set of warnings:
Take a copy of the output of a "good" build, with all its warnings.
After each new build (assuming it did not fail), compare the new log with the one saved -
any changes in the log mean you have a new warning.
Cheers

- 4,005
- 1
- 31
- 39
-
well, no. i can count all warnings i have right now. but still don't know how to fail build with maven when number of warnings is too high – piotrek Jan 03 '13 at 16:03
-
1Wrap it with a script that reads the number of warnings from the log and fails (return a non-zero value) if there are too many of those. – Gonen Jan 03 '13 at 17:41
You can use checkstyle task and after report generation finished you can extract number of warnings using xslt (if report is in xml, I believe other report formats available as well).
Then, using ant task you can compare number of warnings in current build vs. acceptablenumber of warnings (it could be either hardcoded number somewhere or taken from previous build artefacts if you want to be fancy)

- 6,970
- 10
- 42
- 65