有人可以指导我从哪里开始这项任务吗?
部署到 jboss 时,我只需排除 spring-boot-starter-tomcat
即可。
我想它会看起来像:
dependencies {
compile("org.springframework.boot:spring-boot-starter-web"){
if(getProperty "spring.profiles.active" == "qat")
exclude module: "spring-boot-starter-tomcat"
}
testCompile('org.springframework.boot:spring-boot-starter-test')
}
使用上面的示例,我收到错误:
Could not get unknown property 'spring.profiles.active' for DefaultExternalModuleDependency{group='org.springframework.boot', name='spring-boot-starter-web', version='null', configuration='default'} of type org.gradle.api.internal.artifacts.dependencies.DefaultExternalModuleDependency.
也许我可以创建一个自定义任务来设置该任务的spring.profiles.active
。帮助!
最佳答案
正如 Peter Ledbrook 提到的,gradle 在编译时无法访问 spring-boot 的 application.yml。并且依赖项
在gradle生命周期的早期运行,在解决依赖项
之前永远不会调用任务。
即使尝试依赖解析策略也是徒劳的。
所以我只需要这样做:
dependencies {
compile("org.springframework.boot:spring-boot-starter-web") {
if(System.getProperty("spring.profiles.active") == "qat"){
exclude module: "spring-boot-starter-tomcat"
}
}
compile("org.springframework.boot:spring-boot-starter-security")
if(System.getProperty("spring.profiles.active") == "qat"){
providedCompile group: 'javax.servlet', name: 'javax.servlet-api', version: '3.0.1'
}
testCompile('org.springframework.boot:spring-boot-starter-test')
}
然后我将在部署到 jboss 时输入 gradle build -Dspring-profiles-active=qat
。和 gradle bootRun -Dspring-profiles-active=dev
当我必须在本地运行时。
关于java - 基于spring.profiles.active动态编译依赖,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50601943/