Thanks for the detailed answer. Seems straigtforward. I'll give it a try.
--
TK

Den 28-07-2011 09:04, Adam Murdoch skrev:

On 28/07/2011, at 3:52 PM, Thor Kummer wrote:

Hello

I'm trying to convert to gradle and I'm not sure how best to model my project setup.

We have about 100 projects in a single directory that logically form much fewer groups.

For example we have

auth-api
auth-impl
auth-persistence
auth-sql

and

rewrite-api
rewrite-impl
rewrite-persistence
rewrite-sql
rewrite-war

There are about 15 such groups plus various plain java and other projects.

Within each group the dependencies are always the same:

impl always depends on api and persistence
war always depends on api

and so on, but a few of the projects have mulitple apis and possibly impls, E.g:

sms-api
sms-client-api
sms-impl

I would like to take advantage of this regularity to avoid having to explicitly write down
all these dependencies.

Additionally, some of the projects depend on others. Auth might for example depend on rewrite.

I understand that I can group the projects logically in settings.gradle. I don't remember the exact syntax
but from memory it was something like:

/auth:/auth-api
/auth:/auth-impl
/auth:/auth-persistence

where auth is just an empty directory under the project directory.

I could of course just move the auth-* directories into auth/ but that would destroy
the ant build, which I want to be able to run in parallel until I'm sure this works.
Alternatively I could link them. I suppose Gradle will traverse symbolic links? Any hints
are welcome.

You don't need to move anything around. Instead, you can do something like this in settings.gradle:

include 'auth:auth-api', 'auth:auth-impl', 'auth:auth-persistence'
project(':auth:auth-api').projectDir = new File(settingsDir, 'auth-api')
project(':auth:auth-impl').projectDir = new File(settingsDir, 'auth-impl')

etc. Of course, you can script this so you don't need to hardcode every project.

Have a look at the dsl reference for the settings.gradle script for more details: http://gradle.org/current/docs/dsl/org.gradle.api.initialization.Settings.html



But my most pressing problem is how to make the dependencies within each group implicit. I'm
aware that that could require a plugin, which seem easy enough to write, but I don't know
exactly how to get that plugin to do the actual compilations etc. Can I apply the java plugin
on the various sup-projects within my plugin?

The simplest option would be to do something like this in your root build.gradle:

project(':auth:auth-api') {
    apply plugin: 'java'
}

project(':auth:auth-impl') {
    apply plugin: 'java'
    dependencies { 
        compile project(':auth:auth-impl')
    }
}

...

Again, you can script this so you don't need to hardcode everything.

Some alternatives to placing this in your root build.gradle:

* Extract it to an external script and apply from: 'my-external-script.gradle'
* Write a plugin in buildSrc which is applied to the root project. You still use the same logic as above.
* Write a plugin in buildSrc which is applied to the container projects (eg auth). Again, you use the same logic as above.


--
Adam Murdoch
Gradle Co-founder
http://www.gradle.org
VP of Engineering, Gradleware Inc. - Gradle Training, Support, Consulting
http://www.gradleware.com


--------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email

Reply via email to