gradle 基本构建配置

参考:

http://blog.jobbole.com/84471/


自定义几个简单脚本

生成jar

build.gradle

apply plugin: 'java'
apply plugin: 'eclipse'


repositories {
    mavenCentral()
}

dependencies { 
   testCompile group: 'junit', name: 'junit', version: '4.+'
}

jar {
manifest {
attributes 'Main-Class': 'idet.rui.user.Hello'
}
}





package idet.rui.user;

public class Hello {

	public static void main(String[] args) {
		System.out.println("hello world");
		
		
	}

}

java -jar idet.jar  会输出


多项目

settings.gradle

include "app", "core","rui-test"

build.gradle

subprojects {
	apply plugin: 'java'
	apply plugin: 'eclipse'
    repositories {
         mavenCentral()
    }
}

allprojects {
    //Add configuration here
}


project(':rui-test') {
	dependencies{
		 compile 'junit:junit:4.11'
	}
}

project(':core') {
	dependencies{
		 testCompile project(':rui-test') 
	}
}

project(':app') {
	dependencies{
	    testCompile project(':rui-test') 
	    compile 'log4j:log4j:1.2.17'     	
	}
}


------------------------------------------------------------------

一个简单项目 gradle和jetty结合

项目github   https://github.com/liangrui1988/gradleSimpleDome

def SpringVersion = '4.0.1.RELEASE'
def JettyVersion = '8.1.14.v20131031'

apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'war'


// gradle 自已用的
buildscript {
        repositories {
		     maven { url "http://10.12.0.110:8081/nexus/content/groups/public/" }
             mavenCentral()
        }
        dependencies {
            // classpath "net.saliman:gradle-cobertura-plugin:2.2.2"
        }
}

// JVM 版本号要求
sourceCompatibility = 1.7
targetCompatibility = 1.7  

repositories {
    maven { url "http://10.12.0.110:8081/nexus/content/groups/public/" }
    mavenCentral()
}


[compileJava, compileTestJava]*.options*.encoding = "UTF-8"


configurations {
     // 所有需要忽略的包定义在此
	all*.exclude group: 'commons-logging', module: 'commons-logging'
}
	
//最终的 Jar 包名,如果没设置,默认为 [baseName]-[appendix]-[version]-[classifier].[extension]
archivesBaseName = "gradle-test-6.6.6.jar"
	
dependencies { 
   testCompile group: 'junit', name: 'junit', version: '4.+'    
   compile 'org.slf4j:slf4j-api:1.7.5'
   compile 'org.slf4j:jcl-over-slf4j:1.7.5'
   compile 'ch.qos.logback:logback-classic:1.0.13'
   compile 'org.apache.commons:commons-lang3:3.1'
   compile 'org.apache.httpcomponents:httpclient:4.3.4'
   compile 'org.apache.httpcomponents:httpmime:4.3.4'
   compile "org.eclipse.jetty:jetty-jsp:${JettyVersion}"
   compile "org.eclipse.jetty:jetty-webapp:${JettyVersion}"
   compile "org.eclipse.jetty:jetty-servlet:${JettyVersion}"
	compile "javax.servlet:javax.servlet-api:3.1.0"
	compile "javax.servlet.jsp:jsp-api:2.2.1-b03"
	compile "javax.servlet.jsp.jstl:javax.servlet.jsp.jstl-api:1.2.1" 
}

//Java 插件已经向项目添加了 compileJava任务和processResources任务,并且配置了这两个任务的destinationDir属性
// 更改插件的默认设置
processResources << {
        file("$destinationDir/version.properties").text = 'version=' + project.version
    }

task copyLib(type: Sync, dependsOn: jar) {
		from jar.archivePath
		from configurations.compile
		into 'build/deploy'
	}
	
	task copyWebapp(type: Sync) {
		from 'src/main/webapp'
		into 'build/deploy/webapp'
	}
	
//task deploy(type: Sync, dependsOn: jar) 
task deploy(dependsOn: [copyLib,copyWebapp])



 // 显示当前项目下所有用于 compile 的 jar.
task listJars(description: 'Display all compile jars.') << {
    configurations.compile.each { File file -> println file.name }
}





package idet.rui.user;

import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.nio.SelectChannelConnector;
import org.eclipse.jetty.util.thread.ExecutorThreadPool;
import org.eclipse.jetty.webapp.WebAppContext;

public class SimpleMain {

	public static void main(String[] args) throws Exception {
		Server server = new Server();
		SelectChannelConnector connector = new SelectChannelConnector();

		// 设置线程
		server.setThreadPool(new ExecutorThreadPool());
		// 端口
		connector.setPort(9808);
		// 设置handler
		//项目目录名/src/main/webapp
		//lib/webapp
		server.setHandler(new WebAppContext("src/main/webapp", "/"));
		// 连接器
		server.addConnector(connector);
		server.start();
	}
}


访问页面成功


linux 上可以用sh 启动脚本

run.sh

#!/bin/bash
PATH_LIB=./lib
CLASSPATH=../etc

for jar in `ls $PATH_LIB/*.jar`
do
      CLASSPATH="$CLASSPATH:""$jar"
done

#        ARGS="$ARGS"" -Djava.rmi.server.hostname="
#        ARGS="$ARGS"" -Dcom.sun.management.jmxremote.port=8990"
#        ARGS="$ARGS"" -Dcom.sun.management.jmxremote.authenticate=false" 
#        ARGS="$ARGS"" -Dcom.sun.management.jmxremote.ssl=false" 
#        ARGS="$ARGS"" -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=8004" 

exec -a 项目目录 java -server -Xms64m -Xmx64m -XX:PermSize=16m -XX:MaxPermSize=128m -XX:+PrintGCDetails -XX:+PrintGCTimeStamps -XX:+PrintHeapAtGC -Xloggc:/srv/server/pro-web/work/gc.log $ARGS -classpath "$CLASSPATH" xx.xx.xx.WebMain 9809 >> work/stdout.log


在结合supervisor 管理启动脚本


不错的文档参考

http://my.oschina.net/zjzhai/blog/220028?fromerr=pFWeJprg

http://www.tuicool.com/articles/ZBJBjej

https://docs.gradle.org/current/dsl/org.gradle.api.initialization.Settings.html


task >>>>>>有时间补上


  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值