gradle可以只包含特定包,并排除其他所有内容

时间:2015-05-23 17:16:26

标签: java spring gradle spring-boot build.gradle

从我的项目中我建造了两个罐子,一个是服务器的胖罐子,另一个是客户端的薄罐子。有没有办法不指定所有排除,并使包含相互排除其他所有内容(依赖项)

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
}

1 个答案:

答案 0 :(得分:1)

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
}   

gradle中的方法根据定义是互斥的,即它将排除包含中未另行规定的所有内容。为了避免将spring-boot依赖项添加到客户端jar,可以简单地将bootRePackage限制为特定的(在本例中为默认值)jar任务

bootRepackage.withJarTask = jar