On 01/12/2010, at 8:12 AM, Chris Hane wrote:

> I want to compile the server directories while excluding the client 
> sub-directories except for the "shared" directories.  Is there a way to do 
> this?  My source directories looks something like:
> 
> /src/domain/client
> /src/domain/client/module1
> /src/domain/client/module1/shared
> /src/domain/client/module1/notshared
> /src/domain/client/module1/submoduleA
> /src/domain/client/module1/submoduleA/shared
> /src/domain/client/module1/submoduleA/notshared
> /src/domain/client/module2
> /src/domain/client/module2/shared
> /src/domain/client/module2/notshared
> 
> /src/domain/server/module1
> /src/domain/server/module2
> 
> 
> It used to work under .7 (which is what I am upgrading from) with the 
> following:
> 
> srcRootName = '.'
> srcDirNames = ['src']
> compile {
>    exclude('domain/client/**/*.java')
> }
> 
> The compiler would only compile the "client" classes if referenced from the 
> server code.  Worked great.
> 
> 
> Now I'm trying to figure out something similar under .9-rc3 but am stumped.  
> The last thing I tried was:
> 
> sourceSets{
>  main{
>    java{
>      srcDir 'src'
>    }
>  }
> }
> 
> compileJava {
>    exclude('domain/client/**/*.java')
>    include('domain/client/**/shared/*.java')
>    include('domain/server/**/*.java')
> }
> 
> The include for the 'shared' directory is not working.  The exclude is always 
> taking precedence.
> 
> Any pointers would be appreciated.


Some options:

option 1 - explicitly list all the included packages:

sourceSets.main.java {
    srcDir 'src'
    include 'domain/client/**/shared/*'
    include 'domain/server/**'
}

option 2 - replicate the Gradle 0.7 behaviour:

sourceSets.main.java {
    srcDir 'src'
    exclude 'domain/client/**'
}

compileJava {
    options.compileArgs << ['-sourcepath', file('src').absolutePath]
}       

option 3 - use an exclude predicate:

sourceSets.main.java {
    srcDir 'src'
    exclude { FileTreeElement e -> e.path.startsWith('domain/client/') && ! 
e.path.contains('/shared/') }
}


--
Adam Murdoch
Gradle Developer
http://www.gradle.org
CTO, Gradle Inc. - Gradle Training, Support, Consulting
http://www.gradle.biz

Reply via email to