Is there a task to create src/main/java/ and similar directories?


(rtayek) #1

hi, i am used to the eclipse style directory structure (src/, tst/, etc.).

is there a built in task for creating src/main/java, src/test/java, etc.?

or should i roll my own.

thanks


(rtayek) #2

maybe i can iterate over java.srcDirs and resources.srcDirs for the java part?

thanks


(Szczepan Faber) #3

Hey,

At the moment, there’s no task to create those dirs for you. You can iterate the srcDirs and create them from the build script (e.g. in some custom task). We plan to improve the bootstrap plugin to have tasks to create a quickstart java app, etc.

Hope that helps!


(rtayek) #4

looking at the sourceSetJavaProperties example from the new gradle book (please see below), i can iterate over some of the source sets if i have the java plugin

sourceSets.each { set->println “set $set” }

sourceSets.main.java.srcDirs.each { File file -> println “java dir $file” }

sourceSets.test.java.srcDirs.each { File file -> println “java dir $file” }

the above works fine.

but trying to get the resources dirs does not.

println sourceSets.main.resources.dump() // is confusing

but println “resources.srcDirs = ${resources.srcDirs}” works in the sample from the book.

thanks

task sourceSetJavaProperties << {

sourceSets {

main {

println “java.srcDirs = ${java.srcDirs}”

println “resources.srcDirs = ${resources.srcDirs}”

println “java.files = ${java.files.name}”

println “allJava.files = ${allJava.files.name}”

println “resources.files = ${resources.files.name}”

println “allSource.files = ${allSource.files.name}”

println “output.classesDir = ${output.classesDir}”

println “output.resourcesDir = ${output.resourcesDir}”

println “output.files = ${output.files}”

}

} }


(rtayek) #5

found this link https://github.com/townsfolk/gradle-templates in the gradle in action book.


(spencer_allain) #6

Eric Berry’s gradle-templates is the most effective way to create archetypes.

Just remember to run it without the daemon enabled, since several of the tasks prompt the user, and it utilizes System.console() which currently is not proxied by the daemon like raw stdin, stdout, and stderr are.

-Spencer


(rtayek) #7

… Just remember to run it without the daemon enabled …

thanks for the warning


(Martin Gee) #8

My 2 cents is… its a feature flaw that the Java, Groovy, WebApps etc plugins do not have a task to flesh out the src / test directories etc that they expect anyway.

As far as I know the plugins expect certain directory layouts e.g. main/groovy main/resources etc

Why leave it up to the developer to figure this out? Especially frustrating for a noob. Makes the learning curve harder.


(Peter Niederwieser) #9

Gradle 1.7 and 1.8 can already create the necessary directories for a Java library project, and 1.9 will support several other project types as well. For details see the release notes or user guide (build setup plugin).


(Martin Gee) #10

just need to add Groovy and web app to the build setup plugin (with the resources dir too)