在我的项目中,我构建了两个 jar ,一个用于服务器的 fat jar 子,另一个用于客户端的瘦 jar 。有没有一种方法可以不指定所有排除项并使 include 相互排除所有其他内容(以及依赖项)
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
}
最佳答案
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 中的 include 方法根据定义是互斥的,即它将排除 include 中未另行指定的所有内容。为了避免将 spring-boot 依赖项添加到客户端 jar,可以简单地将 bootRePackage 限制为特定(在本例中为默认)jar 任务
bootRepackage.withJarTask = jar
关于java - gradle 可以只包含特定的包并排除其他所有包吗,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30415528/