-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.gradle.kts
More file actions
155 lines (132 loc) · 4.32 KB
/
Copy pathbuild.gradle.kts
File metadata and controls
155 lines (132 loc) · 4.32 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
plugins {
`java-library`
`maven-publish`
signing
id("com.github.johnrengelman.shadow") version "7.1.2"
id("io.github.gradle-nexus.publish-plugin") version "1.1.0"
}
// gradlew publishToSonatype closeSonatypeStagingRepository for staging and manual release
// gradlew publishToSonatype closeAndReleaseSonatypeStagingRepository for automatic release
val versionObject = Version(breaking = "1", minor = "0", nonbreaking = "0", revision = "2", date = "2206")
project.group = "com.riskrieg"
project.version = "$versionObject"
java {
withJavadocJar()
withSourcesJar()
toolchain {
languageVersion.set(JavaLanguageVersion.of(17))
}
}
repositories {
mavenCentral()
}
dependencies {
api("com.github.spotbugs:spotbugs-annotations:4.6.0")
testImplementation("org.junit.jupiter:junit-jupiter-api:5.8.2")
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:5.8.2")
}
fun getProjectProperty(name: String) = project.properties[name] as? String
tasks.getByName<Test>("test") {
useJUnitPlatform()
failFast = true
}
tasks.jar {
archiveBaseName.set(project.name)
manifest.attributes(
mapOf(
"Implementation-Version" to project.version,
"Automatic-Module-Name" to "com.riskrieg.map"
)
)
includeEmptyDirs = false
}
tasks.javadoc {
options.encoding = "UTF-8"
}
class Version(
val breaking: String,
val minor: String,
val nonbreaking: String,
val revision: String,
val date: String,
val classifier: String? = null
) {
override fun equals(other: Any?): Boolean {
if (other === this) return true
if (other !is Version) return false
return breaking == other.breaking
&& minor == other.minor
&& nonbreaking == other.nonbreaking
&& revision == other.revision
&& date == other.date
&& classifier == other.classifier
}
override fun hashCode(): Int {
var result = breaking.hashCode()
result = 31 * result + minor.hashCode()
result = 31 * result + nonbreaking.hashCode()
result = 31 * result + revision.hashCode()
result = 31 * result + date.hashCode()
result = 31 * result + (classifier?.hashCode() ?: 0)
return result
}
override fun toString(): String {
return "$breaking.$minor.$nonbreaking-$revision.$date" + if (classifier != null) "-$classifier" else ""
}
}
/* Maven Central Publishing and Signing */
fun generatePom(pom: MavenPom) {
pom.packaging = "jar"
pom.name.set(project.name)
pom.description.set("Standard Java representation of Riskrieg maps and the RKM binary file format: https://riskrieg.com")
pom.url.set("https://github.com/Riskrieg/map")
pom.scm {
url.set("https://github.com/Riskrieg/map")
connection.set("scm:git:git://github.com/Riskrieg/map.git")
developerConnection.set("scm:git:ssh:git@github.com:Riskrieg/map.git")
}
pom.licenses {
license {
name.set("MIT License")
url.set("https://github.com/Riskrieg/map/blob/main/LICENSE")
distribution.set("repo")
}
}
pom.developers {
developer {
id.set("aaronjyoder")
name.set("Aaron J Yoder")
email.set("aaronjyoder@gmail.com")
}
}
}
// Publish
// Skip fat jar publication (https://github.com/johnrengelman/shadow/issues/586)
components.java.withVariantsFromConfiguration(configurations.shadowRuntimeElements.get()) { skip() }
val SoftwareComponentContainer.java
get() = components.getByName("java") as AdhocComponentWithVariants
publishing {
publications {
register("Release", MavenPublication::class) {
from(components["java"])
artifactId = project.name
groupId = project.group as String
version = project.version as String
generatePom(pom)
}
}
}
val canSign = getProjectProperty("signing.keyId") != null
if (canSign) {
signing {
sign(publishing.publications.getByName("Release"))
}
}
nexusPublishing {
repositories {
sonatype {
nexusUrl.set(uri("https://s01.oss.sonatype.org/service/local/"))
snapshotRepositoryUrl.set(uri("https://s01.oss.sonatype.org/content/repositories/snapshots/"))
}
}
}