-
Notifications
You must be signed in to change notification settings - Fork 29
/
Copy pathbuild.gradle
179 lines (148 loc) · 5.04 KB
/
build.gradle
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
///////////////////////////////////////////////////////////////////////////////////////
//
// Gradle Template Summary
//
// Frequently Used Command:
// [ gradle ] Default task. same with 'gradle build'.
// [ gradle build ] Compile/test your code, and create a war file containing your main classes and resources.
//
////////////////////////////////////////////////////////////////////////////////////////
//Definition apply plugin
apply plugin: 'idea'
apply plugin: 'java'
apply plugin: 'maven'
//--------------------------------- Based setting for current project ---------------------------------
// Definition sourceCompatibility and targetCompatibility.
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
buildscript {
ext {
MODULE = "goodutils"
MAVEN_GROUP_ID = "goodutils"
MAVEN_ARTIFACT_ID = "goodutils"
MAVEN_VERSION = "0.1"
}
repositories {
mavenCentral()
}
configurations.all {
resolutionStrategy.cacheChangingModulesFor 0, 'seconds'
}
}
// Access maven center.
repositories {
mavenCentral()
}
// Definition source which should include.
sourceSets {
main {
java {
srcDir 'src'
}
resources {
srcDir 'src'
}
}
test {
java {
srcDir 'test'
}
}
}
//--------------------------------- Dependencies definition ---------------------------------
dependencies {
compile "org.bouncycastle:bcprov-jdk16:1.46"
//compile group: 'org.codehaus.groovy', name: 'groovy-all', version: '2.4.13'
compile "com.google.guava:guava:18.0"
compile "commons-io:commons-io:2.2"
compile "commons-cli:commons-cli:1.4"
compile "commons-lang:commons-lang:2.6"
compile "org.jsoup:jsoup:1.11.2"
compile "org.apache.httpcomponents:httpclient:4.5.5"
compile "org.apache.logging.log4j:log4j-api:2.5"
compile "org.apache.logging.log4j:log4j-core:2.5"
// https://mvnrepository.com/artifact/dom4j/dom4j
compile group: 'dom4j', name: 'dom4j', version: '1.6.1'
compile group: 'org.json', name: 'json', version: '20180130'
compile 'com.github.javaparser:javaparser-symbol-solver-core:3.6.5'
compile group: 'com.sun.tools.btrace', name: 'btrace-boot', version: '1.2.3'
compile group: 'com.sun.tools.btrace', name: 'btrace-agent', version: '1.2.3'
compile group: 'com.sun.tools.btrace', name: 'btrace-client', version: '1.2.3'
compile group: 'commons-cli', name: 'commons-cli', version: '1.4'
compile "org.apache.httpcomponents:httpasyncclient:4.1.4"
compile "org.apache.httpcomponents:httpcore-nio:4.4.10"
// Include non maven standard layout file into war
testCompile(
"junit:junit:4.11",
)
}
// Define manifest
ext.sharedManifest = manifest {
attributes(
'Modlue': "${MODULE}",
'Implementation-Title': "${project.name}",
'Built-Date': new Date().getDateTimeString(),
'Built-With': "gradle-${project.getGradle().getGradleVersion()}, groovy-${GroovySystem.getVersion()}",
'Created-By': 'Java ' + System.getProperty('java.version') + ' (' + System.getProperty('java.vendor') + ')'
)
}
//--------------------------------- Specific Tasks ---------------------------------
/*
* Override jar task addition attributes
*/
jar {
manifest = project.manifest {
from sharedManifest
}
}
task printDependencies << {
String projectName = project.getProperties().get("name")
BufferedWriter bw = null
try {
File file = new File(projectName + "-dependencies.txt")
bw = new BufferedWriter(new FileWriter(file))
configurations.runtime.resolvedConfiguration.resolvedArtifacts.each { artifact ->
def id = artifact.moduleVersion.id
bw.writeLine(String.format("%-30s\t%-30s\t%s", id.group, id.name, id.version))
println "group: ${id.group}, name: ${id.name}, version: ${id.version}"
}
println "Dependencies written to " + file.getCanonicalPath()
}
finally {
if (bw != null) {
bw.close()
}
}
}
/**
* fatjar demo
*/
task fatjar(type: Jar) {
manifest {
attributes 'Implementation-Title': project.name,
'Implementation-Version': '1.0'
}
baseName = project.name
from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } }
with jar
exclude 'META-INF/*.RSA', 'META-INF/*.SF','META-INF/*.DSA'
}
defaultTasks 'clean','test','jar'
task build (overwrite: true ) {
dependsOn = ['clean','test','jar']
test.mustRunAfter clean
jar.mustRunAfter test
}
task devbuild {
dependsOn = ['clean','jar']
jar.mustRunAfter clean
}
//Define the test task
test {
ignoreFailures = true
reports.html.destination = file("$buildDir/test-reports")
}
task createJavaProject << {
sourceSets*.java.srcDirs*.each { it.mkdirs() }
sourceSets*.resources.srcDirs*.each { it.mkdirs()}
}