github项目地址
/mx342/luceneDemo
build.gradle示例一
plugins {id 'java'}//相当于maven的groupidgroup 'com.cyjz'//相当于maven的versionversion '1.0-SNAPSHOT'//maven中的artifactId相当于name,显示在settings.gradle里面//配置所有项目公共信息allprojects{//插件的类型,可以添加warapply plugin:'java'sourceCompatibility = 1.8//项目发布到仓库供其他人使用//3步,1.添加发布插件// apply plugin:'maven-publish'// //2.添加发布url// //3.执行发布任务// publishing{// publishions{// myPublish(MavenPubliscation){//from compenents.java// }// }// repositories{// maven{//name "myRepo"//url ""// }// }// }}//配置子项目内容subprojects{repositories {//指定阿里云镜像maven{url '/nexus/content/groups/public/'}mavenCentral()}//依赖,类似于maven的dependenciesdependencies {//对子项目依赖的写法// compile project(":model")// compile 'org.hibernate:hibernate-core:3.6.3.Final'compile group: 'ch.qos.logback', name: 'logback-classic', version: '1.2.3'testCompile group: 'junit', name: 'junit', version: '4.12'// //解决冲突方式1,排除传递性依赖// compile('org.hibernate:hibernate-core:3.6.3.Final'){// exclude group:'org.slf4j',module:'slf4j-api'// }// //解决冲突方式2,强制指定一个版本// configurations.all{// resolutionStrategy{// force 'org.slf4j:slf4j-api:1.7.24'// }// }}}//发现版本冲突就构建失败,不要默认去选择最高版本的策略configurations.all{resolutionStrategy{failOnVersionConflict()}}//解决冲突方式2,强制指定一个版本configurations.all{resolutionStrategy{force 'org.slf4j:slf4j-api:1.7.24'}}repositories {//指定阿里云镜像maven{url '/nexus/content/groups/public/'}mavenCentral()}dependencies {//对子项目依赖的写法// compile project(":model")// compile 'org.hibernate:hibernate-core:3.6.3.Final'// compile group: 'ch.qos.logback', name: 'logback-classic', version: '1.2.3'testCompile group: 'junit', name: 'junit', version: '4.12'// //解决冲突方式1,排除传递性依赖// compile('org.hibernate:hibernate-core:3.6.3.Final'){// exclude group:'org.slf4j',module:'slf4j-api'// }// //解决冲突方式2,强制指定一个版本// configurations.all{// resolutionStrategy{// force 'org.slf4j:slf4j-api:1.7.24'// }// }}//创建文件夹目录的闭包def createDir = {path ->File dir = new File(path);if(!dir.exists()){dir.mkdirs()}}//初始化生成项目的任务task makeJavaDir(){def paths = ['src/test/test','src/test/web']doFirst{paths.forEach(createDir)}}task makeWebDir(){dependsOn 'makeJavaDir'def paths = ['src/main/webapp','src/test/webapp']doFirst{paths.forEach(createDir)}}//4个配置要求//1.所有项目中应用java插件//2.web子项目打包成war//3.所有项目添加logback日志功能//4.统一配置group和version
plugins {id 'maven-publish'}dependencies {testCompile group: 'junit', name: 'junit', version: '4.12'compile('org.springframework:spring-context:5.0.9.RELEASE'){exclude group:'commons-logging',module:'commons-logging'}compile 'org.springframework:spring-web:5.0.9.RELEASE'compile 'org.springframework:spring-webmvc:5.0.9.RELEASE'compile 'org.codehaus.janino:janino:3.0.10'compile 'commons-lang:commons-lang:2.6'compile 'commons-codec:commons-codec:1.11'compile 'com.alibaba:fastjson:1.2.49'compile 'ty:netty-all:4.1.29.Final'compile ('com.alibaba:dubbo:2.6.2'){exclude group: 'org.springframework', module: 'spring'exclude group: 'ty', module: 'netty'}compile 'org.apache.zookeeper:zookeeper:3.4.9'compile 'org.apache.curator:curator-framework:2.12.0'}publishing {publications {maven(MavenPublication) {from(components.java)}}}//设置资源编译的编码tasks.withType(JavaCompile) {options.encoding = 'UTF-8'}//资源目录的设置sourceSets {main {java {srcDir 'src/main/java'}resources {srcDir 'src/main/java/resources'}}test {java {srcDir 'test/java'}resources {srcDir 'test/resources'}}}//设置主程序入口def mainClassName = "com.cyjz.server.Main"//在某些场合,我们不需要依赖和src打在一个jar包,我们希望有个lib,然后我们的jar运行时,自动去找依赖jar。这样,就可以不用插件了task copyDependencies(type: Copy) {from configurations.runtimeinto 'build/libs/lib'}jar.dependsOn(copyDependencies)jar {manifest {attributes "Main-Class": "$mainClassName"attributes "Implementation-Title": project.name}//设置打包依赖的jar// from {// pile.collect { it.isDirectory() ? it : zipTree(it) }// }if (!configurations.runtime.isEmpty()) {manifest.attributes('Class-Path': '. lib/' + configurations.runtime.collect { it.name }.join(' lib/'))}//将静态资源打包出来processResources {from('src/main/java/resources'){include '**/*.*'}}}
gradle.properties示例
group = 'com.cyjz'version = '1.0-SNAPSHOT'
settings.gradle示例
rootProject.name = 'todoGradle'include 'model'include 'repository'include 'web'