forked from GoogleContainerTools/jib-extensions
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle
325 lines (282 loc) · 9.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
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
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
// define all versioned plugins here and apply in subprojects as necessary without version
plugins {
id 'com.github.sherter.google-java-format' version '0.9' apply false
id 'net.ltgt.errorprone' version '1.3.0' apply false
id 'net.researchgate.release' version '2.8.1' apply false
// apply so we can correctly configure the test runner to be gradle at the project level
id 'org.jetbrains.gradle.plugin.idea-ext' version '0.10'
// apply so that we can collect quality metrics at the root project level
id 'org.sonarqube' version '3.3'
}
// run tests in intellij using gradle test runner
idea.project.settings {
delegateActions {
delegateBuildRunToGradle = false
testRunner = 'GRADLE'
}
}
import net.ltgt.gradle.errorprone.CheckSeverity
subprojects {
group 'com.google.cloud.tools'
repositories {
mavenCentral()
}
// `java-library` must be applied before `java`. `java-gradle-plugin` in
// Gradle sub-projects auto applies `java-library`, so ensure `java-library`
// is applied first.
if (project.name.endsWith('-gradle')) {
apply plugin: 'java-library'
}
apply plugin: 'java'
apply plugin: 'checkstyle'
apply plugin: 'com.github.sherter.google-java-format'
apply plugin: 'net.ltgt.errorprone'
apply plugin: 'jacoco'
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
compileJava.options.encoding = 'UTF-8'
compileJava.options.compilerArgs += [ '-Xlint:deprecation' ]
compileTestJava.options.compilerArgs += [ '-Xlint:deprecation' ]
/* PROJECT DEPENDENCY VERSIONS */
// define all common versioned dependencies here
project.ext.dependencyStrings = [
GUAVA: 'com.google.guava:guava:30.1.1-jre',
JSR305: 'com.google.code.findbugs:jsr305:3.0.2', // transitively pulled in by GUAVA
JIB_CORE: 'com.google.cloud.tools:jib-core:0.20.0',
JIB_GRADLE: 'gradle.plugin.com.google.cloud.tools:jib-gradle-plugin:3.2.0',
// for Build Plan and Jib Plugins Extension API
JIB_GRADLE_EXTENSION: 'com.google.cloud.tools:jib-gradle-plugin-extension-api:0.4.0',
JIB_MAVEN_EXTENSION: 'com.google.cloud.tools:jib-maven-plugin-extension-api:0.4.0',
SPRING_BOOT: 'org.springframework.boot:spring-boot-gradle-plugin:2.3.1.RELEASE', // for Spring Boot Gradle extension
MAVEN_API: 'org.apache.maven:maven-plugin-api:3.8.2',
//test
TRUTH: 'com.google.truth:truth:1.1.3',
TRUTH8: 'com.google.truth.extensions:truth-java8-extension:1.1.3', // should match TRUTH version
JUNIT: 'junit:junit:4.13.2',
JUNIT_PARAMS: 'pl.pragmatists:JUnitParams:1.1.1',
MOCKITO_CORE: 'org.mockito:mockito-core:3.11.2',
SLF4J_API: 'org.slf4j:slf4j-api:1.7.30',
SYSTEM_RULES: 'com.github.stefanbirkner:system-rules:1.19.0',
]
/* PROJECT DEPENDENCY VERSIONS */
/* ERROR PRONE */
dependencies {
// NullAway errorprone plugin
annotationProcessor 'com.uber.nullaway:nullaway:0.8.0'
errorprone 'com.google.errorprone:error_prone_core:2.3.4'
// Using github.com/google/error-prone-javac is required when running on
// JDK 8. Remove when migrating to JDK 11.
if (System.getProperty('java.version').startsWith('1.8.')) {
errorproneJavac('com.google.errorprone:javac:9+181-r4173-1')
}
}
// Adds NullAway errorprone checks.
tasks.withType(JavaCompile) {
if (!name.toLowerCase().contains('test')) {
options.errorprone {
check('NullAway', CheckSeverity.ERROR)
option('NullAway:ExcludedFieldAnnotations', 'org.apache.maven.plugins.annotations.Component')
option('NullAway:AnnotatedPackages', 'com.google.cloud.tools')
}
}
}
/* ERROR PRONE */
/* GOOGLE JAVA FORMAT */
googleJavaFormat {
toolVersion = '1.7'
}
check.dependsOn verifyGoogleJavaFormat
/* GOOGLE JAVA FORMAT */
/* CHECKSTYLE */
checkstyle {
toolVersion = '8.29'
// use google checks from the jar
def googleChecks = resources.text.fromArchiveEntry(configurations.checkstyle[0], 'google_checks.xml').asString()
// set the location of the suppressions file referenced in google_checks.xml
configProperties['org.checkstyle.google.suppressionfilter.config'] = getConfigDirectory().file('checkstyle-suppressions.xml').get().toString()
// add in copyright header check on only java files (replace the last </module> in file)
def copyrightChecks = '''
<module name="RegexpHeader">
<property name="headerFile" value="${config_loc}/copyright-java.header"/>
<property name="fileExtensions" value="java"/>
<property name="id" value="header"/>
</module>
</module>
'''
googleChecks = googleChecks.substring(0, googleChecks.lastIndexOf('</module>')) + copyrightChecks
// this is the actual checkstyle config
config = resources.text.fromString(googleChecks)
maxErrors = 0
maxWarnings = 0
}
/* CHECKSTYLE */
/* TEST CONFIG */
tasks.withType(Test) {
reports.html.setDestination file("${reporting.baseDir}/${name}")
}
test {
testLogging {
showStandardStreams = true
exceptionFormat = 'full'
}
}
configurations {
tests
}
/* TEST CONFIG */
/* INTEGRATION TESTS */
sourceSets {
integrationTest {
java.srcDir file('src/integration-test/java')
resources.srcDir file('src/integration-test/resources')
}
}
configurations {
integrationTestImplementation.extendsFrom testImplementation
integrationTestRuntime.extendsFrom testRuntime
}
dependencies {
integrationTestImplementation sourceSets.main.output
integrationTestImplementation sourceSets.test.output
integrationTestImplementation configurations.compile
integrationTestImplementation configurations.testImplementation
integrationTestImplementation configurations.runtime
integrationTestImplementation configurations.testRuntime
}
// Integration tests must be run explicitly
task integrationTest(type: Test) {
testClassesDirs = sourceSets.integrationTest.output.classesDirs
classpath = sourceSets.integrationTest.runtimeClasspath
systemProperty '_JIB_DISABLE_USER_AGENT', true
}
integrationTest.dependsOn test
configurations {
integrationTests
}
/* INTEGRATION TESTS */
/* JAVADOC ENFORCEMENT */
// Fail build on javadoc warnings
tasks.withType(Javadoc) {
options.addBooleanOption('Xwerror', true)
}
assemble.dependsOn javadoc
/* JAVADOC ENFORCEMENT */
/* JAR */
jar {
manifest {
attributes 'Implementation-Title': project.name,
'Implementation-Version': version,
'Built-By': System.getProperty('user.name'),
'Built-Date': new Date(),
'Built-JDK': System.getProperty('java.version'),
'Built-Gradle': gradle.gradleVersion
}
}
/* JAR */
/* MAVEN CENTRAL RELEASES */
// for projects that release to maven central
project.ext.configureMavenRelease = {
apply plugin: 'maven-publish'
task sourceJar(type: Jar) {
from sourceSets.main.allJava
classifier 'sources'
}
task javadocJar(type: Jar, dependsOn: javadoc) {
from javadoc.destinationDir
classifier 'javadoc'
}
publishing {
publications {
mavenJava(MavenPublication) {
pom {
// to be filled by subproject after calling configure configureMavenRelease
// name = ''
// description = ''
url = 'https://github.com/GoogleContainerTools/jib-extensions'
inceptionYear = '2020'
licenses {
license {
name = 'The Apache License, Version 2.0'
url = 'http://www.apache.org/licenses/LICENSE-2.0.txt'
distribution = 'repo'
}
}
developers {
developer {
id = 'chanseokoh'
name = 'Chanseok Oh'
email = '[email protected]'
}
developer {
id = 'loosebazooka'
name = 'Appu Goundan'
email = '[email protected]'
}
developer {
id = 'mpeddada1'
name = 'Mridula Peddada'
email = '[email protected]'
}
}
scm {
url = 'https://github.com/GoogleContainerTools/jib-extensions'
connection = 'scm:https://github.com/GoogleContainerTools/jib-extensions.git'
developerConnection = 'scm:git://github.com/GoogleContainerTools/jib-extensions.git'
}
}
}
}
}
generatePomFileForMavenJavaPublication {
destination = file("${project.buildDir}/pom/${project.name}-${project.version}.pom")
}
// define a special install task that handles installing locally for manual testing
task install {
dependsOn publishToMavenLocal
}
// For kokoro sign and release to maven central
task prepareRelease(type: Copy) {
from jar
from sourceJar
from javadocJar
from generatePomFileForMavenJavaPublication
into "${project.buildDir}/release-artifacts"
dependsOn build
dependsOn cleanPrepareRelease
}
}
/* MAVEN CENTRAL RELEASE */
/* TEST COVERAGE */
jacocoTestReport {
reports {
xml.enabled true
html.enabled false
}
}
/* TEST COVERAGE */
}
/* SONARQUBE */
sonarqube {
properties {
property 'sonar.projectName', 'jib-extensions'
property 'sonar.projectKey', 'GoogleContainerTools_jib-extensions'
property 'sonar.host.url', 'https://sonarcloud.io'
property 'sonar.organization', 'googlecontainertools-1'
}
}
/* SONARQUBE */
/* LOCAL DEVELOPMENT HELPER TASKS */
tasks.register('dev') {
subprojects.each { subproject ->
subproject.tasks.classes.dependsOn subproject.tasks.googleJavaFormat
dependsOn subproject.tasks.check
dependsOn subproject.tasks.javadoc
}
}
tasks.register('devFull') {
dependsOn tasks.dev
subprojects.each { subproject ->
dependsOn subproject.tasks.integrationTest
}
}
/* LOCAL DEVELOPMENT HELPER TASKS */