Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can gradle include only specific package and exclude everything else

From my project I'm building two jars, one a fat jar for server and the other a thin jar for client. Is there a way to NOT specify all the excludes and make the include mutually exclude everything else (the dependencies as well)

apply plugin: 'java'
apply plugin: 'spring-boot'
apply plugin: 'eclipse'

repositories { jcenter() }
configurations {
    compile.exclude module: "spring-boot-starter-tomcat"
}
dependencies {
    compile(bootweb)
    compile(bootundertow)
    testCompile(boottest)
}
mainClassName = 'mordeth.sentinel.util.SentinelServer'

jar{
    baseName='sentinel-service-boot'
    version = version
}   


task clientJar(type: Jar){
    baseName='sentinel-service-client'
    version = version
    from sourceSets.main.output.classesDir  
    include 'mordeth/sentinel/dto/*.class'
}   

artifacts{
    archives jar, clientJar
}
like image 569
Monish Sen Avatar asked Oct 12 '25 22:10

Monish Sen


1 Answers

apply plugin: 'spring-boot'
apply plugin: 'java'
apply plugin: 'eclipse'


repositories { jcenter() }

configurations {
    compile.exclude module: "spring-boot-starter-tomcat"
}

dependencies {
    compile(bootweb)
    compile(bootundertow)
    testCompile(boottest)
}

mainClassName = 'mordeth.sentinel.util.SentinelServer'

jar {
    baseName='sentinel-service-boot'
    version = version
}

task clientJar(type: Jar, dependsOn: jar){
    baseName = 'sentinel-service-client'
    from sourceSets.main.output.classesDir
    include 'mordeth/sentinel/dto/*'
}

bootRepackage.withJarTask = jar


artifacts{
    archives jar, clientJar
}   

include method in gradle is by definition mutually exclusive i.e it'll exclude everything not otherwise specified in the include. To avoid spring-boot dependencies getting added to the client jar, one can simply restrict the bootRePackage to a specific (in this case the default) jar task

bootRepackage.withJarTask = jar
like image 178
Monish Sen Avatar answered Oct 14 '25 12:10

Monish Sen



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!