一、gradle与gradlewjava
gradle命令用的本地的gradle。而gradlew是包装器,经过gradle Wrapper容许在没有安装gradle的机器上进行gradle构建,能够自动下载定义好的grale版本,其余人不需预先安装gradle,能够保证编译环境统一。 缓存
二、使用gradlew时提示:“错误: 找不到或没法加载主类 org.gradle.wrapper.GradleWrapperMain”app
GradleWrapperMain位于gradle-wrapper.jar,gradlew没有找到该jar包。能够将gradle-wrapper.jar与gradle-wrapper.properties拷到项目的gradle/wrapper目录下。eclipse
|---gradle
|---wrapper
|---gradle-wrapper.jar
|---gradle-wrapper.properties
|---gradlew
|---gradlew.bat
三、设置缓存目录maven
能够设置环境变量GRADLE_USER_HOME为d:\repos\.gradle。测试
四、例子gradle
项目目录结构:ui
|---SimpleIM.net
|---IMServernetty
|---src
|---main
|---java
|---IMServer.java
|---db
|---DBManager.java
|---test
|---java
|---testDBManager.java
|---IMClient
|---settings.gradle
|---build.gradle
子项目定义在settings.gradle中:
include 'IMServer','IMClient'
build.gradle定义:
工程能够经过gradlew eclipse生成eclipse项目文件。
子项目是Java项目,从maven仓库中找依赖的jar包。
编译生成的java包带上版本0.0.1
针对子项目IMServer,生成的jar包为SimpleIMServer-0.0.1.jar
设置SimpleIMServer的主类为IMServer
编译依赖netty,测试的编译依赖junit
编译生成测试的jar包SimpleIMServer-test.jar
allprojects{ apply plugin:'eclipse' } subprojects{ apply plugin:'java' repositories { mavenCentral() } jar { version='0.0.1' } } project(':IMServer'){ archivesBaseName='SimpleIMServer' jar{ manifest.attributes 'Main-Class': 'IMServer' } dependencies{ compile 'io.netty:netty-all:4.1.9.Final' testCompile "junit:junit:4.9" } task testJar(type: Jar) { classifier = 'test' from sourceSets.test.output } artifacts { archives testJar } } task wrapper(type: Wrapper) { gradleVersion = '2.14.1' }