Tuesday, September 16, 2014

deadcode4j v2.0.0 released

deadcode4j v2.0.0 is out! It is available via Maven central, so it is conveniently available for your Maven project.

What's new?

Although version 2.0.0 adds only a few frameworks to its feature list, e.g. Jetty XML configuration and Spring Data custom repositories, changes "under the hood" were massive and allowed to eliminate two of the most common reasons for false positives: type erasure and constants inlining. Additionally, the custom analyzers are now much more powerful: they now recognize transitive implementation of an interface or a superclass. To keep configuration slick, unnecessary configuration (like ignoring classes that don't even exist) is recognized by deadcode4j and is requested to be removed from the configuration.
All changes are listed in the change log.

Major Release: Usage Statistics

The major release is due to two changes: the deprecated goal find-without-packaging was removed; but most importantly, deadcode4j now requests your permission to send some usage statistics. Those usage statistics will help me understand usage scenarios, project sizes, configuration usage etc. - allowing to improve deadcode4j furthermore. Sending statistics is completely transparent; it is optional and can be skipped permanently or on a per-usage basis.
Do you have an opinion on usage statistics? Do you find it invasive, or do you appreciate my intentions to improve by gathering feedback?

How to use

It's so simple: go to the console, navigate to your Maven project, type
  mvn de.is24.mavenplugins:deadcode4j-maven-plugin:find ‑Dmaven.test.skip=true
and see what it finds.

Hop on over to GitHub to learn more, browse the code, or contribute.

Looking for reference projects & users

Currently I'm using the big legacy application of my employer as a reference project. But I'm slowly running out of false positives, so my feature list is shrinking. That's why I'd love to analyze some more projects to get more feedback. So, if you know of an (open source) candidate I can analyze or if you are using deadcode4j for yourself and want something added or you have some nice ideas, please comment!

Here you can read how it all started.

Friday, September 12, 2014

Coveralls for Java, Travis & the Maven Invoker

The other day, a colleague of mine integrated deadcode4j with Coveralls.
I had looked at Coveralls before, but seeing it did not support Java, I quickly turned away. Fortunately, my colleague knew of a neat Maven Plugin that does the job: it simply sends a JaCoCo (or Cobertura or Saga) coverage report to Coveralls using their API.

Integration was pretty easy. Then again, I noticed some missing paths and worse coverage than on my local machine. It took me a considerable amount of time to track down the problem; also, I found no place describing the issue (let alone a solution). In case you have some issues with Maven running on Travis, you might want to read on.

Missing Coverage

To record the code coverage, I actually executed unit tests, integration tests and (as deadcode4j is a Maven Plugin) the Invoker Plugin. By comparing the coverage reported on Coveralls with my local results, I could narrow down my problems to the Invoker Plugin: coverage results from the invoker execution were not showing up at Coveralls. After endless trickery with the travis.yml file, I finally stumbled over the problem: Travis exports a MAVEN_OPTS variable just before Maven is executed (by the usage of /etc/mavenrc), thus effectively preventing it from being overwritten. As this is how the JaCoCo Maven Plugin records the Invoker's code coverage, it just couldn't enable code coverage for the Invoker.

Solution

There are two approaches to work around that issue, all coming down to adding something to your travis.yml file:

The sledgehammer method would be to remove the /etc/mavenrc file:

  before_install: sudo rm /etc/mavenrc

If you refrain from using sudo, you may skip the execution of /etc/mavenrc (note however, that this approach also skips the execution of ~/.mavenrc:

  before_install: export MAVEN_SKIP_RC=true

That's about it. Enjoy running your tests! ;)

About deadcode4j

deadcode4j is a Maven plugin which finds dead code. To use it, go to the console, navigate to your Maven project, type
  mvn de.is24.mavenplugins:deadcode4j-maven-plugin:find ‑Dmaven.test.skip=true
and see what it finds.

Hop on over to GitHub to learn more, browse the code, or contribute.

Here you can read how it all started.