java - gradle 可以只包含特定的包并排除其他所有包吗

标签 java spring gradle spring-boot build.gradle

在我的项目中,我构建了两个 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/

相关文章:

maven - 用于gradle的多个Maven存储库

java - 为什么 Double.valueof javadoc 说它缓存值,而实际上没有?

java - Spring Swing 集成

java - hibernate 同步更新

java - Spring Data REST - POST 方法未调用 RepositoryEventHandler 方法?

java - Spring-Test-Mvc Controller 测试

configuration - Gradle 中编译配置和运行时配置的区别

gradle - 尝试使用gradle-swagger-generator-plugin生成代码时,获取java.lang.NoSuchMethodError:org.joda.time.DateTime.now()Lorg/joda/time/DateTime

java - 如何从字符串中选择特定值并将其转换为整数

java - lein自定义java类未找到异常