
apply from: 'dependencyDefine.gradle'

// SpringBoot
buildscript {
    ext {
        springBootVersion = '2.1.3.RELEASE'
//        wrapperVersion = '1.0.21.RELEASE'
    }
    repositories {
        mavenLocal()
//		maven { url = "http://maven.aliyun.com/nexus/content/groups/public" }
        mavenCentral()
        maven {
            url "https://plugins.gradle.org/m2/"
        }
    }
    dependencies {
//        classpath("org.springframework.boot.experimental:spring-boot-thin-gradle-plugin:${wrapperVersion}")
        classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
    }
}

subprojects {
    apply plugin: 'java'
    apply plugin: "idea"
    apply plugin: 'maven'
//    apply plugin: 'eclipse'
    apply plugin: 'org.springframework.boot'
    apply plugin: 'io.spring.dependency-management'

    group = 'com.qxgmat'
    version = '0.0.1-SNAPSHOT'

    sourceCompatibility = 1.8
    targetCompatibility = 1.8

    tasks.withType(JavaCompile) {
        options.encoding = 'UTF-8'
    }

    repositories {
        mavenLocal()
        maven { url = "http://maven.aliyun.com/nexus/content/groups/public" }
        mavenCentral()
    }

    configurations{
        parentClasspath {}
    }

    // 清除现有的lib目录
    task clearJar(type: Delete) {
        delete "$buildDir/libs/lib"
    }

    // 将依赖包复制到lib目录
    task copyJar(type: Copy, dependsOn: 'clearJar') {
        from configurations.compileClasspath
        into "$buildDir/libs/lib"
    }

    // 删除多余依赖
    task clearCom(type: Copy, dependsOn: 'copyJar') {
        delete "$buildDir/libs/lib/com"
    }

    dependencies {
        compileClasspath("org.springframework.boot:spring-boot-starter")
        compileClasspath("org.springframework.boot:spring-boot-starter-web")
        compileClasspath('org.springframework.boot:spring-boot-starter-aop')
        compileClasspath('org.springframework.boot:spring-boot-starter-jdbc')
        compileClasspath('org.springframework.boot:spring-boot-starter-data-jpa')
//	compileClasspath("org.springframework.boot:spring-boot-starter-security")
        compileClasspath("org.springframework.boot:spring-boot-starter-actuator")
        compileClasspath('org.springframework.boot:spring-boot-starter-logging')
        compileClasspath('org.springframework.boot:spring-boot-starter-cache')
        compileClasspath('org.springframework.boot:spring-boot-starter-data-redis')
        compileClasspath("org.springframework.boot:spring-boot-devtools")

        compileClasspath('mysql:mysql-connector-java')
        compileClasspath(libraries."mybatis", libraries."mybatis-page")
        compileClasspath("tk.mybatis:mapper-spring-boot-starter:2.1.5"){
            exclude group: "javax.persistence"
        }

        testCompile("org.springframework.boot:spring-boot-starter-test")


        compileClasspath group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: '2.9.9'
        compileClasspath group: 'com.alibaba', name: 'fastjson', version: '1.2.46'
        compileClasspath 'javax.persistence:javax.persistence-api:2.2'

        compileClasspath fileTree(dir:'libs',include:['*.jar'])
    }

//自定义环境 start
    def env = System.getProperty("ENV") ?: (System.getenv("ENV") ?: "dev")
    println(env)
    sourceSets {
        main {
            resources {
                srcDirs = ["src/main/resources", "src/main/profile/$env", "src/main/java"]
            }
        }
    }
//自定义环境 end

}
// 如果不使用spring boot plugin，也可以使用spring boot dependency management，只需要导入SpringBootPlugin类的BOM_COORDINATES常量
//dependencyManagement {
//	imports {
//		mavenBom org.springframework.boot.gradle.plugin.SpringBootPlugin.BOM_COORDINATES
//	}
//}

//如果module中名称有包含api的，则加入下面的内容
configure(subprojects.findAll {it.name.contains('api')}) {
    apply plugin: 'war'
    apply plugin: 'application'
//    apply plugin: 'org.springframework.boot.experimental.thin-launcher'

    springBoot {
        buildInfo()
    }

//    war {
//        manifest {
//            attributes("Implementation-Title": "Gradle")
//        }
//    }

//    task createPom {
//        doLast {
//            pom {
//                withXml(dependencyManagement.pomConfigurer)
//            }.writeTo("build/resources/main/META-INF/maven/${project.group}/${project.name}/pom.xml")
//        }
//    }
//
//    thinResolvePrepare {
//        into new File("${buildDir}/thin/deploy")
//    }
//
//    jar.dependsOn = [createPom]


    dependencies {
//    providedRuntime 'org.springframework.boot:spring-boot-starter-tomcat'
//        providedRuntime 'org.springframework.boot:spring-boot-starter-jetty'
    }

}

project(':data') {
    dependencies {
        compile(project(":tools"))
    }
}
project(':gateway-api') {
    dependencies {
        compile(project(":tools"))
        compile(project(":data"))
        compileClasspath project(path:":tools", configuration: 'parentClasspath')
        compileClasspath project(path:":data", configuration: 'parentClasspath')
    }
}
