Java 如何使用gradle源集制作多个war工件
我正在尝试将一个现有的gradle项目转换为使用源代码集,以便可以在两个独立的应用程序中重用某些类 到目前为止,我有以下新的build.gradle:Java 如何使用gradle源集制作多个war工件,java,spring,gradle,Java,Spring,Gradle,我正在尝试将一个现有的gradle项目转换为使用源代码集,以便可以在两个独立的应用程序中重用某些类 到目前为止,我有以下新的build.gradle: buildscript { repositories { mavenCentral() } dependencies { classpath("org.springframework.boot:spring-boot-gradle-plugin:1.5.1.RELEASE")
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:1.5.1.RELEASE")
classpath('com.h2database:h2:1.4.193')
classpath('org.hibernate:hibernate-core:5.0.1.Final')
}
}
apply plugin: 'java'
sourceCompatibility = 1.8
targetCompatibility = 1.8
sourceSets{
main{
apply plugin: 'idea'
java{
srcDirs = ['src/main/java']
}
}
api{
apply plugin: 'idea'
apply plugin: 'org.springframework.boot'
apply plugin: 'war'
springBoot{
mainClass="com.robocubs4205.cubscout.Application"
}
java{
srcDirs = ['src/main/java','src/api/java']
}
war{
baseName="cubscout-server"
version="0.0.0"
}
}
web_client{
apply plugin: 'idea'
apply plugin: 'org.springframework.boot'
apply plugin: 'war'
springBoot{
mainClass="com.robocubs4205.cubscout.Application"
}
java {
srcDirs = ['src/web-client/java', 'src/main/java']
}
war{
baseName="cubscout-client"
version="0.0.0"
}
}
}
repositories {
jcenter()
}
dependencies {
compile 'org.springframework.boot:spring-boot-gradle-plugin:1.3.5.RELEASE'
compile 'org.springframework.boot:spring-boot-starter-web:1.5.1.RELEASE'
compile 'org.springframework.boot:spring-boot-starter-data-jpa:1.5.2.RELEASE'
//compile 'org.springframework:spring-context:4.3.6.RELEASE'
//compile 'org.springframework.hateoas:spring-hateoas:0.23.0.RELEASE'
//compile 'org.springframework.integration:spring-integration-core:4.3.7.RELEASE'
//compile 'org.springframework.batch:spring-batch-core:3.0.7.RELEASE'
compile 'org.springframework.data:spring-data-jpa:1.11.0.RELEASE'
compile 'org.springframework.data:spring-data-rest-webmvc:2.6.0.RELEASE'
//compile 'org.springframework.security:spring-security-web:4.2.1.RELEASE'
compile 'org.hibernate:hibernate-core:5.0.1.Final'
compile 'com.h2database:h2:1.4.193'
compile 'org.springframework.boot:spring-boot-starter-tomcat:1.5.1.RELEASE'
testCompile 'junit:junit:4.12'
testCompile 'org.mockito:mockito-all:1.10.19'
providedRuntime 'org.springframework.boot:spring-boot-starter-tomcat:1.5.1.RELEASE'
}
我的意图是创建两个工件:cubscout-client-0.0.0.war
和cubscout-server-0.0.0.war
,前者使用src/web client
中的源代码,后者使用src/api
中的源代码,两者都使用源代码表单src/main
。但是,它一次只创建一个
我能找到的最接近答案是,但我无法理解答案,因为正如我读到的大多数关于Gradle的文章一样,人们没有给出任何关于build.Gradle的上下文,他们的代码片段去了哪里
我正在使用Intellij Idea作为我的IDE,如果能帮助Intellij看到这两个工件,我将不胜感激
编辑:我尝试使用多项目构建而不是使用源集。build.gradle如下所示:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:1.5.2.RELEASE")
classpath('com.h2database:h2:1.4.193')
classpath('org.hibernate:hibernate-core:5.0.1.Final')
}
}
plugins{
id 'org.springframework.boot' version '1.5.2.RELEASE'
}
apply plugin: 'idea'
allprojects{
apply plugin: 'java'
apply plugin: 'idea'
apply plugin: 'war'
sourceCompatibility = 1.8
targetCompatibility = 1.8
repositories {
jcenter()
}
dependencies {
compile 'org.springframework.boot:spring-boot-gradle-plugin:1.5.2.RELEASE'
compile 'org.springframework.boot:spring-boot-starter-web:1.5.1.RELEASE'
compile 'org.springframework.boot:spring-boot-starter-data-jpa:1.5.2.RELEASE'
//compile 'org.springframework:spring-context:4.3.6.RELEASE'
//compile 'org.springframework.hateoas:spring-hateoas:0.23.0.RELEASE'
//compile 'org.springframework.integration:spring-integration-core:4.3.7.RELEASE'
//compile 'org.springframework.batch:spring-batch-core:3.0.7.RELEASE'
compile 'org.springframework.data:spring-data-jpa:1.11.0.RELEASE'
compile 'org.springframework.data:spring-data-rest-webmvc:2.6.0.RELEASE'
//compile 'org.springframework.security:spring-security-web:4.2.1.RELEASE'
compile 'org.hibernate:hibernate-core:5.0.1.Final'
compile 'com.h2database:h2:1.4.193'
compile 'org.springframework.boot:spring-boot-starter-tomcat:1.5.1.RELEASE'
testCompile 'junit:junit:4.12'
testCompile 'org.mockito:mockito-all:1.10.19'
providedRuntime 'org.springframework.boot:spring-boot-starter-tomcat:1.5.1.RELEASE'
}
}
project(':api'){
apply plugin: 'java'
apply plugin: 'org.springframework.boot'
apply plugin: 'war'
springBoot{
mainClass="com.robocubs4205.cubscout.Application"
}
war{
baseName="cubscout-server"
version="0.0.0"
}
dependencies{
compile project(':')
}
}
project(':web-client'){
apply plugin: 'java'
apply plugin: 'org.springframework.boot'
apply plugin: 'war'
springBoot{
mainClass="com.robocubs4205.cubscout.Application"
}
war{
baseName="cubscout-client"
version="0.0.0"
}
dependencies{
compile project(':')
}
}
当I
api:build
或client:build
时,生成成功,但运行build
会导致springsbootRepackage
任务失败,并且找不到主类。此外,来自api:build
和client:build
的工件似乎没有启用spring引导,因为当spring通常有多个页面时,它们没有任何控制台输出。为什么不将其拆分为单独的项目?@opal我不知道如何做到这一点。我能找到的文档令人困惑,似乎暗示不同的项目没有共享源。为什么不将其拆分为不同的项目?@opal我不知道如何做到这一点。我能找到的文档令人困惑,似乎暗示着不同的项目没有共享资源。