On 13/03/10 7:56 AM, Rene Groeschke wrote:
Hi there,
to speed up our aspectj build I've changed the following task:

-------------------------
task compileJava(dependsOn: JavaPlugin.PROCESS_RESOURCES_TASK_NAME, overwrite: true) << { ant.taskdef( resource:"org/aspectj/tools/ant/taskdefs/aspectjTaskdefs.properties", classpath: configurations.ajc.asPath) ant.iajc(source:sourceCompatibility, target:targetCompatibility, destDir:sourceSets.main.classesDir.absolutePath, maxmem:"512m", fork:"true", aspectPath:configurations.aspects.asPath, inpath:configurations.ajInpath.asPath, sourceRootCopyFilter:"**/.svn/*,**/*.java",classpath:configurations.compile.asPath){
                 sourceroots{
               sourceSets.main.java.srcDirs.each{
                   pathelement(location:it.absolutePath)
               }                  }
       }     }
-------------------------

to the following code:

-------------------------
   task compileJava(dependsOn: JavaPlugin.PROCESS_RESOURCES_TASK_NAME,
                   overwrite: true) {
       outputs.files sourceSets.main.classesDir
inputs.files sourceSets.main.java.srcDirs, configurations.aspects.files, configurations.ajInpath.files, configurations.compile inputs.properties(["sourceCompatibility":sourceCompatibility, "targetCompatibility":targetCompatibility])
   }

   compileJava.doLast{
ant.taskdef( resource:"org/aspectj/tools/ant/taskdefs/aspectjTaskdefs.properties", classpath: configurations.ajc.asPath) ant.iajc(source:sourceCompatibility, target:targetCompatibility, destDir:sourceSets.main.classesDir.absolutePath, maxmem:"512m", fork:"true", aspectPath:configurations.aspects.asPath, inpath:configurations.ajInpath.asPath, sourceRootCopyFilter:"**/.svn/*,**/*.java",classpath:configurations.compile.asPath){
                 sourceroots{
               sourceSets.main.java.srcDirs.each{
                   pathelement(location:it.absolutePath)
               }                  }
       }      }
-------------------------

What I don't like about this change, is that I have to split the task into configuration and doLast setup. Is there a more convenient way to do this?

You don't have to split them. You can do this sort of thing:

task compileJava(...) {
    inputs.files someFiles
    outputs.files someOutputFiles
    doLast {
        ant.taskdef(...)
        ant.iajc(...)
    }
}

I would be tempted to use a custom task for this, and use the various annoations, such as @InputFiles and @OutputDirectory:

task compileJava(type: AspectJCompile) {
    ajcClasspath = configurations.ajc
    source = sourceSets.main.java
    destDir = sourceSets.classesDir
    // ... plus some more properties
}

class AspectJCompile extends DefaultTask { // or possibly extends SourceTask
    @InputFiles
    def FileCollection ajcClasspath
    @InputFiles
    def FileCollection source
    @OutputDirectory
    def File destDir
    @Input
    def souceCompatibility
    // ... plus some more properties ...

    @TaskAction
    def compile() {
        project.ant {
            taskdef(..., classpath: ajcClasspath.asPath)
iajc(..., destDir: destDir, sourceCompatibility: sourceCompatibility) {
                 ....
            }
        }
    }
}

This is arguably a better way of separating the 'what' and the 'how'. Plus, by using the annotations, you get validation and (some) dependency auto-wiring for free.


--
Adam Murdoch
Gradle Developer
http://www.gradle.org


---------------------------------------------------------------------
To unsubscribe from this list, please visit:

   http://xircles.codehaus.org/manage_email


Reply via email to