I have almost all source files which are java files, and some are groovy source files. And then I have lib/*.jar files those I should take into compiling. How can I compile with 3 steps with Gradle? Some source files are included and some are excluded into/from compiling.
Source structure:
src/main/java src/main/groovy
My build.gradle:
apply plugin: ‘groovy’ // apply plugin: ‘java’
version = 1.1
defaultTasks ‘clean’, ‘main1classes’, ‘main2classes’, ‘main3classes’, ‘myjar’
sourceCompatibility=1.6 targetCompatibility=1.6
repositories {
mavenCentral() }
def libs = files(‘lib/activation.jar’, ‘…/xalan.jar’)
dependencies {
groovy group: ‘org.codehaus.groovy’, name: ‘groovy-all’, version: ‘2.0.5’
testCompile group: ‘junit’, name: ‘junit’, version: ‘4.8.2’
compile libs
// main1classes libs
// main1classes2 libs
// compileMain3Java libs
// main1classes3 libs }
sourceSets {
main1 {
java {
srcDirs = [‘src/main/java’]
compileClasspath += libs
include ‘fi/nkl/thp/app/**/*/XmlReader’, …
exclude ‘fi/nkl/thp/app/**/*/*Article’
}
}
main2 {
groovy {
srcDirs = [‘src/main/groovy’]
compileClasspath += sourceSets.main1.output
compileClasspath += libs
include ‘fi/nkl/thp/app/**/*/HameensanomatArticle’
}
}
main3 {
java {
srcDirs = [‘src/main/java’]
compileClasspath += sourceSets.main1.output
compileClasspath += sourceSets.main2.output
compileClasspath += libs
include ‘fi/**//’
}
}
}
task myjar(type: Jar) {
baseName = ‘hameensanomat’
from sourceSets.main1.output
from sourceSets.main2.output
from sourceSets.main3.output }
// project.group = “test.tree” project.version = “” // manifest.mainAttributes(“Main-Class” : “test.tree.App”)
compileJava.options.encoding = ‘UTF-8’
Thank in advance,
Tuomas