forked from eclipse-tractusx/tractusx-edc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle.kts
207 lines (184 loc) · 8 KB
/
build.gradle.kts
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
/*
* Copyright (c) 2023 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Apache License, Version 2.0 which is available at
* https://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
*/
import com.bmuschko.gradle.docker.tasks.image.DockerBuildImage
import com.github.jengelman.gradle.plugins.shadow.ShadowJavaPlugin
import java.time.Duration
plugins {
`java-library`
`maven-publish`
`jacoco-report-aggregation`
id("com.diffplug.spotless") version "6.20.0"
id("com.github.johnrengelman.shadow") version "8.1.1"
id("com.bmuschko.docker-remote-api") version "9.3.2"
id("io.github.gradle-nexus.publish-plugin") version "1.3.0"
}
val txScmConnection: String by project
val txWebsiteUrl: String by project
val txScmUrl: String by project
val annotationProcessorVersion: String by project
val metaModelVersion: String by project
buildscript {
repositories {
mavenLocal()
}
dependencies {
val edcGradlePluginsVersion: String by project
classpath("org.eclipse.edc.edc-build:org.eclipse.edc.edc-build.gradle.plugin:${edcGradlePluginsVersion}")
}
}
// include all subprojects in the jacoco report aggregation
project.subprojects.forEach {
dependencies {
jacocoAggregation(project(it.path))
}
}
allprojects {
apply(plugin = "org.eclipse.edc.edc-build")
repositories {
mavenCentral()
}
dependencies {
implementation("org.slf4j:slf4j-api:2.0.7")
// this is used to counter version conflicts between the JUnit version pulled in by the plugin,
// and the one expected by IntelliJ
testImplementation(platform("org.junit:junit-bom:5.10.0"))
constraints {
implementation("org.yaml:snakeyaml:2.1") {
because("version 1.33 has vulnerabilities: https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2022-1471.")
}
implementation("net.minidev:json-smart:2.5.0") {
because("version 2.4.8 has vulnerabilities: https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2023-1370.")
}
}
}
// configure which version of the annotation processor to use. defaults to the same version as the plugin
configure<org.eclipse.edc.plugins.autodoc.AutodocExtension> {
processorVersion.set(annotationProcessorVersion)
outputDirectory.set(project.buildDir)
// uncomment the following lines to enable the Autodoc-2-Markdown converter
// only available with EDC 0.2.1 SNAPSHOT
// additionalInputDirectory.set(downloadDir.asFile)
// downloadDirectory.set(downloadDir.asFile)
}
configure<org.eclipse.edc.plugins.edcbuild.extensions.BuildExtension> {
versions {
// override default dependency versions here
metaModel.set(metaModelVersion)
}
pom {
// this is actually important, so we can publish under the correct GID
groupId = project.group.toString()
projectName.set(project.name)
description.set("edc :: ${project.name}")
projectUrl.set(txWebsiteUrl)
scmConnection.set(txScmConnection)
scmUrl.set(txScmUrl)
}
swagger {
title.set((project.findProperty("apiTitle") ?: "Tractus-X REST API") as String)
description =
(project.findProperty("apiDescription")
?: "Tractus-X REST APIs - merged by OpenApiMerger") as String
outputFilename.set(project.name)
outputDirectory.set(file("${rootProject.projectDir.path}/resources/openapi/yaml"))
resourcePackages = setOf("org.eclipse.tractusx.edc")
}
}
configure<CheckstyleExtension> {
configFile = rootProject.file("resources/tx-checkstyle-config.xml")
configDirectory.set(rootProject.file("resources"))
//checkstyle violations are reported at the WARN level
this.isShowViolations = System.getProperty("checkstyle.verbose", "true").toBoolean()
}
// publishing to OSSRH is handled by the build plugin, but publishing to GH packages
// must be configured separately
publishing {
repositories {
maven {
name = "GitHubPackages"
url = uri("https://maven.pkg.github.com/${System.getenv("REPO")}")
credentials {
username = System.getenv("GITHUB_PACKAGE_USERNAME")
password = System.getenv("GITHUB_PACKAGE_PASSWORD")
}
}
}
}
// EdcRuntimeExtension uses this to determine the runtime classpath of the module to run.
tasks.register("printClasspath") {
doLast {
println(sourceSets["main"].runtimeClasspath.asPath)
}
}
}
// the "dockerize" task is added to all projects that use the `shadowJar` plugin
subprojects {
afterEvaluate {
if (project.plugins.hasPlugin("com.github.johnrengelman.shadow") &&
file("${project.projectDir}/src/main/docker/Dockerfile").exists()
) {
val agentFile = project.buildDir.resolve("opentelemetry-javaagent.jar")
// create task to download the opentelemetry agent
val openTelemetryAgentUrl = "https://github.com/open-telemetry/opentelemetry-java-instrumentation/releases/download/v1.27.0/opentelemetry-javaagent.jar"
val downloadOtel = tasks.create("downloadOtel") {
// only execute task if the opentelemetry agent does not exist. invoke the "clean" task to force
onlyIf {
!agentFile.exists()
}
// this task could be the first in the graph, so "build/" may not yet exist. Let's be defensive
doFirst {
project.buildDir.mkdirs()
}
// download the jar file
doLast {
val download = { url: String, destFile: File -> ant.invokeMethod("get", mapOf("src" to url, "dest" to destFile)) }
logger.lifecycle("Downloading OpenTelemetry Agent")
download(openTelemetryAgentUrl, agentFile)
}
}
//actually apply the plugin to the (sub-)project
apply(plugin = "com.bmuschko.docker-remote-api")
// configure the "dockerize" task
val dockerTask: DockerBuildImage = tasks.create("dockerize", DockerBuildImage::class) {
val dockerContextDir = project.projectDir
dockerFile.set(file("$dockerContextDir/src/main/docker/Dockerfile"))
images.add("${project.name}:${project.version}")
images.add("${project.name}:latest")
// specify platform with the -Dplatform flag:
if (System.getProperty("platform") != null)
platform.set(System.getProperty("platform"))
buildArgs.put("JAR", "build/libs/${project.name}.jar")
buildArgs.put("OTEL_JAR", agentFile.relativeTo(dockerContextDir).path)
inputDir.set(file(dockerContextDir))
}
// make sure always runs after "dockerize" and after "copyOtel"
dockerTask.dependsOn(tasks.named(ShadowJavaPlugin.SHADOW_JAR_TASK_NAME))
.dependsOn(downloadOtel)
}
}
}
nexusPublishing {
transitionCheckOptions {
maxRetries.set(120)
delayBetween.set(Duration.ofSeconds(10))
}
}
tasks.check {
dependsOn(tasks.named<JacocoReport>("testCodeCoverageReport"))
}