-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathbuild.gradle.kts
196 lines (169 loc) · 5.71 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
import com.google.protobuf.gradle.*
import org.gradle.api.artifacts.dsl.RepositoryHandler
import org.gradle.api.artifacts.repositories.MavenArtifactRepository
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
import java.net.URI
buildscript {
repositories {
gradlePluginPortal()
mavenCentral()
}
}
@Suppress("DSL_SCOPE_VIOLATION") /** https://github.com/gradle/gradle/issues/22797 */
plugins {
kotlin("jvm") version "1.8.10"
alias(libs.plugins.protobuf.gradle)
alias(libs.plugins.protocGen.krotoPlus)
`java-library`
`maven-publish`
signing
alias(libs.plugins.nexusPublishing)
}
repositories {
mavenCentral()
}
java {
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
withSourcesJar()
withJavadocJar() /** Needed to pass Nexus validation rules */
}
tasks.withType<Javadoc>().all {
options {
/**
* Necessary to suppress errors of invalid Javadocs generated from protobufs.
* Via https://stackoverflow.com/a/73930431
*/
(this as CoreJavadocOptions).addStringOption("Xdoclint:none", "-quiet")
}
}
tasks.withType<KotlinCompile>().all {
kotlinOptions {
freeCompilerArgs += listOf(
"-Xjsr305=strict",
)
jvmTarget = "11"
apiVersion = "1.8"
languageVersion = "1.8"
/** Necessary to allow deprecation warnings from the Java & Kotlin generated for deprecated protobuf fields */
allWarningsAsErrors = false
}
}
val projectVersion = project.property("version")?.takeIf { it != "unspecified" } ?: "1.0-SNAPSHOT"
dependencies {
listOf(
libs.kotlin.stdLib,
libs.protocGen.validate.base,
libs.protocGen.validate.javaStub,
libs.bundles.protobuf,
).forEach(::implementation)
listOf(
libs.junit.jupiter.api,
).forEach(::testImplementation)
listOf(
libs.junit.jupiter.engine,
).forEach(::testRuntimeOnly)
}
fun Provider<MinimalExternalModuleDependency>.toModule(): ModuleIdentifier = map { it.module }.get()
fun ProviderConvertible<String>.toVersionString(): String = asProvider().get()
protobuf {
// protoc plugin names
val validation = "javapgv"
protoc {
artifact = "${libs.protoc.toModule()}:${libs.versions.protobuf.toVersionString()}"
}
plugins {
id(validation) {
artifact = "${libs.protocGen.validate.base.toModule()}:${libs.versions.protocGenValidate.get()}"
}
}
generateProtoTasks {
all().forEach {
it.plugins {
ofSourceSet("main")
id(validation) {
option("lang=java")
}
}
it.builtins {
id("kotlin")
}
}
}
}
configurations.forEach { it.exclude("org.slf4j", "slf4j-api") }
tasks.withType<Test> {
useJUnitPlatform {
includeEngines("junit-jupiter")
}
testLogging {
events("passed", "skipped", "failed")
}
reports.html.required.set(true)
}
publishing {
publications {
create<MavenPublication>("maven") {
groupId = "io.provenance.model"
artifactId = "metadata-asset-model"
version = "$projectVersion"
from(components["java"])
pom {
name.set("Asset Metadata Model")
description.set("Asset/NFT reference data model for Provenance Blockchain metadata module")
url.set("https://figure.tech")
licenses {
license {
name.set("The Apache License, Version 2.0")
url.set("http://www.apache.org/licenses/LICENSE-2.0.txt")
}
}
developers {
developer {
id.set("vwagner")
name.set("Valerie Wagner")
email.set("tech@figure.com")
}
}
scm {
connection.set("git@github.com:provenance-io/metadata-asset-model.git")
developerConnection.set("git@github.com/provenance-io/metadata-asset-model.git")
url.set("https://github.com/provenance-io/metadata-asset-model")
}
}
}
}
signing {
sign(publishing.publications["maven"])
}
}
nexusPublishing {
repositories {
sonatype {
nexusUrl.set(uri("https://s01.oss.sonatype.org/service/local/"))
snapshotRepositoryUrl.set(uri("https://s01.oss.sonatype.org/content/repositories/snapshots/"))
username.set(findProject("ossrhUsername")?.toString() ?: System.getenv("OSSRH_USERNAME"))
password.set(findProject("ossrhPassword")?.toString() ?: System.getenv("OSSRH_PASSWORD"))
stagingProfileId.set("3180ca260b82a7") // prevents querying for the staging profile id, performance optimization
}
}
}
object Repos {
private object SonaTypeRepositoryURLs {
const val snapshots = "https://s01.oss.sonatype.org/content/repositories/snapshots/"
const val releases = "https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/"
}
fun RepositoryHandler.sonatypeOss(projectVersion: String): MavenArtifactRepository {
val mavenUrl =
if (projectVersion == "1.0-SNAPSHOT") SonaTypeRepositoryURLs.snapshots
else SonaTypeRepositoryURLs.releases
return maven {
name = "Sonatype"
url = URI.create(mavenUrl)
credentials {
username = System.getenv("OSSRH_USERNAME")
password = System.getenv("OSSRH_PASSWORD")
}
}
}
}