forked from spring-projects-experimental/spring-fu
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.gradle.kts
181 lines (150 loc) · 4.15 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
import org.gradle.api.Project
import java.io.ByteArrayOutputStream
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
import org.gradle.api.publish.maven.MavenPublication
plugins {
id("org.jetbrains.kotlin.jvm") version "1.8.22" apply false
id("org.springframework.boot") apply false
id("io.spring.dependency-management") version "1.1.2"
id("maven-publish")
id("com.jfrog.artifactory") version "5.+"
}
fun Project.runCommand(command: String): String {
val stdout = ByteArrayOutputStream()
project.exec {
commandLine = command.split(" ")
standardOutput = stdout
}
return stdout
.toString()
.trim()
}
fun sanitizeVersion(branch: String): String {
return branch
.replace(Regex("[^A-Za-z0-9.-]+"), "-")
.replace(Regex("-+"), "-")
}
fun Project.gitVersionPostfix(): String {
val isGitRepo = runCatching { runCommand("git rev-parse --is-inside-work-tree") }
.getOrElse { "" } == "true"
if (!isGitRepo) {
return "-nogit"
}
val branch = runCommand("git rev-parse --abbrev-ref HEAD")
val commitsCount = runCommand("git rev-list --count HEAD")
return sanitizeVersion("-$branch-$commitsCount")
}
fun String.kebabToLowerCamelCase(): String {
return "-[a-zA-Z]"
.toRegex()
.replace(this) {
it.value
.replace("-","")
.toUpperCase()
}
}
subprojects {
apply {
plugin("java-library")
plugin("maven-publish")
plugin("com.jfrog.artifactory")
plugin("io.spring.dependency-management")
}
version = "0.6.0" + gitVersionPostfix()
group = "org.springframework.fu"
dependencyManagement {
imports {
mavenBom("org.springframework.boot:spring-boot-dependencies:${findProperty("bootVersion")}")
mavenBom("org.testcontainers:testcontainers-bom:1.15.3")
}
}
tasks.withType<Test> {
useJUnitPlatform()
}
tasks.withType<JavaCompile> {
sourceCompatibility = "17"
targetCompatibility = "17"
}
tasks.withType<KotlinCompile> {
kotlinOptions {
freeCompilerArgs += "-Xjsr305=strict"
freeCompilerArgs += "-Xextended-compiler-checks"
jvmTarget = "17"
}
}
repositories {
mavenCentral()
maven("https://repo.spring.io/milestone")
maven("https://repo.spring.io/snapshot")
}
tasks.register<Jar>("sourcesJar") {
dependsOn("classes")
archiveClassifier.set("sources")
from(project.the<SourceSetContainer>()["main"].allSource)
}
tasks.register<Jar>("javadocJar") {
dependsOn("javadoc")
archiveClassifier.set("javadoc")
from(tasks.named<Javadoc>("javadoc").get().destinationDir)
}
artifactory {
clientConfig.isIncludeEnvVars = false
val artifactoryContextUrl: String = findProperty("artifactoryContextUrl")
?.toString()
?: error(
"Artifactory Context Url must not be null. " +
"Check artifactoryContextUrl in gradle.properties or environment"
)
val artifactoryRepoPublish: String = findProperty("artifactoryRepoPublish")
?.toString()
?: error(
"Artifactory Repo Publish must not be null. " +
"Check artifactoryRepoPublish in gradle.properties or environment"
)
val artifactoryUser: String = findProperty("artifactoryUser")
?.toString()
?: error(
"Artifactory User must not be null. " +
"Check artifactoryUser in gradle.properties or environment"
)
val artifactoryPassword: String = findProperty("artifactoryPassword")
?.toString()
?: error(
"Artifactory Password must not be null. " +
"Check artifactoryPassword in gradle.properties or environment"
)
setContextUrl(artifactoryContextUrl)
publish {
repository {
repoKey = artifactoryRepoPublish
username = artifactoryUser
password = artifactoryPassword
}
defaults {
publications(project.name.kebabToLowerCamelCase())
setPublishArtifacts(true)
isPublishBuildInfo = false
}
}
}
publishing {
publications {
create<MavenPublication>(project.name.kebabToLowerCamelCase()) {
groupId = project.group.toString()
version = project.version.toString()
artifactId = project.name
versionMapping {
usage("java-api") {
fromResolutionOf("runtimeClasspath")
}
usage("java-runtime") {
fromResolutionResult()
}
}
artifact(tasks.named("sourcesJar"))
artifact(tasks.named("javadocJar"))
from(components["java"])
}
}
}
}