Gradle, AspectJ and non-transitive project dependencies

To set up a multi-project build such that the output of one project is on the inPath of another, do this in the build file of the dependant project:

  2. apply plugin: ‘aspectj’
  4. dependencies {
  5.         ajInpath project(path: ‘:weavemeplease’, transitive: false)
  6. }

‘weavemeplease’ is the name of the project to be woven. We want this dependency to be non-transitive so we don’t end up weaving all of the upstream dependencies as well.

Gradle 1.11 and AspectJ 1.7

See the Gradle docs for more about multi-project builds, and the gradle-aspectj plugin for how to build with AspectJ.

The other hot tip regarding the gradle-aspectj plugin is this: apply the java plugin first, then configure the java stuff, *then* apply the aspect plugin. Finally, you can add aspect-specific configuration. The aspectj plugin works by copying state from the java configuration, so it helps if the java configuration actually exists. I really don’t know what controls execution order in Gradle, but evidently it does fall back to source code order in at least some circumstances.

PS: I’m posting this because this has taken me three hours of slightly wrong examples and completely cryptic error messages to work out. Groovy experts can laugh, but I know zero Groovy and have just started with Gradle. I’m beginning to suspect that the above syntax is a literal Map argument to the project() method of the DependencyHandler object – but given I don’t actually know what Groovy map syntax looks like, I’m not sure, and I have no idea what the meaningful keys and values in that map might be.

Do you need to know Groovy to use Gradle? I’m beginning to think it would help a lot. But even with no Groovy, it’s a lot better than maven’s eyeball-melting XML files.

One thought on “Gradle, AspectJ and non-transitive project dependencies

  1. Wow that was strange. I just wrote an very long comment but after I
    clicked submit my comment didn’t show up. Grrrr… well I’m not writing all that over again. Anyway, just wanted to say superb blog!

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>