forked from Contract-LIB/contract-lib-java
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle
110 lines (93 loc) · 2.96 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
/*
* This file was generated by the Gradle 'init' task.
*/
plugins {
id 'java-library'
id 'antlr'
id 'maven-publish'
id 'org.xbib.gradle.plugin.jflex' version '3.0.2'
id 'com.diffplug.spotless' version '6.25.0'
}
repositories {
mavenCentral()
}
configurations { antlr4 }
sourceSets {
main {
java {
srcDir "$buildDir/generated-src/antlr4/main/"
srcDir "$buildDir/generated-src/jflex/main/"
}
}
}
dependencies {
api 'org.antlr:antlr4:4.13.2'
antlr4 'org.antlr:antlr4:4.13.2'
testImplementation 'org.junit.jupiter:junit-jupiter:5.7.1'
testRuntimeOnly 'org.junit.platform:junit-platform-launcher'
}
group = 'org.contractlib'
version = '0.1-SNAPSHOT'
description = 'Contract-LIB'
java.sourceCompatibility = JavaVersion.VERSION_21
tasks.withType(Test).configureEach {
useJUnitPlatform()
}
java {
withJavadocJar()
withSourcesJar()
}
publishing {
publications {
maven(MavenPublication) {
from(components.java)
}
}
}
spotless {
java {
targetExclude "$buildDir/**"
/* To achieve (nearly) the same behavior as in the Maven build (formatter-maven-plugin), the eclipse version is
* fixed here. In addition, the same config file is used. The config file is taken from here:
* https://github.com/revelc/formatter-maven-plugin/blob/formatter-maven-plugin-2.24.1/src/main/resources/formatter-maven-plugin/eclipse/java.xml
* Should be updated if we don't need exactly identical behavior as with Maven ... */
eclipse('4.31').configFile("java.xml")
//indentWithSpaces(4)
//trimTrailingWhitespace()
}
}
def antlr4Output = "$buildDir/generated-src/antlr4/main/org/contractlib/antlr4parser"
tasks.register('runAntlr4', JavaExec) {
//see incremental task api, prevents rerun if nothing has changed.
inputs.files "src/main/antlr4/ContractLIB.g4"
outputs.dir antlr4Output
classpath = configurations.antlr4
mainClass.set("org.antlr.v4.Tool")
args = ["-visitor",
"-Xexact-output-dir", "-o", antlr4Output,
"-package", "org.contractlib.antlr4parser",
"src/main/antlr4/ContractLIB.g4"]
doFirst {
file(antlr4Output).mkdirs()
println("create $antlr4Output")
}
}
tasks.withType(JavaCompile).configureEach {
options.encoding = 'UTF-8'
}
compileJava.dependsOn runAntlr4
tasks.withType(Javadoc).configureEach {
options.encoding = 'UTF-8'
}
sourcesJar.dependsOn generateGrammarSource
sourcesJar.dependsOn runAntlr4
afterEvaluate {
// this needs to be done in afterEvaluate, otherwise "generateJflex" is unknown
compileJava.dependsOn generateJflex
sourcesJar.dependsOn generateJflex
// workaround: there is no public property to set the output in the extension, we need to directly refer to the
// task instead
tasks.named('generateJflex').configure {
target = file("$buildDir/generated-src/jflex/main")
}
}