美文网首页
gradle spring boot 配置多项目结构

gradle spring boot 配置多项目结构

作者: 辛多雷 | 来源:发表于2018-11-28 02:27 被阅读0次

    demo-parent下面的

    目录结构 其中子目录下面的setting.gradle可以去掉

    ├── build.gradle
    ├── demo-common
    │   └── build.gradle
    ├── demo-dao
    │   └── build.gradle
    ├── demo-service
    │   └── build.gradle
    ├── demo-web
    │   └── build.gradle
    └── settings.gradle
    
    

    整体的buildscript

    buildscript {
        ext {
            springBootVersion = '2.0.0.RELEASE'
            springCloudVersion = 'Finchley.M8'
        }
        repositories {
            mavenLocal()
            mavenCentral()
            maven { url "http://mvnrepository.com/" }
            maven { url "http://maven.aliyun.com/nexus/content/groups/public/" }
            maven { url "https://repo.spring.io/snapshot" }
            maven { url "https://repo.spring.io/milestone" }
            maven { url "https://repo.spring.io/release" }
            maven { url "https://repo.spring.io/libs-milestone" }
            jcenter()
        }
        dependencies {
            classpath "io.spring.gradle:dependency-management-plugin:0.5.2.RELEASE"
            classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
        }
    
    }
    
    
    allprojects {
        group = "com.demo"
        version '0.0.1-SNAPSHOT'
    
        ext {
            springBootVersion = '2.0.0.RELEASE'
        }
    
        apply plugin: 'java'
    }
    
    subprojects {
        apply plugin: 'io.spring.dependency-management'
        sourceCompatibility = 1.8
        targetCompatibility = 1.8
        tasks.withType(JavaCompile) {
            options.encoding = 'UTF-8'
        }
        repositories {
            mavenLocal()
            mavenCentral()
            maven { url "http://mvnrepository.com/" }
            maven { url "http://maven.aliyun.com/nexus/content/groups/public/" }
            maven { url "https://repo.spring.io/snapshot" }
            maven { url "https://repo.spring.io/milestone" }
            maven { url "https://repo.spring.io/libs-milestone" }
            maven { url "https://repo.spring.io/release" }
            jcenter()
        }
    
        dependencies {
            compile 'org.slf4j:slf4j-api:1.7.25'
            testCompile 'junit:junit:4.12'
            testCompile('org.springframework.boot:spring-boot-starter-test')
        }
    
        dependencyManagement {
            imports {
                mavenBom 'org.springframework.cloud:spring-cloud-config:2.0.0.M8'
                mavenBom "org.springframework.cloud:spring-cloud-dependencies:${springCloudVersion}"
            }
        }
    }
    

    demo-common 以jar包的形式应用其build.gradle 为 其它 demo-service和demo-dao中的build.gradle 一样

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

    demo-web 是可执行的jar包 build.gradle

    buildscript {
        repositories {
            maven { url 'http://maven.aliyun.com/nexus/content/groups/public' }
            maven { url "https://repo.spring.io/release" }
            mavenCentral()
            jcenter()
            mavenLocal()
        }
        dependencies {
            classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
        }
    }
    
    apply plugin: 'java'
    apply plugin: 'org.springframework.boot'
    
    repositories {
        maven { url "https://repo.spring.io/milestone" }
        mavenCentral()
    }
    
    jar{
        baseName ="demo-web"
        version ="0.0.1-SNAPSHOT"
    }
    
    dependencies {
        compile project(':demo-service')
        compile ('org.springframework.boot:spring-boot-starter-thymeleaf')
    
    }
    

    相关文章

      网友评论

          本文标题:gradle spring boot 配置多项目结构

          本文链接:https://www.haomeiwen.com/subject/hdpoqqtx.html