-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.gradle.kts
More file actions
170 lines (145 loc) · 5.12 KB
/
Copy pathbuild.gradle.kts
File metadata and controls
170 lines (145 loc) · 5.12 KB
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
plugins {
id("java")
id("application")
// Spring Boot runnable JAR support dependency management
id("org.springframework.boot") version "4.1.0"
// Create Java API from OpenAPI specification
id("org.openapi.generator") version "7.23.0"
// Dependencies list and diff automation in command line and CI/CD
id("org.cyclonedx.bom") version "3.2.4"
// Docker image creation
id("com.google.cloud.tools.jib") version "3.5.3"
// Allow configuring IntelliJ IDEA project
id("idea")
}
group = "com.example.nexus-repository-cleanup"
version = "0.0.1-SNAPSHOT"
java {
toolchain {
languageVersion = JavaLanguageVersion.of(17)
}
}
application {
mainClass.set("com.pyx4j.nxrm.cleanup.Application")
}
repositories {
mavenCentral()
}
dependencies {
implementation(platform(org.springframework.boot.gradle.plugin.SpringBootPlugin.BOM_COORDINATES))
implementation("org.springframework.boot:spring-boot-starter-webflux")
// Keep jackson 2.x for backward compatibility with the OpenAPI-generated client
implementation(platform("com.fasterxml.jackson:jackson-bom:2.22.0"))
// Command line arguments
implementation("info.picocli:picocli:4.7.7")
implementation("com.opencsv:opencsv:5.12.0")
// YAML parsing
implementation("com.fasterxml.jackson.dataformat:jackson-dataformat-yaml")
// Jackson 2.x for backward compatibility with generated OpenAPI client
implementation("com.fasterxml.jackson.core:jackson-databind")
implementation("com.fasterxml.jackson.datatype:jackson-datatype-jsr310")
implementation("com.google.guava:guava:33.6.0-jre")
implementation("org.apache.commons:commons-lang3")
// Runtime validation alternative...
implementation("org.assertj:assertj-core:3.27.7")
// Tests
testImplementation("org.springframework.boot:spring-boot-starter-test") {
exclude(group = "org.xmlunit", module = "xmlunit-core")
exclude(group = "com.jayway.jsonpath", module = "json-path")
}
testRuntimeOnly("org.junit.platform:junit-platform-launcher")
}
val generatedSourcesPath = "$projectDir/generated/src/main/java"
val apiDescriptionFile = "$projectDir/src/main/resources/open-api-nexus.json"
// Validating a single specification
openApiValidate {
inputSpec.set(apiDescriptionFile)
}
openApiGenerate {
generatorName.set("java")
inputSpec.set(apiDescriptionFile)
outputDir.set(generatedSourcesPath)
modelPackage.set("org.sonatype.nexus.model")
apiPackage.set("org.sonatype.nexus.api")
generateApiTests.set(false)
generateModelTests.set(false)
generateApiDocumentation.set(false)
generateModelDocumentation.set(false)
configOptions.put("library", "webclient")
configOptions.put("useJakartaEe", "true")
configOptions.put("openApiNullable", "false")
configOptions.put("useBeanValidation", "false")
configOptions.put("hideGenerationTimestamp", "true")
}
// Add the generated sources to the project
java.sourceSets["main"].java.srcDir(generatedSourcesPath)
idea {
module {
generatedSourceDirs.add(file(generatedSourcesPath))
}
}
// Make sure the sources are validated and generated before compiled
tasks {
val openApiValidate by getting
val openApiGenerate by getting {
dependsOn(openApiValidate)
}
val compileJava by getting {
dependsOn(openApiGenerate)
}
}
tasks.withType<JavaCompile> {
options.isDeprecation = true
// Enables http unit tests
options.compilerArgs.add("-parameters")
}
tasks.withType<Test> {
useJUnitPlatform()
testLogging {
events("passed", "skipped", "failed", "standardOut", "standardError")
}
}
// Example: gradle sbom; vk-sbom-diff sbom-1.json sbom.json
tasks.register("sbom", org.cyclonedx.gradle.CyclonedxDirectTask::class) {
includeConfigs.set(listOf("runtimeClasspath"))
projectType.set(org.cyclonedx.model.Component.Type.APPLICATION)
schemaVersion.set(org.cyclonedx.Version.VERSION_16)
jsonOutput.set(project.layout.projectDirectory.file("sbom.json"))
includeBomSerialNumber.set(false)
includeLicenseText.set(false)
}
// Default to local Docker daemon for development
// When container.image.repository is not set, JIB builds to local Docker
if (!hasProperty("container.image.name")) {
extra["container.image.name"] = project.name
}
// JIB configuration for Docker image creation
jib {
from {
image = "eclipse-temurin:17-jre-alpine"
}
to {
// Use repository if provided, otherwise build locally with 'gradle jibDockerBuild'
if (extra.has("container.image.registry")) {
image = "${extra["container.image.registry"]}/${extra["container.image.name"]}"
} else {
image = extra["container.image.name"].toString()
}
tags = setOf("latest", version.toString())
}
container {
mainClass = application.mainClass.get()
ports = listOf() // CLI application, no exposed ports
environment = mapOf(
"JAVA_TOOL_OPTIONS" to "-XX:+UseContainerSupport -XX:MaxRAMPercentage=75.0"
)
labels = mapOf(
"org.opencontainers.image.title" to "Nexus Repository Cleanup",
"org.opencontainers.image.description" to "CLI tool for cleaning up artifacts in Nexus Repository Manager",
"org.opencontainers.image.version" to version.toString(),
"org.opencontainers.image.vendor" to "skarzhevskyy",
"org.opencontainers.image.licenses" to "Apache-2.0"
)
creationTime = "USE_CURRENT_TIMESTAMP"
}
}