-
Notifications
You must be signed in to change notification settings - Fork 11
/
build.gradle
223 lines (184 loc) · 6.85 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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
buildscript {
repositories {
mavenCentral()
maven { url "https://plugins.gradle.org/m2/" }
}
}
plugins {
id 'jacoco'
id 'org.sonarqube' version '2.8'
}
group 'me.sunlan'
version '1.0-SNAPSHOT'
apply plugin: 'java'
apply plugin: 'groovy'
apply plugin: 'antlr'
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
// added duplicatesStrategy for tasks with Jar to avoid: Execution failed for task ':jar'.: Entry org/codehaus/groovy/antlr/java/JavaLexer$1.class is a duplicate but no duplicate handling strategy has been set.
tasks.withType(Jar).all {
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
}
tasks.withType(JavaCompile) {
options.encoding = 'UTF-8'
}
tasks.withType(GroovyCompile) {
groovyOptions.encoding = 'UTF-8'
}
repositories {
flatDir { dirs("lib") }
mavenCentral()
maven { url 'https://oss.sonatype.org/content/repositories/snapshots' }
maven { url 'https://oss.jfrog.org/oss-snapshot-local/' }
}
generateGrammarSource {
maxHeapSize = '1g'
outputs.cacheIf { true }
final PARSER_PACKAGE_NAME = 'org.apache.groovy.parser.antlr4'
arguments += ["-visitor", "-no-listener", "-package", PARSER_PACKAGE_NAME]
doLast {
def parserFilePattern = 'Groovy*'
def outputPath = generateGrammarSource.outputDirectory.canonicalPath
def parserPackagePath = "${outputPath}/${PARSER_PACKAGE_NAME.replace('.', '/')}"
file(parserPackagePath).mkdirs()
copy {
from outputPath
into parserPackagePath
include parserFilePattern
}
delete fileTree(outputPath) {
include parserFilePattern
}
}
}
compileJava.dependsOn generateGrammarSource
configurations {
antlr2
}
ext {
asmVersion = '9.6'
antlr4Version = '4.13.1.5'
groovyVersion = '4.0.16'
junitVersion = '4.13.2'
antlrVersion = '2.7.7'
antVersion = '1.10.11'
}
dependencies {
antlr "me.sunlan:antlr4:$antlr4Version"
implementation "org.ow2.asm:asm:$asmVersion"
implementation "org.ow2.asm:asm-analysis:$asmVersion"
implementation "org.ow2.asm:asm-commons:$asmVersion"
implementation "org.ow2.asm:asm-tree:$asmVersion"
implementation "org.ow2.asm:asm-util:$asmVersion"
implementation "org.apache.groovy:groovy:$groovyVersion"
implementation "org.apache.groovy:groovy-test:$groovyVersion"
implementation "org.apache.groovy:groovy-console:$groovyVersion"
implementation "antlr:antlr:$antlrVersion"
antlr2 "org.apache.ant:ant-antlr:$antVersion"
testImplementation "junit:junit:$junitVersion"
}
ext.generatedDirectory = "${buildDir}/generated/sources"
sourceSets {
main {
java {
srcDir "$generatedDirectory/antlr2/src/main"
}
groovy {
srcDir "$generatedDirectory/antlr2/src/main"
}
}
antlr2 {
resources {
srcDirs = ['src/main/antlr2']
}
}
}
task generateLegacyGrammarSource {
outputs.cacheIf { true }
description = 'Ensure all the Antlr2 generated files are up to date.'
ext.antlrDirectory = "$projectDir/src/main/antlr2/org/codehaus/groovy/antlr"
ext.javaParserDirectory = "$ext.antlrDirectory/java"
ext.genPath = "$generatedDirectory/antlr2/src/main/org/codehaus/groovy/antlr"
ext.groovyOutDir = "$ext.genPath/parser"
ext.javaOutDir = "$ext.genPath/java"
inputs.dir(antlrDirectory)
outputs.dir(groovyOutDir)
outputs.dir(javaOutDir)
doFirst {
new File(groovyOutDir).mkdirs()
new File(javaOutDir).mkdirs()
ant {
taskdef(name: 'antlr2',
classname: 'org.apache.tools.ant.taskdefs.optional.ANTLR',
classpath: configurations.antlr2.asPath)
antlr2(target: "$ext.antlrDirectory/groovy.g", outputdirectory: ext.groovyOutDir) {
classpath path: configurations.compileClasspath.asPath
}
antlr2(target: "$ext.javaParserDirectory/java.g", outputdirectory: ext.javaOutDir) {
classpath path: configurations.compileClasspath.asPath
}
}
}
}
compileJava.dependsOn generateLegacyGrammarSource
wrapper {
gradleVersion = '7.4.2'
}
tasks.register("console", JavaExec) {
jvmArgs += ["-Dgroovy.attach.groovydoc=true"]
main = 'groovy.console.ui.Console'
classpath = sourceSets.main.runtimeClasspath
}
test {
def commonJvmArgs = ['-ea', "-Xms512m", "-Xmx2g", "-XX:MaxMetaspaceSize=512m", "-XX:+UseG1GC", "-XX:+UnlockDiagnosticVMOptions", "-XX:+DebugNonSafepoints", "-Dgroovy.antlr4.cache.threshold=0", "-Dgroovy.permissive.property.access=true", "-Duser.language=en"]
if (rootProject.hasProperty('async.profiler.agentpath')) {
commonJvmArgs << "-agentpath:${rootProject.property('async.profiler.agentpath')}=start,event=cpu,width=3600,file=build/reports/profile-${System.nanoTime()}.svg"
}
jvmArgs(*commonJvmArgs)
def headless = System.properties['java.awt.headless']
if (headless == 'true') {
systemProperties 'java.awt.headless': 'true'
}
forkEvery = 0
maxParallelForks = isRunningOnCI() ? 1 : Runtime.runtime.availableProcessors()
scanForTestClasses = true
ignoreFailures = false
testLogging {
events /*"passed",*/ "skipped", "failed", "standardOut" /*, "standardError"*/
afterSuite { desc, result ->
if (!desc.parent) {
println "Test results for ${project.name}: ${result.resultType} (${result.testCount} tests, ${result.successfulTestCount} passed, ${result.failedTestCount} failed, ${result.skippedTestCount} skipped), forkEvery: ${forkEvery}, maxParallelForks: ${maxParallelForks}"
}
}
}
}
jacocoTestReport {
reports {
xml.enabled true
}
}
plugins.withType(JacocoPlugin) {
tasks["test"].finalizedBy 'jacocoTestReport'
}
logger.lifecycle "Detected ${isRunningOnCI() ? 'Continuous Integration environment' : 'development environment'}"
boolean isRunningOnCI() {
new File('.').absolutePath =~ /teamcity|jenkins|hudson|travis|circleci|ubuntu/
}