Change DestinationDir

I’ve this task:

task generateMetamodel(type: JavaCompile, group: 'build', description: 'Generates the QueryDSL query types') {
    source = sourceSets.jpamodelgen.java
    classpath = configurations.compile + configurations.jpamodelgen
    options.compilerArgs = [
        "-proc:only"
    ]
    destinationDir = sourceSets.main.java.srcDirs.iterator().next()
}
compileJava.dependsOn generateMetamodel

I need to change destinationDir in order to set generated files in a subfolder sourceSets.main.java.srcDirs.iterator().next(). So I’d need to set them in sourceSets.main.java.srcDirs.iterator().next() + /metamodel

I guess it’s absolutly possible, however I’m not quite figuring out how to do it.

Thanks for all.

I’d go for
destinationDir = file(sourceSets.main.java.srcDirs.first().absolutePath+’/metamodel’)

Note the use of groovy first() method, available on all Iterable, which is less dodgy than iterator().next()