-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuild.gradle
181 lines (151 loc) · 5.99 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
plugins {
id 'java'
id 'maven-publish'
id 'jacoco'
id "io.freefair.lombok" version "5.3.0"
id "com.github.hierynomus.license" version "0.15.0"
// Nemerosa Versioning Plugin for the build info
id "net.nemerosa.versioning" version "2.14.0"
}
jacoco {
// Use JaCoCo 0.8.6 for (experimental) support for Java 15 class files.
toolVersion = "0.8.6"
}
group = 'com.dumbdogdiner'
version = '2.1.0'
// License Plugin Options
license {
header = project.file('LICENSE_HEADER')
ext.year = Calendar.getInstance().get(Calendar.YEAR)
mapping("java", "SLASHSTAR_STYLE")
exclude "**/*.json" // Exclude JSON to keep the font width data valid
}
tasks.withType(JavaCompile) {
options.compilerArgs << "-Xlint:unchecked" << "-Xlint:deprecation" << "-XDignore.symbol.file"
}
configurations {
jaxDoclet
// give test dependencies access to compileOnly dependencies to emulate providedCompile
testImplementation.extendsFrom compileOnly
}
repositories {
mavenCentral()
jcenter()
maven { url 'https://oss.sonatype.org/content/repositories/snapshots' }
maven { url 'https://papermc.io/repo/repository/maven-public/' }
// Define a Ivy repo for the font width data (that way we don't need another plugin!)
def ddd_mc_font = ivy {
url 'https://dumbdogdiner.github.io/'
patternLayout { artifact '/[module]/[revision]/[classifier].[ext]'}
metadataSources { artifact() }
}
// Only use the Ivy repo for font width data - speeds up dependency resolution
exclusiveContent {
forRepositories(ddd_mc_font)
filter { includeGroup("dumbdogdiner") }
}
}
dependencies {
// Font width data (see above)
compile 'dumbdogdiner:mc-font-extractor:main:mojangles_width_data@json'
compileOnly 'org.projectlombok:lombok:1.18.18'
annotationProcessor 'org.projectlombok:lombok:1.18.18'
compileOnly 'com.destroystokyo.paper:paper-api:1.16.5-R0.1-SNAPSHOT'
compileOnly 'net.md-5:bungeecord-api:1.16-R0.5-SNAPSHOT'
implementation 'org.jetbrains:annotations:20.1.0'
implementation 'com.google.code.gson:gson:2.8.6'
implementation 'io.github.classgraph:classgraph:4.8.102'
implementation 'com.github.seancfoley:ipaddress:5.3.3'
// Tests - JUnit 5
testImplementation("org.junit.jupiter:junit-jupiter-params:5.7.1")
testImplementation("org.junit.jupiter:junit-jupiter-api:5.7.1")
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:5.7.1")
// Tests - Mocking Suite (eg. mocking Bukkit for tests)
testImplementation("org.mockito:mockito-core:3.7.7")
}
test {
useJUnitPlatform()
testLogging {
events "passed", "skipped", "failed"
// Show System.out for code ran by tests
showStandardStreams = true
}
finalizedBy jacocoTestReport // report is always generated after tests run
}
jacocoTestReport {
dependsOn test // tests are required to run before generating the report
reports {
xml.enabled true
html.enabled true
}
}
task sources(type: Jar, dependsOn: classes) {
archiveClassifier.set("sources")
from sourceSets.main.allSource
}
// Javadoc Fixes
// Some environments (such as the builder image) do not use UTF-8 as the default encoding!
// This sets UTF-8 as the encoding for the following tasks: delombok, compileJava, compileTestJava and javadoc.
delombok.encoding = "UTF-8"
compileJava.options.encoding = "UTF-8"
compileTestJava.options.encoding = "UTF-8"
javadoc.options.encoding = "UTF-8"
// Build Info
// Set the timestamp format
def dataBuildTimestamp = "yyyy-MM-dd'T'HH:mm:ss.SSSZ"
// Import the filter
import org.apache.tools.ant.filters.ReplaceTokens
// Define the map containing the tokens we want to replace
def tokensMap = [
BUILDINFO_VERSION: project.version,
BUILDINFO_DATEFORMAT: dataBuildTimestamp,
BUILDINFO_TIMESTAMP: new java.text.SimpleDateFormat(dataBuildTimestamp).format(new Date()),
BUILDINFO_COMMIT: versioning.info.commit,
BUILDINFO_BRANCH: versioning.info.branch,
BUILDINFO_ISDIRTY: versioning.info.dirty.toString()
]
// Create task to replace the tokens with their actual values
// NOTE: At the moment this replaces tokens *globally* (format eg. @BUILDINFO_COMMIT@ in source code)
task processSourceTokens(type: Sync) {
from sourceSets.main.java
into 'build/processed/src/main/java'
filter(ReplaceTokens, tokens: tokensMap)
// Pretty print the build info
println("\n----- StickyAPI Build Info -----\n")
tokensMap.each { println "${String.format("%1\$-" + 10 + "s", it.key.replace("BUILDINFO_", "").toLowerCase())}\t${it.value}" }
}
// Use the filter task as the input for compileJava
compileJava.source = processSourceTokens.outputs
// Font Width Info
task copyMCFontExtractor(type: Copy) {
def path = project.configurations.compile.find {it.name.startsWith("mc-font-extractor") }
println path
from file(path)
// into file("src/main/resources")
// - Please keep this comment for future reference.
// - This is how we would do this if we weren't also adding build info (see processSourceTokens)
destinationDir file("src/main/resources/generated/")
rename 'mc-font-extractor-main-mojangles_width_data.json', 'mojangles_width_data.json'
}
// Run the license formatter and font data copier before compiling the source code.
tasks.compileJava.dependsOn licenseFormatMain, licenseFormatTest, copyMCFontExtractor
tasks.build.dependsOn sources
tasks.publish.dependsOn build
publishing {
repositories {
maven {
name = "GitHubPackages"
url = uri("https://maven.pkg.github.com/DumbDogDiner/StickyAPI")
credentials {
username = project.findProperty("gpr.user") ?: System.getenv("GITHUB_ACTOR")
password = project.findProperty("gpr.key") ?: System.getenv("GITHUB_TOKEN")
}
}
}
publications {
gpr(MavenPublication) {
from(components.java)
artifact sources // Publish the output of the sources task
}
}
}