On 06/03/2012, at 1:30 AM, Andrew Spina wrote:

> I'm trying to write a task that manipulates both dependencies and generated 
> artifacts. I have two kinds of project, type A and type B. I need to copy the 
> artifacts from A into a directory called 'Plugins'. I need to copy artifacts 
> from B into a directory called 'Libraries'. For both types, I need to copy 
> external dependencies into 'Libraries'. I've been struggling with the copy 
> task and finally decided to ask. Here is what I came up with:
> 
> // This should copy type b generated artifacts into libraries
> task copyTypeBJars(type: Copy) {
>    subprojects {
>        if(isTypeB(project)){
>            // How do I copy just get generated Jars here?
>        }
>    }
>    into "Libraries"
> }

task copyTypeBJars(type: Copy) {
   subprojects {
       if(isTypeB(project)){
           from configurations.archives.allArtifacts.files
       }
   }
   into "Libraries"
}

> 
> task copyLibraries(type: Copy, dependsOn: 'copyTypeBJars') {
>    // Want this to include all external dependencies 
>    subprojects {
>        // This is supposed to exclude all generated jars. Type B jars are 
> copied by copyTypeBJars.
>        exclude '**/$project.name*'
>        // This is supposed to pick up all external compile time dependencies.
>        from configurations.compile
>    }
>    into "Libraries"
> }

This is trickier, because you need to defer dependency resolution by using a 
configuration task.

task configCopyLibraries << {
   subprojects {
     configurations.compile.resolvedConfiguration.resolvedArtifacts.each {
       def dependency = artifact.moduleVersion.id
       if (!typeBProjects.*.name.contains(dependency.name)) { // is not a type 
B project
         copyLibraries.from artifact.file
       }     
     }
   }  
}

task copyLibraries(type: Copy, dependsOn: ['copyTypeBJars', 
configCopyLibraries]) {
   into "Libraries"
}

The reason for this extra indirection is to avoid resolving dependencies on 
every build. This way, we only force dependency resolution when the 
copyLibraries task is going to be run.

> task copyPlugins(type: Copy) {
>    subprojects {
>        if(isTypeA(project)){
>            // How do I copy just get generated Jars here?
>        }
>    }
>    into "Plugins"
> }

Seems to be the same as the first case.

-- 
Luke Daley
Principal Engineer, Gradleware 
http://gradleware.com


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

    http://xircles.codehaus.org/manage_email


Reply via email to