Test your Dependencies with Degraph

I wrote before about (anti)patterns in package dependencies. And of course the regular reader of my blog knows about Degraph, my private project to provide a visualization for package dependencies which can help a lot when you try to identify and fix such antipatterns.

But instead of fixing a problem we all probably prefer preventing the problem in the first place. Therefore in the latest version Degraph got a new feature: A DSL for testing Dependencies.

You can write tests either in Scala or in Java, whatever fits better into your project.

A typical test written with ScalaTest looks like this:

  1. classpath // analyze everything found in the current classpath
  2. .including("de.schauderhaft.**") // only the classes that start with "de.schauderhaft."
  3. .withSlicing("module", "de.schauderhaft.(*).**") // use the third part of the package name as the module name, and make sure the modules don't have cycles
  4. .withSlicing("layer",
  5. ("persistence","de.schauderhaft.legacy.db.**"), // consider everything in the package de.schauderhaft.legacy.db and subpackages as part of the layer "persistence"
  6. "de.schauderhaft.*.(*).**") // for everything else use the fourth part of the package name as the name of the layer
  7. ) should be(violationFree) // check for violations (i.e. dependency circles)

The equivalent test code in Java and JUnit looks like this:

  1. assertThat(
  2. classpath() // analyze everything found in the current classpath
  3. .including("de.schauderhaft.**") // only the classes that start with "de.schauderhaft."
  4. .withSlicing("module", "de.schauderhaft.(*).**") // use the third part of the package name as the module name, and make sure the modules don't have cycles
  5. .withSlicing("layer",
  6. new NamedPattern("persistence","de.schauderhaft.legacy.db.**"), // consider everything in the package de.schauderhaft.legacy.db and subpackages as part of the layer "persistence"
  7. "de.schauderhaft.*.(*).**") // for everything else use the fourth part of the package name as the name of the layer
  8. ),
  9. is(violationFree())
  10. );

You can also constrain the ways different slices depend on each other. For example

  1. .withSlicing("module", "de.schauderhaft.(*).**").allow(oneOf("order", "reporting"), "customer", "core")


  • stuff in de.schauderhaft.order may depend on de.schauderhaft.customer and de.schauderhaft.core
  • the same is true for de.schauderhaft.reporting
  • de.schauderhaft.customer may depend on de.schauderhaft.core
  • all other dependencies between those packages are disallowed
  • packages from and to other packages are allowed

If you also want to allow dependencies between the order slice and the reporting slice replace oneOf with anyOf.

If you want to disallow dependencies from reporting or order to core you can replace allow with allowDirect.

See the official documentation for more details, especially all the options the DSL offers, the imports needed and how to set up Degraph for testing.

I’m trying to get Degraph into maven central to make usage inside projects easier.
I also have some changes to the testing DSL on my to-do list. And finally I’m working on a HTML5 based front end. So stay tuned.

And as always: Feedback including feature requests and pull requests is welcome.

I Don’t Give A Damn About Your Standard

When I get into a discussion about what library to use, or what tool to use, some people bring up the argument:

But it is the standard!

You know what? You can put your standard where the sun doesn’t shine!

Don’t get me wrong, some standards are awesome. I have boxes of hex cap screws. And boxes of nuts. And three different sets of wrenches. And I have never a problem of finding a matching triplet. Except once when I had a screw that wasn’t shaped according to the metric system. A PITA. The metric system and the norms for screws are so awesome because everybody adheres to them (at least where I live). And everybody adheres to them within reasonable precision. Of course if you measure exact enough, you will find out that certain pairs of screw and nut fit better than others. But I don’t care as long as I can put the nut on the screw and use it for fixing whatever needs fixing. And the final reason: I need lots of screws and nuts. If I ever only need one screw with a matching nut, I’d just get a matching pair and couldn’t care less if I find ever a matching nut again.

Unfortunately software standards often aren’t like that. For various reasons:

  1. They aren’t precise enough. I don’t care if two webspheres adhere to some JSR xxx or not. What I do care is: Does my web application work on that websphere. And if “that webserver” happens to be a different one, then the one I use in development, chances are, it won’t. That’s because basically there is next to zero tolerance in software. It’s not so much that software has to be perfect, or better than hardware. It’s more that with hardware it is often easier to determine what the properties are that matter, and what doesn’t matter.
  2. I’m not going to mix 5 different Dependency Injection Containers from 5 different vendors. I’m going to use one. The 10th production server will have the exact same version of the exact same DI Container as the first 9, or somebody will have to do a lot explaining. The basic use case for standards just isn’t there.
  3. The standard is not what some committee says, but what everybody uses. So, it is nice that Java Utils Logging is the official standard for logging in the Javaverse, but if you want to use stuff that everybody knows, you better use log4j or slf4j. By the way this one is true for ‘real world’ standards as well.

So when we talk about libraries and tools the questions are:

  1. Does it solve the problem?
  2. Can the developers use it?
  3. Does it work with the rest of the stack?
  4. Can operations support it?

And the answer to “is it a standard?” is “Go away!”

Scaling Agile Beyond Your Project- What Can We Do?

In the projects I’m involved in we put a lot of energy into becoming agile. This is often a tough fight because I work in an environment that is as anti agile as you can get. Just to give you a glimps at the mindset: They are proud of having the largest websphere installation in Europe. Anyway, we typically make some progress: Tearing down walls between developers and testers. Replacing multi year project plans with a living back log, people talking with each other instead of about each other. This kind of thing.

But for me as a developer there seems to be a wall around our team. Behind this wall the management dragons roam. Sometimes balls of flame fly over the wall in our direction, setting our little project on fire, by dictating rules that just don’t make sense, and we can do nothing but putting out the flames, or can we? I think we might.

One thing to realize is: Most of these dragons aren’t dragons at all. They don’t want to damage the project. Instead they actually want the project to succeed. But the wall is real. It’s not made of stone though, although the physical walls between your desk and the desk of some manager might add to it. There real stuff this wall is made of, is lack of understanding and lack of communication.

Of course, as usual it is easy to blame it on the other guys. The managers have all the power they need to talk to you, right? They are calling the shots so if they really want to they can drop by your place any time. But managers are pretty busy people. What will they get from talking to you?

Let’s do a thought experiment: Imagine the boss of the boss of the highest level manager you normally talk to walks into your office and asks you to tell him whatever you think he needs to know. What would you reply? My expectation is that most of us (including myself) would tell him about why the last brain dead management decision was a brain dead management decision.

Now put yourself in his shoes: You go to somebody with a completely different skill set than you and ask for input and you get a “You are stupid and don’t understand your job” How high would you estimate the chances of this changing your decision or the way you make decisions?

Probably not very high. Maybe at about 0%, maybe a little lower.

If you want a manager to listen to you, you have understand what he wants and needs. And you also have to demonstrate, that you understand. If you understand the reasons for the last “brain dead” management decisions you can start asking questions about these reasons and thus learn that they might be legit or surface that they weren’t. In both cases you made tremendous progress.

And the key is to ask questions. Which is basically applying the agile manifesto:

Individuals and interactions over processes and tools

Don’t bitch about the processes and tools, try to understand the individuals and their challenges behind them. If you manage to get into a discussion, than you can start to change things, and maybe earn enough trust, that your input will be heard before the next decision.

Of course the same applies not only to managers up the chain of command, but also teams in different silos. Don’t tell them how to do their job. Learn to understand why they are doing it the way they do.

And in case you are wondering: Yes I wrote this post in part in order to train myself to take my own advice.

Softwaredevelopment, Learning, Qualitymanagement and all things "schauderhaft"