On 05/03/2011, at 4:02 PM, Kenneth Kousen wrote: > Thanks for the answer. I'm not sure how to use inputs and outputs in this > situation, because I'm not sure what the inputs would be. I only want to > generate the stubs if they haven't already been generated, so the inputs and > the outputs locations are the same.
Not quite. The destdir and sourcedestdir are both outputs of your generation task. Here's how it works: You can think of the outputs for a task as the set of files which the task writes. There are currently 2 types of outputs for tasks: * Output files. An output file is a particular file which the task writes, whose path is known (just) before the task executes. For example, the jar file produced by a Jar task is treated as an output file. * Output directories. An output directory is a directory which the task writes files into, where the set of files are not known before the task executes. For example, the classes directory which the Compile task writes class files into is treated as an output directory. In your case, destdir and sourcedestdir are both output directories. If we look just at output directories, Gradle will execute a task if: * It has not executed the task before * Any of the files the task has previously written to its output directories have been removed or modified since last time the task was executed. Of course, Gradle does more than this, eg it checks input files, and so on. But declaring destdir and sourcedestdir as output directories should do exactly what you want. > Is that acceptable? That's why I was trying to use onlyIf instead. > > Ken > > On Fri, Mar 4, 2011 at 11:38 PM, Peter Niederwieser <[email protected]> > wrote: > > Kenneth Kousen wrote: > > > > This is all working, but it feels brittle because of the explicit source > > directory name. Is there a better, more general way to do this? > > > > The Java source directories can be queried with > "sourceSets.main.java.srcDirs". However, I suggest to separate generated > sources from the rest. I'd probably put them into a subdirectory of the > build output directory: > > sourceSets.main.java.srcDir "$buildDir/generatedSources" // add directory > for generated sources > > This avoids troubles with source control, and allows to clean the generated > sources with "gradle clean". To only regenerate sources if necessary, you > could use Gradle's incremental build capabilities and specify the inputs and > outputs of the generation task. > > > -- > Peter Niederwieser > Developer, Gradle > http://www.gradle.org > Trainer & Consultant, Gradleware > http://www.gradleware.com > Creator, Spock Framework > http://spockframework.org > > > -- > View this message in context: > http://gradle.1045684.n5.nabble.com/Referring-to-main-source-dir-tp3410389p3410432.html > Sent from the gradle-user mailing list archive at Nabble.com. > > --------------------------------------------------------------------- > To unsubscribe from this list, please visit: > > http://xircles.codehaus.org/manage_email > > > > > > -- > Kenneth A. Kousen > President > Kousen IT, Inc. > > Email: [email protected] > Site: http://www.kousenit.com > Blog: http://kousenit.wordpress.com > Twitter: @kenkousen > Making Java Groovy > -- Adam Murdoch Gradle Developer http://www.gradle.org Co-Founder and VP of Engineering, Gradleware Inc. - Gradle Training, Support, Consulting http://www.gradleware.com
