0

I have a complex Java project that ultimately boils down to 3 major packages:

com.myapp.client --> client-side classes
com.myapp.shared --> client- and server-side utility classes
com.myapp.server --> server-side classes

I would like to write an Ant task that checks that no com.myapp.client classes show up as dependencies for com.myapp.server classes, and vice versa. I call this concept "drawbridging", because you're putting up a drawbridge between client and server code. The Ant task would fail the build if such violating dependencies are found.

For the life of me I can't figure out how to do this. Preferably, something already exists out there, however Google didn't turn back anything.

Short of an existing open source solution, my next guess would be to loop through all the client classes and check their imports for server classes; however according to this SO question the Java compiler throws away import references at compile-time.

So, I'm at a loss here. Any ideas? Thanks in advance!

Community
  • 1
  • 1
  • 1
    why not simply split them into three projects with the shared one being a dependency of both? – Brian Roach Jun 19 '13 at 16:46
  • Thanks @BrianRoach I should have put that in my original post - this isn't an option for reasons outside the scope of this question... –  Jun 19 '13 at 16:47

2 Answers2

0

As Java bytecode references to classes by their fully qualified names it should be quite feasible (but not easy), using a library like BCEL or ASM.

However, I think this question has a pretty distinctive X-Y ring to it, meaning that you're trying to solve a problem that is actually a symptom of the root cause you should be solving, in this case probably by properly compartmentalizing your code just as Brian Roach already suggested.

fvu
  • 32,488
  • 6
  • 61
  • 79
0

AntContrib VerifyDesign is exactly what I was looking for. Thanks me!