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:

apply plugin: 'aspectj'

dependencies {
	ajInpath project(path: ':weavemeplease', transitive: false)

‘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.

Leave a Reply

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