Gradle configurations

Gradle官网上说明:每个依赖项都有不同的作用范围,如果想要配置可以使用configurations选项配置.
图1.Configurations声明的依赖项用于特定目的
图1.Configurations声明的依赖项用于特定目的

1|1使用groovy语言是配置gradle全局排除依赖:
configurations.all* { exclude group: 'org.springframework.boot', module: 'spring-boot-starter-logging' }
 
configurations { all*.exclude group: 'org.springframework.boot', module: 'spring-boot-starter-logging' }
1|2使用kotlin语言配置gradle全局排除依赖:
configurations.all { exclude ("org.springframework.boot","spring-boot-starter-logging") }

        SpringBoot包含了一套额外的工具集,可以让开发的过程更加愉快。spring-boot-devtools模块可以在任何工程中被添加,以支持一些额外的开发时特性。在构建时添加模块的依赖,这样项目就支持了开发者工具集,Maven和Gradle的示例如下:

Maven:

<dependencies>
  <dependency>
    <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-devtools</artifactId>
  <optional>true</optional>
  </dependency>
</dependencies>

Gradle:

configurations {
  developmentOnly
  runtimeClasspath {
  extendsFrom  developmentOnly
}
}
 
dependencies {
  developmentOnly("org.springframework.boot:spring-boot-devtools")
}

注意:

        运行一个完全打包的程序时会自动禁用开发者工具,如果你得程序通过java -jar或者通过一个特殊的类加载器启动,则会被认为是一个“生产”程序(会禁用开发者工具集)。如果这个对你不适用(你是通过容器启动的程序),可以考虑排除开发者工具或者设置程序的配置-Dspring.devtools.restart.enabled=false

原文地址:https://www.cnblogs.com/javalinux/p/14255291.html