Newer
Older
common / build.gradle
steven on 27 Aug 3 KB 配置修改
import java.text.SimpleDateFormat

plugins {
    id 'org.springframework.boot' version '2.4.5'
    id 'io.spring.dependency-management' version '1.0.11.RELEASE'
    id 'java'
    id 'maven'
}
// 是否存在参数
def isParameter = project.hasProperty('profile')
group = 'com.yn'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '1.8'
def artifactId = isParameter ? "yn-byx-common-".concat("$profile") : "yn-byx-common"

repositories {
    mavenLocal()
    mavenCentral()
    maven { url 'https://plugins.gradle.org/m2/' }
    maven { url 'http://maven.aliyun.com/nexus/content/groups/public/' }
}

dependencies {
    implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
    implementation 'org.springframework.boot:spring-boot-starter-data-elasticsearch'
    implementation 'org.springframework.boot:spring-boot-starter-data-mongodb'
    compileOnly 'org.projectlombok:lombok'
    annotationProcessor 'org.projectlombok:lombok'
    implementation group: 'javax.validation', name: 'validation-api', version: '2.0.1.Final'
    implementation group: 'io.springfox', name: 'springfox-swagger2', version: "2.7.0"
    implementation group: 'org.apache.commons', name: 'commons-lang3', version: '3.12.0'
}

test {
    useJUnitPlatform()
}


jar {
    manifest {
        attributes(
            "Manifest-Version": 1.0,
            'Pack-Person': getUserName(),
            'Package-Time': getCurrentTime(),
            'Git-Branch': getGitBranch(),
            'Git-CommitId': gitCommitId(),
            'Commit-Description': gitCommitDescription()
        )
    }
    enabled = true
}

//打包源代码
task sourcesJar(type: Jar, dependsOn: classes) {
    archiveBaseName = "$artifactId"
    archiveClassifier = 'sources'
    from sourceSets.main.allSource
}
// 获取最新提交的记录的commitId
def gitCommitId() {
    try {
        def commit = 'git rev-parse HEAD'.execute([], project.rootDir).text.trim()
        return commit ?: 'unknown'
    } catch (Exception e) {
        System.err.println("fail to get commit id, errMsg:" + e.getMessage())
        return 'unknown'
    }
}
// 获取最新提交的记录的描述
def gitCommitDescription() {
    try {
        def commit = 'git log -1 --pretty=format:"%s"'.execute([], project.rootDir).text.trim()
        return commit ?: 'unknown'
    } catch (Exception e) {
        System.err.println("fail to get CommitDescription, errMsg:" + e.getMessage())
        return 'unknown'
    }
}
// 获取当前分支名称
def getGitBranch() {
    try {
        def commit = 'git rev-parse --abbrev-ref HEAD'.execute([], project.rootDir).text.trim()
        return commit ?: 'unknown'
    } catch (Exception e) {
        System.err.println("fail to get Branch, errMsg:" + e.getMessage())
        return 'unknown'
    }
}
// 获取当前用户
static def getUserName() {
    return 'git config user.name'.execute().text.trim()
}
// 获取当前时间
static def getCurrentTime() {
    return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date())
}

artifacts {
    archives sourcesJar
}

install {
    repositories.mavenInstaller {
        pom.version = "$project.version"
        pom.artifactId = "$artifactId"
        pom.groupId = "$project.group"
    }
}

//上传到nexus
uploadArchives {
    repositories {
        mavenDeployer {
            repository(url: "http://120.76.99.226:8889/nexus/content/repositories/snapshots") {
                authentication(userName: "admin", password: "admin123")
            }
            pom.version = "$project.version"
            pom.artifactId = "$artifactId"
            pom.groupId = "$project.group"
        }
    }
}