-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.gradle
333 lines (300 loc) · 11.5 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
326
327
328
329
330
331
332
333
/*
* Copyright (c) Siemens AG 2019-2025 ALL RIGHTS RESERVED
*/
plugins {
id 'java-library'
id 'jacoco'
id 'idea'
id 'checkstyle'
id 'signing'
id 'maven-publish'
id 'org.ajoberstar.grgit' version '4.1.1'
id 'org.barfuin.gradle.jacocolog' version '3.1.0'
id 'org.barfuin.gradle.taskinfo' version '2.2.0'
}
repositories {
mavenCentral()
}
import org.gradle.internal.jvm.Jvm
/*
* - - - - PROJECT METADATA - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
*/
ext {
buildTimestamp = new Date()
grgit.open(currentDir: project.rootDir).withCloseable { gitRepo ->
gitVersion = grgit.describe {
tags = true
match = ['v*']
always = true
}
gitHash = gitRepo.head().id
gitCleanBuild = gitRepo.status().isClean()
if (gitVersion.startsWith('v')) {
gitVersion = gitVersion.substring(1)
}
if (!gitCleanBuild) {
gitVersion += '-dirty'
}
}
publishedName = 'standard-bom'
website = 'https://sbom.siemens.io/'
codeRepo = 'https://github.com/siemens/standard-bom-java'
// The version of the spec we are currently implementing.
// Must correspond to an existing tag, without the leading 'v', or validation may fail later!
formatVersion = '3.0.0'
}
group = 'com.siemens.sbom.standardbom'
description = 'Standard BOM helper library for Java'
version = project.ext.gitVersion
project.gradle.taskGraph.whenReady { taskGraph ->
if (taskGraph.hasTask(':jar')) {
logger.lifecycle("\nBuilding ${project.name} ${project.version}")
}
}
/*
* - - - - DEPENDENCIES - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
*/
dependencies {
compileOnly group: 'com.google.code.findbugs', name: 'jsr305', version: '3.0.2'
api group: 'org.cyclonedx', name: 'cyclonedx-core-java', version: '10.1.0'
implementation group: 'org.slf4j', name: 'slf4j-api', version: '2.0.16'
testCompileOnly group: 'com.google.code.findbugs', name: 'jsr305', version: '3.0.2'
testImplementation group: 'junit', name: 'junit', version: '4.13.2'
testImplementation group: 'commons-io', name: 'commons-io'
testRuntimeOnly group: 'org.apache.logging.log4j', name: 'log4j-slf4j2-impl', version: '2.24.3'
}
/*
* - - - - INTELLIJ CONFIG - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
*/
idea.module {
downloadSources = true
downloadJavadoc = true
excludeDirs += file('.idea')
excludeDirs += file('_support')
excludeDirs += file('bin')
}
idea.project {
jdkName = JavaVersion.VERSION_1_8
languageLevel = JavaVersion.VERSION_1_8
}
/*
* - - - - COMPILATION - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
*/
java {
toolchain {
languageVersion.set(JavaLanguageVersion.of(8))
}
withSourcesJar()
withJavadocJar()
}
tasks.withType(JavaCompile).configureEach {
options.encoding = 'UTF-8'
options.compilerArgs << '-Xlint:unchecked' << '-Xlint:deprecation' << '-proc:none'
}
tasks.register('createVersionFile') {
group = LifecycleBasePlugin.BUILD_GROUP
description = 'Create a properties file containing the current version number.'
final File outFile = new File(temporaryDir, "standard-bom-version.properties")
outputs.file(outFile)
doLast {
Properties props = new Properties()
props.setProperty('clean', String.valueOf(rootProject.ext.gitCleanBuild))
props.setProperty('libGroup', rootProject.group)
props.setProperty('libName', rootProject.name)
props.setProperty('libVersion', rootProject.getVersion().toString())
props.setProperty('libWebsite', rootProject.ext.codeRepo)
props.setProperty('libDescription', rootProject.description)
props.setProperty('specName', rootProject.name)
props.setProperty('specVersion', rootProject.ext.formatVersion)
props.setProperty('specWebsite', rootProject.ext.website)
outFile.withPrintWriter('UTF-8', {
props.store(it, rootProject.name + ' version information')
})
}
}
tasks.named('processResources').configure { it.dependsOn(tasks.createVersionFile) }
sourceSets.main.resources.srcDir(tasks.createVersionFile.temporaryDir)
/*
* - - - - TESTS - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
*/
tasks.named('jacocoTestReport').configure {
it.dependsOn tasks.named('test')
reports {
html.required = true
xml.required = true
csv.required = false
}
}
tasks.named('check').configure { t ->
t.dependsOn tasks.named('jacocoTestReport')
}
/*
* - - - - ARTIFACTS - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
*/
tasks.named('jar').configure {
archiveBaseName.set(project.ext.publishedName)
into('META-INF') {
from 'LICENSE.md'
}
manifest {
attributes = [
'Manifest-Version' : '1.0',
'Specification-Title' : project.ext.publishedName,
'Specification-Vendor' : 'Siemens AG',
'Specification-Vendor-Id' : 'com.siemens',
'Specification-Version' : project.version,
'Implementation-Title' : project.ext.publishedName,
'Implementation-Vendor' : 'Siemens AG',
'Implementation-Vendor-Id' : 'com.siemens',
'Implementation-Version' : project.version,
'Implementation-SCM-Revision': project.ext.gitHash,
'Automatic-Module-Name' : 'com.siemens.sbom.standardbom',
'Website' : project.ext.website,
'Created-By' : "Gradle ${gradle.gradleVersion}",
'Built-By' : System.getProperty('user.name'),
'Build-Jdk' : Jvm.current().toString(),
'Build-Clean' : project.ext.gitCleanBuild
]
}
doFirst {
manifest {
attributes 'Build-Timestamp': rootProject.ext.buildTimestamp.toString()
}
}
}
sourcesJar {
archiveBaseName.set(project.ext.publishedName)
into('META-INF') {
from 'LICENSE.md'
}
afterEvaluate {
manifest.getAttributes().putAll(tasks.jar.manifest.attributes.findAll { it.key != 'Automatic-Module-Name' })
manifest {
attributes 'Build-Timestamp': project.ext.buildTimestamp.toString()
}
}
}
tasks.sourcesJar.dependsOn tasks.createVersionFile
javadocJar {
archiveBaseName.set(project.ext.publishedName)
into('META-INF') {
from 'LICENSE.md'
}
afterEvaluate {
manifest.getAttributes().putAll(tasks.jar.manifest.attributes.findAll { it.key != 'Automatic-Module-Name' })
manifest {
attributes 'Build-Timestamp': project.ext.buildTimestamp.toString()
}
}
}
/*
* - - - - JAVADOC - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
*/
tasks.named('javadoc').configure {
title = project.ext.publishedName + " v${project.version}"
options.locale = 'en'
options.encoding = 'UTF-8'
options.docEncoding = 'UTF-8'
options.charSet = 'UTF-8'
options.windowTitle = project.ext.publishedName
options.noDeprecated = true
options.header = project.ext.publishedName + " v${project.version}"
options.links('https://www.javadoc.io/doc/com.google.code.findbugs/jsr305/3.0.2/',
'https://docs.oracle.com/javase/8/docs/api/',
'https://cyclonedx.github.io/cyclonedx-core-java/')
excludes = ['com/siemens/sbom/standardbom/internal/**']
// javadoc does not inherit the proxy settings (https://issues.gradle.org/browse/GRADLE-1228)
if (System.properties['http.proxyHost'] != null) {
options.jFlags('-DproxyHost=' + System.properties['http.proxyHost'],
'-DproxyPort=' + System.properties['http.proxyPort'],
'-DproxyUser=' + System.properties['http.proxyUser'],
'-DproxyPassword=' + System.properties['http.proxyPassword'])
}
// workaround for JDK 9+: https://github.com/gradle/gradle/issues/11182
def currentJavaVersion = JavaVersion.current()
if (currentJavaVersion >= JavaVersion.VERSION_1_9) {
options.addStringOption("-release", "8")
}
}
/*
* - - - - CHECKSTYLE - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
*/
checkstyle {
toolVersion = '8.27'
showViolations = true
ignoreFailures = false
}
project.extensions.findByName('checkstyle').sourceSets.each { SourceSet s ->
Checkstyle task = (Checkstyle) tasks.findByName(s.getTaskName('checkstyle', null))
task.setSource(s.allSource)
getLogger().info('Reconfigured task \'' + task.name + '\' to include all files in sourceSet \'' + s.name + '\'')
}
dependencies {
checkstyle "com.puppycrawl.tools:checkstyle:${project.extensions.checkstyle.toolVersion}"
checkstyle group: 'com.github.sevntu-checkstyle', name: 'sevntu-checks', version: '1.37.0'
}
/*
* - - - - PUBLISHING - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
*/
publishing {
repositories {
maven {
name = 'localBuildDir'
url = project.layout.buildDirectory.dir('maven-repo-test')
}
if (project.hasProperty('SB_SONATYPE_USER') && project.hasProperty('SB_SONATYPE_PASSWORD')) {
maven {
name = 'mavenCentralStaging'
url = 'https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/'
credentials {
username = project.getProperty('SB_SONATYPE_USER')
password = project.getProperty('SB_SONATYPE_PASSWORD')
}
}
}
}
publications {
mavenJava(MavenPublication) {
from components.java
pom {
artifactId = project.ext.publishedName
name = project.ext.publishedName
description = (String) project.description
url = (String) project.ext.website
inceptionYear = '2019'
licenses {
license {
name = 'MIT'
url = 'https://raw.githubusercontent.com/siemens/standard-bom-java/refs/tags/v' +
project.version + '/LICENSE'
}
}
developers {
developer {
name = 'Thomas Jensen'
email = '[email protected]'
}
}
final String ga = '[email protected]:siemens/standard-bom-java.git'
scm {
connection = 'scm:git:' + ga
developerConnection = 'scm:git:' + ga
url = ga
}
}
}
}
}
if (!Boolean.parseBoolean(System.getenv('CI')) || project.hasProperty('signingKey')) {
signing {
if (Boolean.parseBoolean(System.getenv('CI'))) {
def signingKey = project.getProperty('signingKey')
def signingPassword = project.getProperty('signingPassword')
useInMemoryPgpKeys(signingKey, signingPassword)
}
else {
useGpgCmd() // use local GPG installation and agent
}
sign publishing.publications.mavenJava
}
}