apply plugin: 'java' tasks.withType(JavaCompile){ options.encoding = 'UTF-8' destinationDir = file('build/classes/2') } //指定构建的jdk版本 sourceCompatibility=1.5 def jarname="fine-third-10.0.jar" def classesDir='build/classes/2' //解压lib下的jar到classes文件夹 jar{ baseName="fine-third_2-10.0" } def srcDir="." //设置源码路径 sourceSets{ main{ java{ srcDirs=[ "${srcDir}/fine-aspectj/src", "${srcDir}/fine-spring/src", "${srcDir}/fine-spring/resources" ] } } } sourceSets.main.output.classesDir = file('build/classes/2') repositories{ mavenCentral() } //获取什么分支名 FileTree files =fileTree(dir:'./',include:'build.*.gradle') def buildDir=files[0].path.substring(0,files[0].path.lastIndexOf ('/')) def branchName=buildDir.substring(buildDir.lastIndexOf ('/')+1) //指定依赖 dependencies{ compile fileTree(dir:"${srcDir}/fine-aspectj/lib",include:'**/*.jar') compile fileTree(dir:"${srcDir}/fine-spring/lib",include:'**/*.jar') compile fileTree(dir:"${srcDir}/build/libs/",include:'**/*.jar') compile fileTree(dir:"../../finereport-lib-base/${branchName}",include:'**/*.jar') compile fileTree(dir:"../../finereport-lib-other/${branchName}",include:'**/*.jar') testCompile 'junit:junit:4.12' } //指明无法编译文件所在路径 def dataContent ={def dir -> copySpec{ from ("${dir}"){ exclude '**/.setting/**','.classpath','.project','**/*.java','**/*.db','**/*.g','**/package.html' } } } task copyFiles(type:Copy,dependsOn:'compileJava'){ copy{ println "------------------------------------------------copyfiles" with dataContent.call("${srcDir}/fine-spring/src") with dataContent.call("${srcDir}/fine-spring/resources") into "${classesDir}" } } jar.dependsOn copyFiles