1apply plugin: 'maven-publish' 2apply plugin: 'signing' 3apply plugin: 'org.jetbrains.dokka' 4 5def dokkaConfiguration = { 6 outputDirectory.set(file("$rootDir/docs/2.x")) 7 8 dokkaSourceSets { 9 configureEach { 10 reportUndocumented.set(false) 11 skipDeprecated.set(true) 12 jdkVersion.set(8) 13 perPackageOption { 14 matchingRegex.set("com\\.squareup.okio.*") 15 suppress.set(true) 16 } 17 perPackageOption { 18 matchingRegex.set("okio\\.internal.*") 19 suppress.set(true) 20 } 21 } 22 } 23} 24 25dokkaGfm.configure(dokkaConfiguration) 26dokkaHtml.configure(dokkaConfiguration) 27 28def rootRelativePath(path) { 29 return rootProject.file(path).toString().replace('\\', '/') 30} 31 32dokkaHtml.pluginsMapConfiguration.set([ 33 "org.jetbrains.dokka.base.DokkaBase": """{ "customStyleSheets": ["${rootRelativePath("docs/css/dokka-logo.css")}"], "customAssets" : ["${rootRelativePath("docs/images/logo-square.png")}"]}""" 34]) 35 36def isReleaseBuild() { 37 return VERSION_NAME.contains("SNAPSHOT") == false 38} 39 40def getReleaseRepositoryUrl() { 41 return hasProperty('RELEASE_REPOSITORY_URL') ? RELEASE_REPOSITORY_URL : 42 "https://oss.sonatype.org/service/local/staging/deploy/maven2/" 43} 44 45def getSnapshotRepositoryUrl() { 46 return hasProperty('SNAPSHOT_REPOSITORY_URL') ? SNAPSHOT_REPOSITORY_URL : 47 "https://oss.sonatype.org/content/repositories/snapshots/" 48} 49 50def getRepositoryUsername() { 51 return hasProperty('SONATYPE_NEXUS_USERNAME') ? SONATYPE_NEXUS_USERNAME : "" 52} 53 54def getRepositoryPassword() { 55 return hasProperty('SONATYPE_NEXUS_PASSWORD') ? SONATYPE_NEXUS_PASSWORD : "" 56} 57 58task emptySourcesJar(type: Jar) { 59 classifier = 'sources' 60} 61 62task javadocsJar(type: Jar, dependsOn: dokkaGfm) { 63 classifier = 'javadoc' 64 from dokkaGfm.outputDirectory 65} 66 67signing { 68 required { isReleaseBuild() && gradle.taskGraph.hasTask("uploadArchives") } 69 sign(publishing.publications) 70} 71 72publishing { 73 publications.all { 74 artifact javadocsJar 75 76 pom.withXml { 77 def root = asNode() 78 79 root.children().last() + { 80 resolveStrategy = Closure.DELEGATE_FIRST 81 82 description POM_DESCRIPTION 83 name POM_NAME 84 url POM_URL 85 licenses { 86 license { 87 name POM_LICENCE_NAME 88 url POM_LICENCE_URL 89 distribution POM_LICENCE_DIST 90 } 91 } 92 scm { 93 url POM_SCM_URL 94 connection POM_SCM_CONNECTION 95 developerConnection POM_SCM_DEV_CONNECTION 96 } 97 developers { 98 developer { 99 id POM_DEVELOPER_ID 100 name POM_DEVELOPER_NAME 101 } 102 } 103 } 104 } 105 } 106 107 // Use default artifact name for the JVM target 108 publications { 109 kotlinMultiplatform { 110 artifactId = POM_ARTIFACT_ID + '-multiplatform' 111 } 112 jvm { 113 artifactId = POM_ARTIFACT_ID 114 } 115 } 116 117 afterEvaluate { 118 publications.getByName('kotlinMultiplatform') { 119 // Source jars are only created for platforms, not the common artifact. 120 artifact emptySourcesJar 121 } 122 } 123 124 repositories { 125 maven { 126 url isReleaseBuild() ? getReleaseRepositoryUrl() : getSnapshotRepositoryUrl() 127 credentials { 128 username getRepositoryUsername() 129 password getRepositoryPassword() 130 } 131 } 132 maven { 133 name 'test' 134 url "file://${rootProject.buildDir}/localMaven" 135 } 136 } 137} 138