import groovy.json.JsonSlurper apply plugin: 'java' apply plugin: 'idea' def baseProjectName = 'commons-cache-1.0' sourceCompatibility = 1.8 targetCompatibility = 1.8 def addRepo = new File(System.getProperty("user.home"), ".build_add.repo") repositories { //mavenCentral() flatDir { dirs "${System.env.JAVA_HOME}/jre/lib" } flatDir { dirs "${System.env.JAVA_HOME}/lib" } maven { url 'https://maven.aliyun.com/repository/central' } if (addRepo.exists()) { maven() { url addRepo.text.trim() } } } tasks.withType(JavaCompile) { options.encoding = "UTF-8" } // '-x test' skip unit test defaultTasks 'packjar' task packjarsrc { doLast { ant.jar(destfile: "${baseProjectName}-sources.jar") { fileset(dir: 'src/main/java', includes: '**/*.java') } } } packjarsrc.dependsOn build task packjar { doLast { def packtempclasses = "packtempclasses" def libs = ant.path { fileset(dir: 'build/libs', includes: '*.jar') } libs.list().each { ant.unzip(dest: packtempclasses, src: it) } new File(packtempclasses + "/commons-jar-version-build.txt").write(new Date().format("yyyyMMdd"), "UTF-8") ant.jar(destfile: "${baseProjectName}.jar") { fileset(dir: packtempclasses, includes: '**/*.*') } ant.delete(dir: packtempclasses) } } packjar.dependsOn packjarsrc dependencies { implementation files(fileTree(dir: 'lib', includes: ['*.jar'], excludes: ['*-sources.jar', '*-javadoc.jar'])) def buildJSON = new JsonSlurper().parseText(new File("build.json").text) if (buildJSON.repo != null && buildJSON.repo.dependencies != null) { buildJSON.repo.dependencies.each { implementation("${it}") } } testImplementation 'junit:junit:4.13.1' }