1
1
import org.jetbrains.dokka.gradle.DokkaTask
2
2
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
3
+ import de.marcphilipp.gradle.nexus.NexusRepository
3
4
4
5
plugins {
5
6
kotlin(" jvm" ).version(" 1.3.61" )
6
7
id(" org.jetbrains.dokka" ) version " 0.10.0"
7
8
`maven- publish`
8
9
signing
10
+ id(" de.marcphilipp.nexus-publish" ) version " 0.4.0"
9
11
id(" io.codearte.nexus-staging" ) version " 0.21.2"
12
+ id(" com.palantir.git-version" ) version " 0.12.2"
10
13
idea
11
14
}
12
15
13
16
group = " de.joshuagleitze"
14
- version = project.findProperty(" releaseVersion" ) ? : " SNAPSHOT"
17
+ version = if (isSnapshot) versionDetails.gitHash else versionDetails.lastTag.drop(" v" )
18
+ status = if (isSnapshot) " snapshot" else " release"
15
19
16
20
repositories {
17
21
jcenter()
@@ -74,6 +78,8 @@ artifacts {
74
78
}
75
79
76
80
lateinit var publication: MavenPublication
81
+ lateinit var snapshotRepository: ArtifactRepository
82
+ lateinit var releaseRepository: NexusRepository
77
83
78
84
publishing {
79
85
publications {
@@ -117,26 +123,25 @@ publishing {
117
123
}
118
124
}
119
125
repositories {
120
- if (project.isSnapshot) {
121
- maven(" https://maven.pkg.github.com/$githubRepository " ) {
122
- name = " GitHub-Packages"
123
- credentials {
124
- username = githubOwner
125
- password = githubToken
126
- }
127
- }
128
- } else {
129
- maven(" https://oss.sonatype.org/service/local/staging/deploy/maven2/" ) {
130
- name = " OSSRH-Staging"
131
- credentials {
132
- username = ossrhUsername
133
- password = ossrhPassword
134
- }
126
+ snapshotRepository = maven(" https://maven.pkg.github.com/$githubRepository " ) {
127
+ name = " GitHubPackages"
128
+ credentials {
129
+ username = githubOwner
130
+ password = githubToken
135
131
}
136
132
}
137
133
}
138
134
}
139
135
136
+ nexusPublishing {
137
+ repositories {
138
+ releaseRepository = sonatype {
139
+ username.set(ossrhUsername)
140
+ password.set(ossrhPassword)
141
+ }
142
+ }
143
+ }
144
+
140
145
signing {
141
146
val signingKey: String? by project
142
147
val signingKeyPassword: String? by project
@@ -149,15 +154,21 @@ nexusStaging {
149
154
password = ossrhPassword
150
155
}
151
156
152
- val closeAndPromoteRepository by project.tasks
157
+ val closeAndReleaseRepository by project.tasks
153
158
val publish by tasks
154
159
160
+ task(" publishSnapshot" ) {
161
+ group = " publishing"
162
+ description = " Publishes a snapshot of the project to GitHub Packages"
163
+ dependsOn(snapshotRepository.publishTask)
164
+ }
165
+
155
166
task(" release" ) {
156
167
group = " release"
157
- description = " Publishes the project to Maven Central"
158
- dependsOn(publish )
159
- dependsOn(closeAndPromoteRepository )
160
- closeAndPromoteRepository .mustRunAfter(publish )
168
+ description = " Releases the project to Maven Central"
169
+ dependsOn(releaseRepository.publishTask )
170
+ dependsOn(closeAndReleaseRepository )
171
+ closeAndReleaseRepository .mustRunAfter(releaseRepository.publishTask )
161
172
}
162
173
163
174
idea {
@@ -167,4 +178,13 @@ idea {
167
178
}
168
179
}
169
180
170
- val Project .isSnapshot get() = this .version == " SNAPSHOT"
181
+ val Project .isSnapshot get() = versionDetails.commitDistance != 0
182
+
183
+ fun String.drop (prefix : String ) = if (this .startsWith(prefix)) this .drop(prefix.length) else this
184
+
185
+ val Project .versionDetails
186
+ get() = (this .extra[" versionDetails" ] as groovy.lang.Closure <* >)() as com.palantir.gradle.gitversion.VersionDetails
187
+
188
+
189
+ val ArtifactRepository .publishTask get() = tasks[" publishAllPublicationsTo${this .name} Repository" ]
190
+ val NexusRepository .publishTask get() = tasks[" publishTo${this .name.capitalize()} " ]
0 commit comments