Java 基于spring.profiles.active动态编译依赖项
有人能告诉我从哪里开始这项任务吗 在部署到jboss时,我只需排除Java 基于spring.profiles.active动态编译依赖项,java,gradle,build.gradle,Java,Gradle,Build.gradle,有人能告诉我从哪里开始这项任务吗 在部署到jboss时,我只需排除spring boot starter tomcat 我想它看起来会像: dependencies { compile("org.springframework.boot:spring-boot-starter-web"){ if(getProperty "spring.profiles.active" == "qat") exclude module: "spring-boot-s
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-dsspring profiles active=qat
。当我必须在本地运行时,gradle bootRun-dsspring profiles active=dev
。哪里定义了spring.profiles.active
?@ToYonos,它在src_server/main/resources/application.yml.sogetProperty“spring.profiles.active”
中不是真的东西?它不是一个读取application.yml
的方法,我在上面的示例代码中得到了一个错误。我已编辑问题以包含错误消息。是否正在创建WAR文件?请注意,Gradle对application.yml文件一无所知。另外,您确定应该在那里定义spring.profiles.active
?据我所知,application.yml允许您根据spring.profiles.active
的值指定不同的值。