Mulit模块与每个模块一起提供带弹簧的休息服务

时间:2019-03-26 07:36:14

标签: java spring gradle

我尝试使用 Gradle 创建多模块spring项目。 每个模块都有独立的rest api服务。

我对 Gradle 不太了解。 库应用程序可以通过 application 模块进行访问,但不能使用tomcat同时执行每个模块的API。

第1单元:应用程序

文件 settings.gradle:

 rootProject.name = 'application'

 include ':library-application'
 project(':library-application').projectDir = new File('../library-application')

文件 build.gradle:

    buildscript {
        ext { springBootVersion = '2.1.3.RELEASE' }
        repositories {      jcenter()
                    mavenCentral()
                    maven { url "https://plugins.gradle.org/m2/" }   
            }
        dependencies {  classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
                classpath 'org.gradle.api.plugins:gradle-tomcat-plugin:1.0',
                classpath 'org.apache.openjpa:openjpa-all:2.4.1'
                classpath 'at.schmutterer.oss.gradle:gradle-openjpa:0.2.0'
             }
    }

    plugins {
        id "io.spring.dependency-management" version "1.0.5.RELEASE"
    }

    apply plugin: 'java'
    apply plugin: 'eclipse'
    apply plugin: 'org.springframework.boot'
    apply plugin: 'io.spring.dependency-management'

    apply plugin: 'war'
    apply plugin: 'idea'
    apply plugin: 'maven'
    apply plugin: 'tomcat'
    bootJar {
        baseName = 'gs-multi-application'
        version = '0.0.1-SNAPSHOT'
    }
    sourceCompatibility = 1.8

    repositories { mavenCentral() }

    dependencies {
        compile('org.springframework.boot:spring-boot-starter-actuator')
        compile('org.springframework.boot:spring-boot-starter-web')
        compile project(':library-application')
        testCompile('org.springframework.boot:spring-boot-starter-test')
    }

第2单元:库应用 文件 build.gradle:

    buildscript {
        repositories {      jcenter()
                    mavenCentral()
                    maven { url "https://plugins.gradle.org/m2/" }   
            }
        dependencies {  classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
                classpath 'org.gradle.api.plugins:gradle-tomcat-plugin:1.0',
                classpath 'org.apache.openjpa:openjpa-all:2.4.1'
                classpath 'at.schmutterer.oss.gradle:gradle-openjpa:0.2.0'
             }
    }

    plugins {
        id "io.spring.dependency-management" version "1.0.5.RELEASE"
    }

    apply plugin: 'java'
    apply plugin: 'eclipse'
    apply plugin: 'org.springframework.boot'
    apply plugin: 'io.spring.dependency-management'

    apply plugin: 'war'
    apply plugin: 'idea'
    apply plugin: 'maven'
    apply plugin: 'tomcat'

    plugins { id "io.spring.dependency-management" version "1.0.5.RELEASE" }

    ext { springBootVersion = '2.1.3.RELEASE' }

    jar {
        baseName = 'gs-multi-library'
        version = '0.0.1-SNAPSHOT'
    }
    sourceCompatibility = 1.8

    repositories { mavenCentral() }

    dependencies {
        compile('org.springframework.boot:spring-boot-starter')
        testCompile('org.springframework.boot:spring-boot-starter-test')
    }

1 个答案:

答案 0 :(得分:0)

通常,Gradle中的根项目不执行任何操作,仅保留整体build.gradlesettings.properties来将子项目组合在一起。模块规划应该通过管理子项目的依赖性而不是文件夹结构来完成。

尝试以这种方式组织项目:

root_project (very simple project doing nothing)
  - library-application
    - Provide service controllers
  - application (depends on library-application)
    - Provide SpringBootApplication