-
Notifications
You must be signed in to change notification settings - Fork 5
/
build.gradle.kts
164 lines (140 loc) · 5.14 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
import org.gradle.api.Project.DEFAULT_VERSION
import org.gradle.kotlin.dsl.*
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
plugins {
`java-gradle-plugin`
`maven-publish`
`kotlin-dsl`
`signing`
kotlin("jvm") version embeddedKotlinVersion
id("org.jetbrains.dokka") version "1.9.10"
id("io.codearte.nexus-staging") version "0.22.0"
id("de.marcphilipp.nexus-publish") version "0.4.0"
}
group = "io.johnsonlee"
version = project.properties["version"]?.takeIf { it != DEFAULT_VERSION } ?: "1.0.0-SNAPSHOT"
description = "Gradle plugin for publishing artifacts to Sonatype"
repositories {
mavenCentral()
google()
gradlePluginPortal()
}
dependencies {
implementation(gradleApi())
implementation(platform(kotlin("bom")))
implementation(kotlin("stdlib"))
implementation("de.marcphilipp.gradle:nexus-publish-plugin:0.4.0")
implementation("io.codearte.nexus-staging:io.codearte.nexus-staging.gradle.plugin:0.22.0")
implementation("org.jetbrains.dokka:dokka-gradle-plugin:1.9.10")
implementation("org.eclipse.jgit:org.eclipse.jgit:5.13.0.202109080827-r")
compileOnly("com.android.tools.build:gradle:4.0.0")
testImplementation(kotlin("test"))
testImplementation(kotlin("test-junit"))
testImplementation("com.didiglobal.booster:booster-kotlinx:4.8.0")
}
gradlePlugin {
plugins.create("io.johnsonlee.sonatype-publish-plugin") {
id = name
implementationClass = "io.johnsonlee.gradle.publish.SonatypePublishPlugin"
}
}
java {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}
tasks.withType<KotlinCompile> {
kotlinOptions {
freeCompilerArgs = listOf("-Xjsr305=strict")
jvmTarget = "1.8"
}
}
val sourcesJar by tasks.registering(Jar::class) {
dependsOn(JavaPlugin.CLASSES_TASK_NAME)
archiveClassifier.set("sources")
from(sourceSets.main.get().allSource)
}
val javadocJar by tasks.registering(Jar::class) {
dependsOn("dokkaHtml")
archiveClassifier.set("javadoc")
from(tasks["dokkaHtml"])
}
val OSSRH_USERNAME = "${project.properties["OSSRH_USERNAME"] ?: System.getenv("OSSRH_USERNAME")}"
val OSSRH_PASSWORD = "${project.properties["OSSRH_PASSWORD"] ?: System.getenv("OSSRH_PASSWORD")}"
nexusPublishing {
this.repositories {
sonatype {
username.set(OSSRH_USERNAME)
password.set(OSSRH_PASSWORD)
}
}
}
publishing {
repositories {
maven {
url = uri("https://oss.sonatype.org/service/local/staging/deploy/maven2/")
}
}
publications {
withType(MavenPublication::class.java).configureEach {
val publication = this
groupId = "${project.group}"
artifactId = project.name
version = "${project.version}"
if ("mavenJava" == publication.name) {
from(components["java"])
}
artifact(sourcesJar.get())
artifact(javadocJar.get())
pom.withXml {
asNode().apply {
appendNode("name", project.name)
appendNode("url", "https://github.com/johnsonlee/${rootProject.name}")
appendNode("description", project.description ?: project.name)
appendNode("scm").apply {
appendNode("connection", "scm:git:git://github.com/johnsonlee/${rootProject.name}.git")
appendNode("developerConnection", "scm:git:[email protected]:johnsonlee/${rootProject.name}.git")
appendNode("url", "https://github.com/johnsonlee/${rootProject.name}")
}
appendNode("licenses").apply {
appendNode("license").apply {
appendNode("name", "Apache License")
appendNode("url", "https://www.apache.org/licenses/LICENSE-2.0")
}
}
appendNode("developers").apply {
appendNode("developer").apply {
appendNode("id", "johnsonlee")
appendNode("name", "Johnson Lee")
appendNode("email", "[email protected]")
}
}
}
}
signing {
sign(publication)
}
}
}
}
tasks.withType<AbstractPublishToMaven>().configureEach {
val signingTasks = tasks.withType<Sign>()
mustRunAfter(signingTasks)
}
nexusStaging {
packageGroup = "io.johnsonlee"
username = OSSRH_USERNAME
password = OSSRH_PASSWORD
numberOfRetries = 60
delayBetweenRetriesInMillis = 5000
}
val functionalTestSourceSet = sourceSets.create("functionalTest") {
}
gradlePlugin.testSourceSets(functionalTestSourceSet)
configurations["functionalTestImplementation"].extendsFrom(configurations["testImplementation"])
val functionalTest by tasks.registering(Test::class) {
testClassesDirs = functionalTestSourceSet.output.classesDirs
classpath = functionalTestSourceSet.runtimeClasspath
}
tasks.check {
dependsOn(functionalTest)
}