Injecting Custom Tasks Into Build Chain

374 views
Skip to first unread message

Jake Wharton

unread,
Jun 14, 2013, 1:17:21 AM6/14/13
to adt...@googlegroups.com

I'm trying to inject a custom task into the normal build chain. Doing things I shouldn't... as usual.

def debugVariants = android.applicationVariants.matching { variant ->
  variant.buildType.debuggable
}

debugVariants.each { variant ->
  task chatty(dependsOn: variant.dexTask.dependsOn) << {
    println "hey"
  }
  variant.dexTask.dependsOn = chatty
}
* What went wrong:
A problem occurred evaluating project ':foo'.
> Could not find property 'dexTask' on com.android.build.gradle.internal.api.ApplicationVariantImpl_Decorated@1ef05b9b.

Which I find strange because BasePlugin.groovy has this (emphasis added):

// Add a dex task
def dexTaskName = "dex${variantData.name}"
def dexTask = project.tasks.create(dexTaskName, Dex)
variantData.dexTask = dexTask

if (variantData.proguardTask != null) {
    dexTask.dependsOn variantData.proguardTask
} else {
    dexTask.dependsOn variantData.javaCompileTask
}

Any ideas?



Jake Wharton
http://about.me/jakewharton

Xavier Ducrohet

unread,
Jun 14, 2013, 11:28:16 AM6/14/13
to adt...@googlegroups.com
The properties on the variant are named differently from that code in BasePlugin. There's 2 "variant" class (actually 3).

VariantData is internal storage
There's a [Base|Test|Apk|Library]Variant class for the api inside a build.gradle
Finally there's a "Variant" interface for the model that is sent to the IDE.

You'll find the names of the properties of the [Base|Test|Apk|Library]Variant classes here: http://tools.android.com/tech-docs/new-build-system/user-guide#TOC-Manipulating-tasks




--
You received this message because you are subscribed to the Google Groups "adt-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to adt-dev+u...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 



--
Xavier Ducrohet
Android SDK Tech Lead
Google Inc.
http://developer.android.com | http://tools.android.com

Please do not send me questions directly. Thanks!

Jake Wharton

unread,
Jun 14, 2013, 11:47:26 AM6/14/13
to adt...@googlegroups.com
That worked. Thanks.

I read that section, too. Must've not permeated into my brain.

Brian Shuman

unread,
Jun 14, 2013, 5:17:58 PM6/14/13
to adt...@googlegroups.com
what about

tasks.withType(org.gradle.api.tasks.compile.JavaCompile){
println javaCompile.classpath
}

I get "Could not find property 'javaCompile' on task :XXXXXX:compileDebug"

I'm referencing the link above and javaCompile should be there

Xavier Ducrohet

unread,
Jun 14, 2013, 7:30:32 PM6/14/13
to adt...@googlegroups.com
This should work

tasks.withType(org.gradle.api.tasks.compile.JavaCompile){ javaCompile ->
println javaCompile.classpath
}

If you don't specify "javaCompile ->" I think the default property name for the object coming from the collection will be "it"


--
You received this message because you are subscribed to the Google Groups "adt-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to adt-dev+u...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Brian Shuman

unread,
Jun 14, 2013, 7:44:27 PM6/14/13
to adt...@googlegroups.com
that did the trick, now i just have to find out how to keep the integrity of the classpath since its getting overriden..


On Thursday, June 13, 2013 10:17:21 PM UTC-7, Jake Wharton wrote:
Reply all
Reply to author
Forward
0 new messages