【发布时间】:2016-06-05 17:03:50
【问题描述】:
我有项目 A 和 B,它们都将 common 项目作为编译依赖项定义在它们的 build.gradle 文件中,如下所示:
dependencies {
compile project(":common")
compile('org.springframework.boot:spring-boot-starter-actuator')
compile('org.springframework.boot:spring-boot-starter-web')
compile('org.springframework.boot:spring-boot-starter-security')
compile('org.springframework.boot:spring-boot-starter-cache')
compile("net.oauth.core:oauth:20090617")
compile("net.oauth.core:oauth-httpclient4:20090617")
compile('org.apache.httpcomponents:httpclient')
compile("com.atlassian.jira:jira-rest-java-client:2.0.0-m2")
compile("com.google.guava:guava:18.0")
compile('org.flywaydb:flyway-core')
testCompile('org.springframework.boot:spring-boot-starter-test')
}
这个通用项目有 application.yml 文件,其中包含各种通用信息,例如数据库连接属性、休眠设置等。所以我不想将这些文件复制到其他项目中,例如 A 和 @987654326 @。
在 A 项目中,主 Spring Boot 文件如下所示:
@SpringBootApplication(scanBasePackageClasses = {CommonApp.class,
A.class})
public class A {
public static void main(String[] args) {
SpringApplication.run(A.class, args);
}
}
其中CommonApp 是commmon 项目中的主类。这个common 主文件如下:
@SpringBootApplication
public class CommonApp {
public static void main(String[] args) {
SpringApplication.run(CommonApp.class, args);
}
}
项目A 和B 编译得很好,但是common 项目的类路径中的所有yml 文件在A 和A 和B 中不可见,所以我别无选择在A 和B 中手动复制它们
什么是更好的方法? spring boot 常用项目可以和其他项目共享资源吗?
请注意,理想的解决方案不应该依赖于 gradle,因为我想从 Intellij IDEA 运行单元和集成测试,它不使用 gradle 来运行测试。
我的应用结构是
app
|-A
|-build.gradle
|-web
|-B
|-build.gradle
|-common
|-src/main/resources
|-application.yml
|-database.yml
|-web.yml
|-settings.gradle
|-build.gradle
A、B、common都是spring boot的app(common也是boot app,但是只作为A、B的依赖)。
【问题讨论】:
-
能展示一下常用项目的文件夹结构吗?您是否将 yaml 文件打包到您发布的 jar 中?
-
不,我没有将 yaml 打包到罐子里,我该怎么做? gradle 脚本不是开箱即用的吗?
-
非代码文件仅在标准资源文件夹 (
src/main/resources) 中自动包含在 jar 中,或者它们的位置作为资源位置。在您上面列出的结构中,yaml 文件位于何处? -
是的,对不起。我也将 yml 文件添加到列表中。我在 gradle 的项目中没有添加自定义资源源集文件夹。
标签: java spring gradle spring-boot