β

gradle 基础配置java工程

Harries Blog™ 27 阅读

JAVA APP 配置 build .gradle:

// builg.gradle update by wangqingsong on 20160711
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'maven'

group = "com.greatwqs"
version = "1.0-SNAPSHOT"
[compileJava, compileTestJava]*.options*.encoding = 'UTF-8'

repositories {
   mavenLocal()
   maven {
      // 私有仓库
      credentials {
         username 'admin'
         password 'password'
      }
      url "http://xxxxxxxxxxx:8081/nexus/content/groups/public/"
   }
   mavenCentral()
}

// 上传至中央仓库
uploadArchives {
   repositories {
      mavenDeployer {
         mavenLocal()
      }
   }
}

dependencies {
   compile "net.paoding:rose:1.2.2-SNAPSHOT"
   compile "net.paoding:rose-jade:1.2.2-SNAPSHOT"
   compile "org.slf4j:slf4j-log4j12:1.7.12"
   compile "com.google.guava:guava:18.0"
   compile "sslext:sslext:1.10-4"
   compile "org.json:json:20140107"
   compile "commons-beanutils:commons-beanutils:1.7.0"
   compile "com.google.code.gson:gson:2.2.4"
   compile "org.jsoup:jsoup:1.7.3"
   compile "org.apache.httpcomponents:httpclient:4.5.1"
   compile "org.apache.httpcomponents:httpclient-cache:4.5.1"
   compile "commons-httpclient:commons-httpclient:3.0.1"
   compile "dom4j:dom4j:1.6.1"
   compile "org.apache.commons:commons-lang3:3.3.2"
   compile "com.google.guava:guava:18.0"
   compile "redis.clients:jedis:2.7.2"
   compile "joda-time:joda-time:2.7"
   compile "com.thoughtworks.xstream:xstream:1.4.8"
   compile "xpp3:xpp3:1.1.4c"
   compile "xmlpull:xmlpull:1.1.3.1"
   compile "commons-codec:commons-codec:1.10"
   compile "commons-logging:commons-logging:1.1.3"
   compile "org.aspectj:aspectjweaver:1.6.9"
   compile fileTree(dir: 'libs', include: '*.jar')
}

// 导出项目中所有的jar到exported-libs目录, 用于部署时配置libs
task copyJars(type: Copy) {
   from configurations.runtime
   into 'exported-libs' 
}

// 创建maven风格的项目目录;
task "create-project-dirs" << {
   sourceSets*.java.srcDirs*.each { it.mkdirs() }
   sourceSets*.resources.srcDirs*.each { it.mkdirs() }
}

JAVA WEB 配置 build.gradle:

// builg.gradle 
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'maven'
apply plugin: 'war'

group = "com.greatwqs"
version = "1.0-SNAPSHOT"
sourceCompatibility = 1.7

eclipse.classpath.defaultOutputDir = file('src/main/webapp/WEB-INF/classes')
[compileJava, compileTestJava]*.options*.encoding = 'UTF-8'
sourceSets.main.resources.srcDir 'src/main/resources'
sourceSets.test.resources.srcDir 'src/test/resources'
sourceSets.main.java.srcDir 'src/main/java'
sourceSets.test.java.srcDir 'src/test/java'
 
[compileJava, compileTestJava]*.options*.encoding = 'UTF-8'

repositories {
   mavenLocal()
   maven {
      credentials {
         username 'admin'
         password 'passwod'
      }
      url "http://xxxxxxxxx:8081/nexus/content/groups/public/"
   }
   mavenCentral()
}

// 上传至中央仓库
uploadArchives {
   repositories {
      mavenDeployer {
         mavenLocal()
      }
   }
}

dependencies {
   compile "org.slf4j:slf4j-log4j12:1.7.12"
   compile "com.google.guava:guava:18.0"
   compile "sslext:sslext:1.10-4"
   compile "org.json:json:20140107"
   compile "commons-beanutils:commons-beanutils:1.7.0"
   compile "com.google.code.gson:gson:2.2.4"
   compile "org.jsoup:jsoup:1.7.3"
   compile "org.apache.httpcomponents:httpclient:4.5.1"
   compile "org.apache.httpcomponents:httpclient-cache:4.5.1"
   compile "commons-httpclient:commons-httpclient:3.0.1"
   compile "dom4j:dom4j:1.6.1"
   compile "org.apache.commons:commons-lang3:3.3.2"
   compile "com.google.guava:guava:18.0"
   compile "redis.clients:jedis:2.7.2"
   compile "joda-time:joda-time:2.7"
   compile "com.thoughtworks.xstream:xstream:1.4.8"
   compile "xpp3:xpp3:1.1.4c"
   compile "xmlpull:xmlpull:1.1.3.1"
   compile "commons-codec:commons-codec:1.10"
   compile "commons-logging:commons-logging:1.1.3"
   compile "commons-fileupload:commons-fileupload:1.3.3"
   compile fileTree(dir: 'libs', include: '*.jar')
   //系统提供的依赖
   providedCompile(
      "javax.servlet:javax.servlet-api:3.1.0",
      "javax.servlet.jsp:jsp-api:2.2.1-b03",
      "javax.servlet.jsp.jstl:javax.servlet.jsp.jstl-api:1.2.1"
   )
}

// 导出项目中所有的jar到exported-libs目录, 用于部署时配置libs
task copyJars(type: Copy) {
   from configurations.runtime
   into 'exported-libs'
}

// 创建maven风格的项目目录;
task "create-project-dirs" << {
   sourceSets*.java.srcDirs*.each { it.mkdirs() }
   sourceSets*.resources.srcDirs*.each { it.mkdirs() }
}

说明:

1. 创建maven 风格的项目目录: gradle create-project-dirs

2. 导出项目中所有的jar到exported-libs目录: gradle
copyJars

原文

http://greatwqs.iteye.com/blog/2423282

本站部分文章源于互联网,本着传播知识、有益学习和研究的目的进行的转载,为网友免费提供。如有著作权人或出版方提出异议,本站将立即删除。如果您对文章转载有任何疑问请告之我们,以便我们及时纠正。 PS:推荐一个微信公众号: askHarries 或者qq群:474807195,里面会分享一些资深架构师录制的视频录像:有Spring,MyBatis,Netty源码分析,高并发、高性能、分布式、微服务架构的原理,JVM性能优化这些成为架构师必备的知识体系。还能领取免费的学习资源,目前受益良多

转载请注明原文出处: Harries Blog™ » gradle 基础配置java工程

作者:Harries Blog™
追心中的海,逐世界的梦
原文地址:gradle 基础配置java工程, 感谢原作者分享。

发表评论