Skip to content

Commit df584f5

Browse files
committed
Setup the publishing to maven central
1 parent 197a772 commit df584f5

File tree

8 files changed

+144
-147
lines changed

8 files changed

+144
-147
lines changed

build.gradle

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ buildscript {
2020

2121
plugins {
2222
id("org.jetbrains.dokka") version "$dokka_version"
23+
id("io.github.gradle-nexus.publish-plugin") version "1.1.0"
2324
}
2425

2526
allprojects {
@@ -36,3 +37,5 @@ task clean(type: Delete) {
3637
dokkaHtmlMultiModule.configure {
3738
outputDirectory = new File("${projectDir}/docs")
3839
}
40+
41+
apply from: "${rootDir}/gradle/publish-root.gradle"

gradle/publish-module.gradle

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
apply plugin: 'maven-publish'
2+
apply plugin: 'signing'
3+
4+
task androidSourcesJar(type: Jar) {
5+
archiveClassifier.set('sources')
6+
if (project.plugins.findPlugin("com.android.library")) {
7+
// For Android libraries
8+
from android.sourceSets.main.java.srcDirs
9+
from android.sourceSets.main.kotlin.srcDirs
10+
} else {
11+
// For pure Kotlin libraries, in case you have them
12+
from sourceSets.main.java.srcDirs
13+
from sourceSets.main.kotlin.srcDirs
14+
}
15+
}
16+
17+
task javadocJar(type: Jar, dependsOn: dokkaJavadoc) {
18+
archiveClassifier.set('javadoc')
19+
from dokkaJavadoc.outputDirectory
20+
}
21+
22+
artifacts {
23+
archives androidSourcesJar
24+
archives javadocJar
25+
}
26+
27+
group = PUBLISH_GROUP_ID
28+
version = PUBLISH_VERSION
29+
30+
afterEvaluate {
31+
publishing {
32+
publications {
33+
release(MavenPublication) {
34+
groupId PUBLISH_GROUP_ID
35+
artifactId PUBLISH_ARTIFACT_ID
36+
version PUBLISH_VERSION
37+
38+
// Two artifacts, the `aar` (or `jar`) and the sources
39+
if (project.plugins.findPlugin("com.android.library")) {
40+
from components.release
41+
} else {
42+
artifact jar
43+
}
44+
45+
artifact androidSourcesJar
46+
artifact javadocJar
47+
48+
pom {
49+
name = PUBLISH_ARTIFACT_ID
50+
description = PUBLISH_DESCRIPTION
51+
url = rootProject.ext.githubRepoUrl
52+
licenses {
53+
license {
54+
name = "The MIT License (MIT)"
55+
url = "${rootProject.ext.githubRepoUrl}/blob/master/LICENSE"
56+
distribution = "repo"
57+
}
58+
}
59+
developers {
60+
developer {
61+
id = "esnaultdev"
62+
name = "Matthieu Esnault"
63+
email = "matthieu.esn0@gmail.com"
64+
}
65+
}
66+
67+
scm {
68+
connection = "scm:git:github.com/${rootProject.ext.githubRepoName}.git"
69+
developerConnection = "scm:git:ssh://github.com/${rootProject.ext.githubRepoName}.git"
70+
url = "https://github.com/${rootProject.ext.githubRepoName}/tree/master"
71+
}
72+
}
73+
}
74+
}
75+
}
76+
}
77+
78+
ext["signing.keyId"] = rootProject.ext["signing.keyId"]
79+
ext["signing.password"] = rootProject.ext["signing.password"]
80+
ext["signing.secretKeyRingFile"] = rootProject.ext["signing.secretKeyRingFile"]
81+
82+
signing {
83+
sign publishing.publications
84+
}

gradle/publish-root.gradle

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
ext {
2+
artifactVersion = '1.1.1'
3+
publishGroupId = 'dev.esnault.wanakana'
4+
githubRepoName = 'esnaultdev/wanakana-kt'
5+
githubRepoUrl = "https://github.com/$githubRepoName"
6+
}
7+
8+
// Create secret variables with empty default values
9+
ext["signing.keyId"] = ''
10+
ext["signing.password"] = ''
11+
ext["signing.secretKeyRingFile"] = ''
12+
ext["ossrhUsername"] = ''
13+
ext["ossrhPassword"] = ''
14+
ext["sonatypeStagingProfileId"] = ''
15+
16+
File localPropsFile = project.rootProject.file('local.properties')
17+
if (localPropsFile.exists()) {
18+
Properties properties = new Properties()
19+
new FileInputStream(localPropsFile).withCloseable { is -> properties.load(is) }
20+
ext["signing.keyId"] = properties.getProperty('signing.keyId', '')
21+
ext["signing.password"] = properties.getProperty('signing.password', '')
22+
ext["signing.secretKeyRingFile"] = properties.getProperty('signing.secretKeyRingFile', '')
23+
ext["ossrhUsername"] = properties.getProperty('ossrhUsername', '')
24+
ext["ossrhPassword"] = properties.getProperty('ossrhPassword', '')
25+
ext["sonatypeStagingProfileId"] = properties.getProperty('sonatypeStagingProfileId', '')
26+
}
27+
28+
// Set up Sonatype repository
29+
nexusPublishing {
30+
repositories {
31+
sonatype {
32+
username = ossrhUsername
33+
password = ossrhPassword
34+
stagingProfileId = sonatypeStagingProfileId
35+
nexusUrl.set(uri("https://s01.oss.sonatype.org/service/local/"))
36+
snapshotRepositoryUrl.set(uri("https://s01.oss.sonatype.org/content/repositories/snapshots/"))
37+
}
38+
}
39+
}

gradle/publishing.gradle

Lines changed: 0 additions & 35 deletions
This file was deleted.

wanakana-android/build.gradle

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,4 +46,11 @@ dependencies {
4646
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
4747
}
4848

49-
apply from: "publishing.gradle"
49+
ext {
50+
PUBLISH_GROUP_ID = rootProject.ext.publishGroupId
51+
PUBLISH_VERSION = rootProject.ext.artifactVersion
52+
PUBLISH_ARTIFACT_ID = 'wanakana-android'
53+
PUBLISH_DESCRIPTION = 'Android bindings for WanaKana, a library for detecting and transliterating Hiragana, Katakana and Romaji.'
54+
}
55+
56+
apply from: "${rootProject.projectDir}/gradle/publish-module.gradle"

wanakana-android/publishing.gradle

Lines changed: 0 additions & 56 deletions
This file was deleted.

wanakana-core/build.gradle

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ plugins {
66
id("com.jfrog.bintray") version "1.8.5"
77
}
88

9+
version = rootProject.ext.artifactVersion
10+
911
java {
1012
sourceCompatibility = JavaVersion.VERSION_1_8
1113
targetCompatibility = JavaVersion.VERSION_1_8
@@ -41,4 +43,11 @@ dependencies {
4143
testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:5.7.0"
4244
}
4345

44-
apply from: "publishing.gradle"
46+
ext {
47+
PUBLISH_GROUP_ID = rootProject.ext.publishGroupId
48+
PUBLISH_VERSION = rootProject.ext.artifactVersion
49+
PUBLISH_ARTIFACT_ID = 'wanakana-core'
50+
PUBLISH_DESCRIPTION = 'Kotlin port of WanaKana, a library for detecting and transliterating Hiragana, Katakana and Romaji.'
51+
}
52+
53+
apply from: "${rootProject.projectDir}/gradle/publish-module.gradle"

wanakana-core/publishing.gradle

Lines changed: 0 additions & 54 deletions
This file was deleted.

0 commit comments

Comments
 (0)