1.My project has two main class i want to build jar for each main class using gradle. my source has 2 files ValidationRule.java SupportValidator.java both the file have one main class each i want to build the jar for each main class i can achieve the same from eclipse working fine 2.I want to load the source file for my project from 2 different folder,some part is there in one folder and remaining is there in another folder i.e like project/src snd another folder outside the project(../../../SharedClass)
my script as follows
apply plugin: 'eclipse' apply plugin: 'java' sourceCompatibility = 1.6 archivesBaseName = 'Process_XY' configurations { configurations.compile.transitive = false } dependencies { compile fileTree(dir:'/trunk/Solutions/project/Source/Binaries/CommonFunctions/build/libs', include: '*.jar') compile fileTree(dir:'/trunk/Solutions/project/lib/GeoTools/geotools-2.7.4-bin/geotools-2.7.4', include: '*.jar') compile "org.apache.hadoop:hadoop-core:1.0.3" compile "commons-collections:commons-collections:3.2.1" compile "commons-configuration:commons-configuration:1.6" compile "commons-discovery:commons-discovery:0.2" compile "commons-lang:commons-lang:2.4" compile "commons-logging:commons-logging:1.1.1" compile "commons-logging:commons-logging:1.0.4" compile "log4j:log4j:1.2.16" compile "com.vividsolutions:jts:1.8" compile "commons-net:commons-net:1.4.1" compile "org.apache.hadoop:hadoop-core:1.0.3" compile "commons-httpclient:commons-httpclient:3.0.1" compile "org.mortbay.jetty:servlet-api:2.5-20081211" compile "org.apache.hbase:hbase:0.94.0" compile "org.apache.zookeeper:zookeeper:3.4.3" } repositories { mavenCentral() maven { url "https://repository.cloudera.com/artifactory/cloudera-repos/" } maven { url "http://repo.springsource.org/libs-release" } maven { url "http://repo.springsource.org/libs-milestone" } maven { url "http://repo.springsource.org/libs-snapshot" } maven { url "http://www.datanucleus.org/downloads/maven2/" } maven { url "http://oss.sonatype.org/content/repositories/snapshots" } maven { url "http://people.apache.org/~rawson/repo" } } jar { from configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } manifest.attributes("Main-Class":"org.project.seismic.Process_XY") } sourceSets { main { java { source = ['src/org', '../../../SharedClass/org'] } } }above in sourceSets method i tried to load source from 2 folder but it didnt worked
Thanks in advance..!! How to achieve using gradle.
3
votes
Could you clarify a bit what you're asking? What is the directory structure you're looking at? What have you tried?
- Hiery Nomus
1 Answers
7
votes
Ok, first of all, the source on a SourceDirectorySet takes another SourceDirectorySet. The srcDirs method however takes paths. Change that block to the following:
sourceSets {
main {
java {
srcDirs ['src/org', '../../../SharedClass/org']
}
}
}
And you can easily add a second jar task as follows:
task secondJar(type: Jar) {
name = other-main-jar
from ...
manifest.attributes(...)
}
assemble.dependsOn(secondJar)
This will register a new Jar task called secondJar and makes sure that when the project is assembled, this jar is also created.