On 14/07/10 12:23 AM, Steve Ebersole wrote:
To present an alternative view... You do not have to define separate
source sets if you do not want to.

This is probably the way to go in this case. It's easy enough to wire in some code generation into the main source set. Here's an example:

task someCodeGenerator(type: MyCodeGenerator) {
    destinationDir = file("$buildDir/generated-src")
}

compileJava {
    dependsOn someCodeGenerator
    source someCodeGenerator.destinationDir
}

If you still want to add use an additional source set, you can do something like:

sourceSets {
    version { .... }
    main {
        compileClasspath += version.classes
    }
}


   Gradle is extremely flexible in this
regard.

That is the approach I took, for example, when writing the Gradle Antlr
plugin.  There I simply add a new "directory" to the main source set (I
put directory in quotes because i ended up using a convention object for
various reasons that sorta makes a virtual directory).  If you are not
familiar with Antlr, it essentially reads some text files and produces
java sources, which of course then need to get compiled.  The plugin
adds the Antlr output directory to the main source set java sources in
addition to src/main/java

Have a peek at the Antlr plugin source[1] if you are interested in this
approach.  You do not have to make it a plugin, nor even a separate Task
class; you could do all this directly in your build script.

[1]
http://github.com/gradle/gradle/blob/master/subprojects/gradle-antlr/src/main/groovy/org/gradle/api/plugins/antlr/AntlrPlugin.java

On Mon, 2010-07-12 at 18:09 -0400, Philip Crotwell wrote:
I have 2 source sets in my project, main and version. The java code in
version is generated via a task and so needs to be separate from main.

But I want to be able to use a class in version from within main, much
as you can use main from within test. How do I tell the main sourceSet
that it "depends on" version. I have tried several variants on:

project.sourceSets.main.compileClasspath.add(project.sourceSets.version)
-->  Cause: Could not find method add() for arguments [source set
version] on configuration ':TauP:compile'.

project.sourceSets.main.compileClasspath.add(project.sourceSets.version.classesDir)
-->  Cause: Could not find method add() for arguments
[/export/home/crotwell/dev/seis/TauP/build/classes/version] on
configuration ':TauP:compile'.

And so on, but I can't seem to get it to work. What is the appropriate
way to create a compile dependency from one sourceSet on another.

thanks,
Philip

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

     http://xircles.codehaus.org/manage_email




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


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

   http://xircles.codehaus.org/manage_email


Reply via email to