gradle 打包 groovy 的配置

文章目录
  1. gradle 打包 groovy 的配置
  2. 执行 groovy 脚本

主题:

  • 如何使用 gradle 打包 groovy 代码(jar包)
  • 执行时如何传递参数

gradle 打包 groovy 的配置

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
def name='requirement-dashboard-v0.1'
def appMainClass = 'ProductRequirementManagement'
apply plugin: "groovy"

jar {
baseName "${name}"
from {
configurations.runtime.collect{zipTree(it)}
}
exclude('logs/')
manifest {
attributes 'Main-Class': appMainClass
}
into('/')
}

repositories {
maven { url "http://maven.aliyun.com/nexus/content/groups/public/"}
}

dependencies {
compile "org.apache.poi:poi:3.15"
compile "org.apache.poi:poi-ooxml:3.15"
compile "com.h2database:h2:1.4.200"
compile 'ch.qos.logback:logback-classic:1.2.3'
compile "org.codehaus.groovy:groovy-all:2.5.11"
}

sourceSets {
main {
groovy {
srcDirs = ['src']
}
resources {
srcDir 'resources'
}
}
}

task runScript(type: JavaExec) {
description 'Run Groovy script'
main = appMainClass
classpath = sourceSets.main.runtimeClasspath
if (project.hasProperty('params')) {
args(params)
}
}

defaultTasks 'runScript'

执行 groovy 脚本

1
2
3
4
5
#默认执行 runScript task
gradle groovyScriptName
gradle runScript groovyScriptName
#指定参数 params
gradle groovyScriptName -Pparams=paramsValue