/** * This is a kingdee cosmic template project that is automatically generated by the Kingdee cosmic development assistant plugin. * If there are any issues during the use process, you can provide feedback to the kingdee developer community website. * Website: https://developer.kingdee.com/developer?productLineId=29 * Author: liebin.zheng * Generate Date: 2024-11-22 11:26:47 */ plugins { id 'java' //https://docs.gradle.org/current/userguide/java_library_plugin.html#java_library_plugin id 'java-library' //id 'maven-publish' //https://docs.gradle.org/current/userguide/idea_plugin.html //id 'idea' //https://docs.gradle.org/current/userguide/eclipse_plugin.html //id 'eclipse' //id "org.sonarqube" version "3.5.0.2730" id 'org.hidetake.ssh' version '2.10.1' } apply from: 'config.gradle' def bos = ext.path.bos def trd = ext.path.trd def cus = ext.path.cus def biz = ext.path.biz def outputdir = ext.path.outputdir //所有工程共用的配置 allprojects { apply plugin: 'java' apply plugin: 'maven-publish' apply plugin: 'java-library' apply plugin: 'eclipse' apply plugin: 'idea' repositories{ mavenLocal() maven{ url'https://maven.aliyun.com/repository/public/'} maven{ url'https://maven.aliyun.com/repository/gradle-plugin'} mavenCentral() //maven { url 'https://repo.gradle.org/gradle/libs-releases' } //gradlePluginPortal() } group = System.getProperty('groupId') version = System.getProperty('version') def jdk_version = System.getProperty('jdk.version') sourceCompatibility = jdk_version targetCompatibility = jdk_version tasks.withType(JavaCompile) { options.encoding = "UTF-8" } dependencies { //implementation 'cn.hutool:hutool-all:5.8.20' //implementation 'ch.qos.logback:logback-classic:1.2.12' //implementation 'org.slf4j:log4j-over-slf4j:1.7.36' //implementation 'org.apache.logging.log4j:log4j-to-slf4j:2.20.0' //testImplementation platform('org.junit:junit-bom:5.9.1') //testImplementation 'org.junit.jupiter:junit-jupiter' } test { useJUnitPlatform() } java { withSourcesJar() //withJavadocJar() } Date now = new Date() String date = now.format('yyyy-MM-dd HH:mm:ss') String buildNum = now.format('yyyyMMddHHmmssSSS') String gitCommitShortHash = '' String gitBranch = '' try{ gitCommitShortHash = 'git log -1 --pretty=%H'.execute([], rootDir).text.trim() gitBranch = 'git branch --show-current'.execute([], rootDir).text.trim() } catch(Exception e){ println "warning: the commandline tools of git was not installed!" } jar { manifest { attributes 'Group-Name': project.group attributes 'Project-Name': project.name attributes 'Bundle-Version': project.version attributes 'Build-Num': buildNum attributes 'Build-Date': date attributes 'Build-Jdk': System.getProperty('java.version') attributes 'Built-By': 'Kingdee Cosmic Developer Tools' attributes 'Build-Tool': 'Gradle ' + project.gradle.gradleVersion attributes 'Git-Commit-Hash': gitCommitShortHash attributes 'Git-Branch': gitBranch attributes 'Cloud-Name': '' attributes 'App-Name': '' attributes 'Jar-Id': '' attributes 'Build-Image': '' } } } //所有子工程共用的配置 subprojects { dependencies { } //生成本工程jar包并拷贝到outputdir目录 task buildJar(type: Copy, dependsOn: build){ group 'build' description '生成本工程jar包并拷贝到outputdir目录' from 'build/libs' into outputdir exclude '*sources.jar','*javadoc.jar','*cosmic-debug*.jar' // 多语言配置文件放在src/main/java/resources目录下 // 其他配置文件放在src/main/resources目录下 processResources{ from('src/main/java'){ include '**/*.properties' } } } //生成本工程jar包并拷贝到拷贝到cus目录 task deployJar(type: Copy, dependsOn: buildJar){ group 'build' description '生成本工程jar包并拷贝到拷贝到cus目录' from outputdir into cus exclude '*sources.jar','*javadoc.jar','*cosmic-debug*.jar' } test.ignoreFailures true //打包成 zip //task buildZip(type: Zip, dependsOn: buildJar) { // group 'build' // description '将生成的 JAR 和相关文件打包成 zip' // archiveBaseName.set(project.name) // archiveVersion.set(version) // archiveExtension.set('zip') // // zip 的输出目录 // destinationDirectory.set(file("${buildDir}/zip")) // // 将 build/libs 下的 jar 包加入 zip(默认 buildJar 输出的目录) // from(outputdir) { // include '*.jar' // } // // 如果你还有其他资源需要打包,可以继续 from // // from('src/main/resources') { // // include '**/*' // // } // // 排除不需要的文件 // exclude '*sources.jar', '*javadoc.jar', '*cosmic-debug*.jar','zcgj-zcdev-base-common.jar','zcgj-zcdev-base-helper.jar' //} // 打包 zcdev-pr.zip task zipPr(type: Zip) { group 'build' description '将生成的 JAR 和相关文件打包成 zip' archiveBaseName.set(project.name) archiveVersion.set(version) archiveExtension.set('zip') archiveFileName = 'zcdev-pr.zip' // zip 的输出目录 destinationDirectory.set(file("${buildDir}/zip")) // 将 build/libs 下的 jar 包加入 zip(默认 buildJar 输出的目录) from(outputdir) { include 'zcgj-zcdev-zcdev-pr.jar' } // 如果你还有其他资源需要打包,可以继续 from // from('src/main/resources') { // include '**/*' // } // 排除不需要的文件 exclude '*sources.jar', '*javadoc.jar', '*cosmic-debug*.jar','zcgj-zcdev-base-common.jar','zcgj-zcdev-base-helper.jar' } // 打包 zcdev-fs.zip task zipFs(type: Zip) { group 'build' description '将生成的 JAR 和相关文件打包成 zip' archiveBaseName.set(project.name) archiveVersion.set(version) archiveExtension.set('zip') archiveFileName = 'zcdev-fs.zip' // zip 的输出目录 destinationDirectory.set(file("${buildDir}/zip")) // 将 build/libs 下的 jar 包加入 zip(默认 buildJar 输出的目录) from(outputdir) { include 'zcgj-zcdev-zcdev-fs.jar' } // 如果你还有其他资源需要打包,可以继续 from // from('src/main/resources') { // include '**/*' // } // 排除不需要的文件 exclude '*sources.jar', '*javadoc.jar', '*cosmic-debug*.jar','zcgj-zcdev-base-common.jar','zcgj-zcdev-base-helper.jar' } // 一次执行全部 zip(可选) task zipAll(dependsOn: ['buildJar','zipPr', 'zipFs']) { group 'build' description '同时生成 zcdev-pr.zip 和 zcdev-fs.zip' } // ======================= // SSH 服务器配置 // ======================= remotes { myServer { host = '172.31.195.232' user = 'jcroot' password = 'Nxjc#311.com' port = 22 knownHosts = allowAnyHosts // <—— 关键 } myServerPrd { host = '10.244.17.33' user = 'jcroot' password = 'Nxjc#311.com' port = 22 knownHosts = allowAnyHosts // <—— 关键 } } // ======================= // 上传任务 // ======================= def remoteTargetDir = "/kingdee/cosmic/nginx-appstatic/store/appstatic/appstore/cosmic/cus" def remoteTargetDirPrd = "/mnt/nfs/nginxshare/appstatic/appstore/cosmic/cus" // 上传 zcdev-pr.zip task testuploadPr(dependsOn: zipPr) { group 'deploy' description '打包 PR ZIP 并上传到远程服务器' doLast { ssh.run { session(remotes.myServer) { sftp { put from: "${buildDir}/zip/zcdev-pr.zip", into: remoteTargetDir } } } } } // 上传 zcdev-fs.zip task testuploadFs(dependsOn: zipFs) { group 'deploy' description '打包 FS ZIP 并上传到远程服务器' doLast { ssh.run { session(remotes.myServer) { sftp { put from: "${buildDir}/zip/zcdev-fs.zip", into: remoteTargetDir } } } } } // 一键上传全部 task a_testuploadAll(dependsOn: ['buildJar','zipPr', 'zipFs','testuploadPr', 'testuploadFs']) { group 'deploy' description '一次构建并上传 PR + FS zip' } //正式环境 // 上传 zcdev-pr.zip task PrduploadPr(dependsOn: zipPr) { group 'deploy' description '打包 PR ZIP 并上传到远程服务器' doLast { ssh.run { session(remotes.myServerPrd) { sftp { put from: "${buildDir}/zip/zcdev-pr.zip", into: remoteTargetDirPrd } } } } } // 上传 zcdev-fs.zip task PrduploadFs(dependsOn: zipFs) { group 'deploy' description '打包 FS ZIP 并上传到远程服务器' doLast { ssh.run { session(remotes.myServerPrd) { sftp { put from: "${buildDir}/zip/zcdev-fs.zip", into: remoteTargetDirPrd } } } } } // 一键上传全部 task PrduploadAll(dependsOn: ['buildJar','zipPr', 'zipFs','PrduploadPr', 'PrduploadFs']) { group 'deploy' description '一次构建并上传 PR + FS zip' } }