11import ktx.*
22import org.gradle.api.tasks.testing.logging.TestExceptionFormat.FULL
33import org.gradle.api.tasks.testing.logging.TestLogEvent.*
4+ import org.jetbrains.kotlin.gradle.dsl.JvmTarget
45import org.jetbrains.kotlin.gradle.dsl.jvm.JvmTargetValidationMode
56import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
7+ import com.vanniktech.maven.publish.JavadocJar
8+ import com.vanniktech.maven.publish.KotlinJvm
69
710buildscript {
811 repositories {
@@ -24,11 +27,12 @@ buildscript {
2427val libGroup: String by project
2528val ossrhUsername: String by project
2629val ossrhPassword: String by project
30+ val mavenPublishingPluginVersion: String by project
2731
2832plugins {
2933 java
3034 distribution
31- id(" io.codearte.nexus-staging " ) version " 0.22 .0"
35+ id(" com.vanniktech.maven.publish " ) version " 0.33 .0"
3236}
3337
3438repositories {
@@ -48,11 +52,11 @@ allprojects {
4852}
4953
5054subprojects {
51- apply (plugin = " maven-publish" )
5255 apply (plugin = " java" )
5356 apply (plugin = " kotlin" )
5457 apply (plugin = " signing" )
5558 apply (plugin = " jacoco" )
59+ apply (plugin = " com.vanniktech.maven.publish.base" )
5660
5761 val isReleaseVersion = ! libVersion.endsWith(" SNAPSHOT" )
5862
@@ -77,14 +81,14 @@ subprojects {
7781 }
7882
7983 tasks.withType<KotlinCompile > {
80- kotlinOptions {
81- jvmTarget = JavaVersion . VERSION_1_8 .toString( )
82- freeCompilerArgs + = " -opt-in=kotlin.RequiresOptIn"
84+ compilerOptions {
85+ jvmTarget.set( JvmTarget . JVM_1_8 )
86+ freeCompilerArgs.add( " -opt-in=kotlin.RequiresOptIn" )
8387 }
8488 jvmTargetValidationMode.set(JvmTargetValidationMode .IGNORE )
8589 }
8690 val compileTestKotlin: KotlinCompile by tasks
87- compileTestKotlin.kotlinOptions .jvmTarget = JavaVersion . VERSION_11 .toString( )
91+ compileTestKotlin.compilerOptions .jvmTarget.set( JvmTarget . JVM_11 )
8892
8993 dependencies {
9094 val kotlinVersion: String by project
@@ -140,117 +144,54 @@ subprojects {
140144 }
141145
142146 val dokkaHtml by tasks.getting
143-
144147 tasks.register<Zip >(" dokkaZip" ) {
145- from(" $buildDir /dokka/html" )
146- dependsOn(dokkaHtml)
147- }
148-
149- val javadocJar by tasks.registering(Jar ::class ) {
150- archiveClassifier.set(" javadoc" )
151- from(" $buildDir /dokka/html" )
148+ from(" ${layout.buildDirectory} /dokka/html" )
152149 dependsOn(dokkaHtml)
153150 }
154151
155- val sourcesJar by tasks.registering(Jar ::class ) {
156- from(sourceSets.main.get().allSource)
157- archiveClassifier.set(" sources" )
158- }
159-
160- artifacts {
161- archives(javadocJar)
162- archives(sourcesJar)
163- }
164-
165- afterEvaluate {
166- rootProject.distributions {
167- main {
168- distributionBaseName.set(libVersion)
169- contents {
170- into(" lib" ) {
171- from(tasks.jar)
172- }
173- into(" doc" ) {
174- from(tasks[" dokkaZip" ])
175- }
176- into(" src" ) {
177- from(tasks[" sourcesJar" ])
178- }
179- }
180- }
152+ mavenPublishing {
153+ publishToMavenCentral(automaticRelease = true )
154+ if (isReleaseVersion) {
155+ signAllPublications()
181156 }
182- }
183-
184- tasks.register( " uploadSnapshot " ) {
185- if ( ! isReleaseVersion) finalizedBy(tasks[ " publishAllPublicationsToMavenRepository " ] )
186- }
187-
188- configure< PublishingExtension > {
189- repositories {
190- maven {
191- val releasesRepoUrl = uri( " https://oss.sonatype.org/service/local/staging/deploy/maven2/ " )
192- val snapshotsRepoUrl = uri( " https://oss.sonatype.org/content/repositories/snapshots/ " )
193- url = if (version.toString().endsWith( " SNAPSHOT " )) snapshotsRepoUrl else releasesRepoUrl
194-
195- credentials {
196- username = ossrhUsername
197- password = ossrhPassword
157+ configure( KotlinJvm (
158+ javadocJar = if (isReleaseVersion) JavadocJar . Dokka ( " dokkaHtml " ) else JavadocJar . None (),
159+ sourcesJar = true
160+ ) )
161+
162+ coordinates(libGroup, projectName, libVersion)
163+
164+ pom {
165+ name.set(projectName)
166+ description.set(projectDesc )
167+ inceptionYear.set( " 2016 " )
168+ url.set( " https://github.com/libktx/ktx " )
169+ licenses {
170+ license {
171+ name.set( " CC0-1.0 " )
172+ url.set( " https://creativecommons.org/publicdomain/zero/1.0/ " )
198173 }
199174 }
200- }
201-
202- publications {
203- create<MavenPublication >(" mavenKtx" ) {
204- pom {
205- name.set(projectName)
206- packaging = " jar"
207- description.set(projectDesc)
208- afterEvaluate {
209- artifactId = tasks.jar.get().archiveBaseName.get()
210- }
211-
212- from(components[" kotlin" ])
213- artifact(sourcesJar)
214- artifact(javadocJar)
215-
216- url.set(" https://libktx.github.io/" )
217-
218- licenses {
219- license {
220- name.set(" CC0-1.0" )
221- url.set(" https://creativecommons.org/publicdomain/zero/1.0/" )
222- }
223- }
224-
225- scm {
226- connection.set(" scm:git:git@github.com:libktx/ktx.git" )
227- developerConnection.set(" scm:git:git@github.com:libktx/ktx.git" )
228- url.set(" https://github.com/libktx/ktx/" )
229- }
230-
231- developers {
232- developer {
233- id.set(" mj" )
234- name.set(" MJ" )
235- }
236- }
175+ developers {
176+ developer {
177+ id.set(" mj" )
178+ name.set(" MJ" )
179+ url.set(" https://github.com/czyzby" )
237180 }
238181 }
182+ scm {
183+ url.set(" https://github.com/libktx/ktx" )
184+ connection.set(" scm:git:git://github.com/libktx/ktx.git" )
185+ developerConnection.set(" scm:git:ssh://git@github.com/libktx/ktx.git" )
186+ }
239187 }
240188 }
241189
242- tasks.withType<Sign > { onlyIf { isReleaseVersion } }
243-
244- configure<SigningExtension > {
245- setRequired { isReleaseVersion && gradle.taskGraph.hasTask(" publish" ) }
246- sign(extensions.getByType<PublishingExtension >().publications[" mavenKtx" ])
190+ tasks.register(" uploadSnapshot" ) {
191+ if (! isReleaseVersion) finalizedBy(tasks[" publishToMavenCentral" ])
247192 }
248- }
249193
250- nexusStaging {
251- packageGroup = libGroup
252- username = ossrhUsername
253- password = ossrhPassword
194+ tasks.withType<Sign > { onlyIf { isReleaseVersion } }
254195}
255196
256197tasks.register<JavaExec >(" linterIdeSetup" ) {
0 commit comments