If somebody tried to solve similar problem before, please share your solution. In my gradle file I have different subproject. As of right now I am able to build rest-client with core, but there could be situation when rest-client should be also be build with db-client subproject. Basically the idea is I need to be able to build rest-client with different dependency. Let say one task builds rest-client with dependency to one project and another task build rest-client with dependency on two subproject.
project(':core') {
apply plugin: "groovy"
repositories {
mavenCentral()
}
dependencies {
compile 'org.codehaus.groovy:groovy-all:2.4.5'
testCompile "org.testng:testng:6.8.21"
}
}
//rest-client Project specific stuff
project(':rest-client') {
apply plugin: "groovy"
repositories {
mavenCentral()
}
dependencies {
compile 'org.codehaus.groovy.modules.http-builder:http-builder:0.7.1'
compile project(':core')
compile 'org.codehaus.groovy:groovy-all:2.4.5'
testCompile "org.testng:testng:6.8.21"
}
jar {
from configurations.runtime
}
}
//db-client Project specific stuff
project(':db-client') {
apply plugin: "groovy"
repositories {
mavenCentral()
}
dependencies {
compile project(':core')
compile 'org.codehaus.groovy:groovy-all:2.4.5'
compile 'mysql:mysql-connector-java:5.1.37'
//compile 'org.elasticsearch:elasticsearch:2.3.1'
compile 'org.elasticsearch:elasticsearch-client-groovy:0.10.0'
}
}
解决方案
Sorry for the late response, if you still need something like this here is an example.
apply plugin: "groovy"
repositories {
mavenCentral()
}
configurations {
projectDep
libraryDep
}
project('core') {
apply plugin: "java"
}
dependencies {
projectDep project(':core')
libraryDep 'my.project:project:0.1.0'
compile 'org.codehaus.groovy.modules.http-builder:http-builder:0.7.1'
compile 'org.codehaus.groovy:groovy-all:2.4.5'
testCompile "org.testng:testng:6.8.21"
}
jar {
from configurations.libraryDep
}
task projectJar(type: Jar) {
appendix = 'project'
from sourceSets.main.output, configurations.projectDep, configurations.runtime
}
You have then 2 jar tasks. The jar takes all declared dependencies from compile,runtime and libraryDep and the projectJar takes compile,runtime and projectDep.
Hope this helps.