-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle
269 lines (232 loc) · 10.3 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
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
import groovy.transform.Memoized
/*
* Copyright ConsenSys 2023
*]
* Licensed 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.
*
* SPDX-License-Identifier: Apache-2.0
*/
buildscript {
repositories {
mavenLocal()
maven {
url "https://hyperledger.jfrog.io/artifactory/besu-maven/"
content { includeGroupByRegex('org\\.hyperledger\\.besu\\..*')}
}
mavenCentral()
maven {
url "https://artifacts.consensys.net/public/maven/maven/"
content { includeGroupByRegex('tech\\.pegasys\\..*')}
}
}
dependencies {
classpath 'tech.pegasys.internal.license.reporter:license-reporter:1.1.1'
}
}
plugins {
id 'com.diffplug.spotless' version '6.21.0'
id 'com.github.ben-manes.versions' version '0.46.0'
id 'com.github.hierynomus.license' version '0.16.1'
id 'io.spring.dependency-management' version '1.1.0'
id 'com.github.jk1.dependency-license-report' version '2.1'
id 'net.ltgt.errorprone' version '3.0.1' apply false
id 'com.github.johnrengelman.shadow' version '7.1.2'
id 'java'
id 'java-library'
}
apply plugin: 'java-library'
apply plugin: 'io.spring.dependency-management'
apply plugin: 'net.ltgt.errorprone'
apply plugin: 'jacoco'
apply from: "${rootDir}/gradle/versions.gradle"
apply from: "${rootDir}/gradle/check-licenses.gradle"
group = 'net.consensys.shomei.besu.plugin'
//version = '0.1.0'
version = project.hasProperty('releaseVersion') ? project.getProperty('releaseVersion') : 'snapshot'
sourceCompatibility = JavaVersion.VERSION_21
targetCompatibility = JavaVersion.VERSION_21
defaultTasks 'build', 'checkLicenses', 'javadoc', 'plugin'
repositories {
mavenLocal()
maven {
url "https://hyperledger.jfrog.io/artifactory/besu-maven/"
content { includeGroupByRegex('org\\.hyperledger\\.besu\\..*')}
}
mavenCentral()
maven {
url "https://artifacts.consensys.net/public/maven/maven/"
content { includeGroupByRegex('tech\\.pegasys($|\\..*)')}
}
maven {
url "https://dl.cloudsmith.io/public/libp2p/jvm-libp2p/maven/"
content { includeGroupByRegex('io\\.libp2p($|\\..*)') }
}
maven {
url "https://hyperledger.jfrog.io/artifactory/besu-maven/"
content { includeGroupByRegex('org\\.hyperledger\\.besu($|\\..*)') }
}
}
apply plugin: 'com.diffplug.spotless'
spotless {
java {
// This path needs to be relative to each project
target fileTree('.') {
include '**/*.java'
exclude '**/.gradle/**'
exclude '**/resources'
exclude '**/src/*/generated'
exclude '**/src/*/generated_tests'
exclude '**/build/**'
}
removeUnusedImports()
googleJavaFormat('1.17.0')
importOrder 'net.consensys', 'java', ''
trimTrailingWhitespace()
endWithNewline()
licenseHeaderFile "${rootDir}/gradle/spotless.java.license"
}
}
tasks.withType(JavaCompile) {
options.compilerArgs += [
'-Xlint:unchecked',
'-Xlint:cast',
'-Xlint:rawtypes',
'-Xlint:overloads',
'-Xlint:divzero',
'-Xlint:finally',
'-Xlint:static',
'-Werror',
]
options.forkOptions.jvmArgs += [
'--add-opens=jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED',
'--add-opens=jdk.compiler/com.sun.tools.javac.comp=ALL-UNNAMED',
'--add-opens=jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED'
]
options.errorprone {
enabled = !'true'.equalsIgnoreCase(System.getProperty('avt.disableErrorProne'))
disableWarningsInGeneratedCode
// Our equals need to be symmetric, this checker doesn't respect that
check('EqualsGetClass', net.ltgt.gradle.errorprone.CheckSeverity.OFF)
// We use the JSR-305 annotations instead of the Google annotations
check('ImmutableEnumChecker', net.ltgt.gradle.errorprone.CheckSeverity.OFF)
// Storing a lambda to avoid code duplication is not a bad thing
check('UnnecessaryLambda', net.ltgt.gradle.errorprone.CheckSeverity.OFF)
// Generates a ton of false alarms for no real value
check('LongDoubleConversion', net.ltgt.gradle.errorprone.CheckSeverity.OFF)
check('InlineMeSuggester', net.ltgt.gradle.errorprone.CheckSeverity.OFF)
check('CanIgnoreReturnValueSuggester', net.ltgt.gradle.errorprone.CheckSeverity.OFF)
check('DirectInvocationOnMock', net.ltgt.gradle.errorprone.CheckSeverity.OFF)
// We don't apply strict javadoc requirements yet
check('EmptyBlockTag', net.ltgt.gradle.errorprone.CheckSeverity.OFF)
check('MissingSummary', net.ltgt.gradle.errorprone.CheckSeverity.OFF)
// Force strict compliance with Java naming conventions
check('JavaCase', net.ltgt.gradle.errorprone.CheckSeverity.WARN)
// Check for uses of == that should probably be .equals
check('ReferenceComparison', net.ltgt.gradle.errorprone.CheckSeverity.WARN)
// These checks are imported from errorprone-checks dependency but not required in Teku
check('MethodInputParametersMustBeFinal', net.ltgt.gradle.errorprone.CheckSeverity.OFF)
check('BannedMethod', net.ltgt.gradle.errorprone.CheckSeverity.OFF)
check('ExperimentalCliOptionMustBeCorrectlyDisplayed', net.ltgt.gradle.errorprone.CheckSeverity.OFF)
// These are experimental checks that we want enabled
check('MissingBraces', net.ltgt.gradle.errorprone.CheckSeverity.WARN)
check('InsecureCryptoUsage', net.ltgt.gradle.errorprone.CheckSeverity.WARN)
check('WildcardImport', net.ltgt.gradle.errorprone.CheckSeverity.WARN)
check('DeduplicateConstants', net.ltgt.gradle.errorprone.CheckSeverity.WARN)
check('RedundantOverride', net.ltgt.gradle.errorprone.CheckSeverity.WARN)
check('RedundantThrows', net.ltgt.gradle.errorprone.CheckSeverity.WARN)
check('UnnecessarilyFullyQualified', net.ltgt.gradle.errorprone.CheckSeverity.WARN)
check('InitializeInline', net.ltgt.gradle.errorprone.CheckSeverity.WARN)
check('ClassName', net.ltgt.gradle.errorprone.CheckSeverity.WARN)
check('InterfaceWithOnlyStatics', net.ltgt.gradle.errorprone.CheckSeverity.WARN)
check('PackageLocation', net.ltgt.gradle.errorprone.CheckSeverity.WARN)
}
options.encoding = 'UTF-8'
}
dependencies {
// annotationProcessor generates the file META-INF/services/org.hyperledger.besu.plugin.BesuPlugin
annotationProcessor 'com.google.auto.service:auto-service'
compileOnly 'com.google.auto.service:auto-service-annotations'
compileOnly 'com.google.guava:guava'
errorprone("com.google.errorprone:error_prone_core")
errorprone("tech.pegasys.tools.epchecks:errorprone-checks")
api 'org.slf4j:slf4j-api'
implementation 'org.apache.logging.log4j:log4j-slf4j2-impl'
implementation 'org.apache.logging.log4j:log4j-core'
implementation 'org.hyperledger.besu.internal:rlp'
implementation 'org.hyperledger.besu:plugin-api'
implementation 'org.hyperledger.besu:besu-datatypes'
implementation 'info.picocli:picocli'
implementation 'io.vertx:vertx-web-client'
implementation 'io.vertx:vertx-web'
implementation 'com.fasterxml.jackson.core:jackson-databind'
implementation 'com.fasterxml.jackson.core:jackson-annotations'
testImplementation 'org.assertj:assertj-core'
testImplementation 'org.junit.jupiter:junit-jupiter'
testImplementation 'org.assertj:assertj-core'
testImplementation 'org.junit.jupiter:junit-jupiter-params'
testImplementation 'org.mockito:mockito-core'
testImplementation 'org.mockito:mockito-junit-jupiter'
testImplementation 'io.vertx:vertx-junit5'
}
apply plugin: 'java'
jar {
archiveBaseName = 'besu-shomei-plugin'
manifest {
attributes(
'Specification-Title': archiveBaseName.get(),
'Specification-Version': rootProject.version,
'Implementation-Title': archiveBaseName.get(),
'Implementation-Version': calculateVersion()
)
}
from { configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) } }
exclude 'META-INF/*.RSA', 'META-INF/*.SF', 'META-INF/*.DSA'
duplicatesStrategy(DuplicatesStrategy.INCLUDE)
}
test {
useJUnitPlatform()
}
task plugin(dependsOn: 'jar') {
group 'build'
description 'Alias for the jar task'
}
@Memoized
def calculateVersion() {
String version = rootProject.version
if (version.endsWith("-SNAPSHOT")) {
version = version.replace("-SNAPSHOT", "-dev-" + getCheckedOutGitCommitHash())
}
return version
}
def getCheckedOutGitCommitHash(length = 8) {
try {
def gitFolder = "$projectDir/.git/"
if (!file(gitFolder).isDirectory()) {
// We are in a submodule. The file's contents are `gitdir: <gitFolder>\n`.
// Read the file, cut off the front, and trim the whitespace.
gitFolder = file(gitFolder).text.substring(length).trim() + "/"
}
def takeFromHash = length
/*
* '.git/HEAD' contains either
* in case of detached head: the currently checked out commit hash
* otherwise: a reference to a file containing the current commit hash
*/
def head = new File(gitFolder + "HEAD").text.split(":") // .git/HEAD
def isCommit = head.length == 1 // e5a7c79edabbf7dd39888442df081b1c9d8e88fd
if (isCommit) return head[0].trim().take(takeFromHash) // e5a7c79edabb
def refHead = new File(gitFolder + head[1].trim()) // .git/refs/heads/master
refHead.text.trim().take takeFromHash
} catch (Exception e) {
logger.warn('Could not calculate git commit, using "xxxxxxxx" (run with --info for stacktrace)')
logger.info('Error retrieving git commit', e)
return "xxxxxxxx"
}
}