Hi,
During aSkype session on sunday (Hans & me) we thought of introducing a
SourceDirectory concept to improve our compile/resource and test handling.
some of my first ideas:
# Defining source & resource dirs:
sourceDir('main') {
dir('src/main/java')
}
resourceDir('main') {
dir('src/main/resources')
replaceTokens ( prefix : '${', suffix : '}' ) ( [
tokenOne: 'valueOne',
tokenTwo: 'valueTwo'
])
}
testSourceDir('main') {
dir('src/test/java')
}
testResourceDir('main' {
dir('src/test/resources')
}
a more advanced example (with jdk version specific code):
sourceDir('main') { dir('src/main/java') }
sourceDir('jdk14') { dir('src/jdk14/java') }
sourceDir('jdk15') { dir('src/jdk15/java') }
sourceDirGroup('jdk14'){ sourceDirs('main','jdk14') }
sourceDirGroup('jdk15'){ sourceDirs('main','jdk15') }
testSourceDir('main') { dir('src/test/java') }
testSourceDir('jdk14') { dir('src/test-jdk14/java') }
testSourceDir('jdk15') { dir('src/test-jdk15/java') }
testSourceDirGroup('jdk14') { testSourceDirs('main','jdk14') }
testSourceDirGroup('jdk15') { testSourceDirs('main','jdk15') }
# Define how stuff should be compiled
// default by name and synhtetic
compile('main') {
// options
}
// or
compileMain {
// options
}
// custom compiles (naming optional)
compile ( sourceDir('build/generated-java-sources') ) {
// options
}
// or
compile ('antlr-source-compile', sourceDir('build/generated-java-sources') )
{
// options
}
# Define how stuff should be tested:
// default by name and synhtetic
test('main') {
// options
}
// or
testMain {
// options
}
// custom compiles (naming optional but required when you want to be able to
use it from the command line)
test (sourceDir('main'), testSourceDir('main') ) {
dependsOn(...) ?
// options
}
// with explicit name
test ('slow-test', sourceDir('main'), testSourceDir('main') ) {
// options
}
# Define how stuff should be javadoc-ed
javadoc('main') {
// options
}
// or
javadocMain() {
// options
}
// custom javadoc
javadoc('custom', sourceDirs('jdk14','antlr-sources') ) {
// options
}
# Define how stuff should be packaged
defaultJar(JarTask, name: project.name) {
mainCompile { // include the result of main compile
// additional options includes/excludes ?
}
mainResources // include the result of main resources
}
// or
defaultJar(JarTask, name: project.name) {
main // all of main compile + resources
}
defaultSourceJar(JarTask, name: project.name, classifier: 'sources') {
mainSources
}
defaultJavadocJar(JarTask, name: project.name, classifier: 'javadoc' ) {
javadocMain
}
defaultTestJar(JarTask, name: project.name, classifier: 'tests') {
mainTestCompile
mainTestResources
}
// or
defaultTestJar(JarTask, name:project.name, classifier: 'tests') {
mainTest // all of mainTest test compile + test resources
}
defaultTestSourceJar(JarTask, name: project.name, classifier:
'test-sources') {
mainTestSources
}
// this way it is very easy to define bundles:
gradleExternalJavadocBundle(JarTask, name: 'gradle-external-javadoc' ) {
main {
package('org.gradle.external.javadoc')
}
manifest {
// additional manifest instructions
}
}
I think this is a very powerfull concept to use the task names to include
the result of a compile/resources task in an artifact and I find it very
natural but other views may differ.
Comments other ideas more than welcome.
Kr,
Tom