spring boot使用gradle打包怎么样排除指定jar包

在使用gradle bootRepackage命令时,怎么样排除不想要的jar包
我使用了customConfiguration的配置,但并不像文档描述上的起作用.链接地址

代码如下

buildscript {
    ext {
        springBootVersion = '1.4.0.RELEASE'
    }
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
    }
}

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

repositories {
    mavenLocal()
    mavenCentral()
}

configurations {
    mycustomconfiguration.exclude group: 'org.hibernate'
}

configurations.all {
    //exclude group:"org.hibernate"
}

task clientBoot(type: BootRepackage) {
    // withJarTask = clientJar
    println "~~~~~~~~~~~hello!~~~~~~~~~~~~~~~~"
    customConfiguration = "mycustomconfiguration"
}

dependencies {
    mycustomconfiguration configurations.runtime

    compile 'org.springframework.boot:spring-boot-starter-logging'
    compile 'org.springframework.boot:spring-boot-starter-web'
}

dependencyManagement {
    imports {
        mavenBom 'org.springframework.cloud:spring-cloud-dependencies:Brixton.SR4'
    }
}

我试着想排除掉hibernate-validator-5.2.4.Final.jar,使用了exclude group: 'org.hibernate',但完全没用,是不是我使用的方法有问题

注:providedCompile或者providedRuntime的方式过滤我知道,但因为我有别的目的,所以满足不了需求.

阅读 9.3k
1 个回答

已经解决了,代码如下,如果只是打jar包,war那一段可以删掉

buildscript {
    ext {
        springBootVersion = '1.4.0.RELEASE'
    }
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
    }
}

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

repositories {
    mavenLocal()
    mavenCentral()
}

configurations {
    jmeConfiguration
}

configurations.jmeConfiguration {
    exclude group:"org.springframework"
}

war {
    classpath = classpath.filter {
        return false
    }
}

bootRepackage {
    customConfiguration = "jmeConfiguration"
}

dependencies {
    jmeConfiguration configurations.runtime
}

dependencies {
    compile 'org.springframework.boot:spring-boot-starter-logging'
    compile 'org.springframework.boot:spring-boot-starter-web'
}

dependencyManagement {
    imports {
        mavenBom 'org.springframework.cloud:spring-cloud-dependencies:Brixton.SR4'
    }
}
推荐问题