Skip to content
This repository has been archived by the owner on Jun 27, 2023. It is now read-only.

Commit

Permalink
Merge pull request #3 from milosmns/feature/maven-publish
Browse files Browse the repository at this point in the history
Library publishing config
  • Loading branch information
milosmns authored Jul 12, 2020
2 parents 2c8c8f6 + e46e4a9 commit 3b12321
Show file tree
Hide file tree
Showing 4 changed files with 278 additions and 22 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -202,4 +202,5 @@ $RECYCLE.BIN/

# Custom rules
.gradle
kssm/build
kssm/build
local.properties
77 changes: 56 additions & 21 deletions kssm/build.gradle
Original file line number Diff line number Diff line change
@@ -1,13 +1,43 @@
plugins {
id 'org.jetbrains.kotlin.jvm' version '1.3.72'
id 'org.jmailen.kotlinter' version '2.4.1'
id 'org.jetbrains.dokka' version '0.10.1'
id 'org.jetbrains.kotlin.jvm' version '1.3.72' // Basic Kotlin support
id 'org.jmailen.kotlinter' version '2.4.1' // Lint for Kotlin
id 'org.jetbrains.dokka' version '0.10.1' // Documentation generator
id 'maven-publish' // Packaging and uploading JARs with POMs
id 'com.jfrog.bintray' version '1.8.5' // Uploading to JCenter
id 'com.github.dcendents.android-maven' version '2.1' // Packaging resources into JARs
}

// Globally accessible variables

ext {
kotlinTargetLevel = "1.6" // Required for old JVMs (still active)
javaTargetLevel = "1.8" // Required for JUnit Jupiter

outputDir = 'build'
javaSourceDir = 'src/main/java'
kotlinSourceDir = 'src/main/kotlin'
resourcesDir = 'src/main/resources'

projectVersion = '1.0.0'
projectGroup = 'me.angrybyte'

VERSION_NAME = projectVersion // Needed for 'bintrayUpload' task
GROUP = projectGroup // Needed for 'bintrayUpload' task

coroutines_version = "1.3.7"
}

// Directory configuration

project.buildDir = outputDir
sourceSets.main.java.srcDirs += javaSourceDir
sourceSets.main.kotlin.srcDirs += kotlinSourceDir
sourceSets.main.resources.srcDirs += resourcesDir

// Maven Coordinates

group 'me.angrybyte'
version '0.1'
group projectGroup
version projectVersion

// Module dependencies

Expand All @@ -16,33 +46,34 @@ repositories {
mavenCentral()
}

ext {
coroutines_version = "1.3.7"
}

dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:$coroutines_version"
api "org.jetbrains.kotlin:kotlin-stdlib-jdk8"
api "org.jetbrains.kotlinx:kotlinx-coroutines-core:$coroutines_version"

testImplementation "org.junit.jupiter:junit-jupiter:5.6.2"
testImplementation "org.jetbrains.kotlinx:kotlinx-coroutines-test:$coroutines_version"
}

test {
useJUnitPlatform()
testLogging {
events "passed", "skipped", "failed", "standardOut", "standardError"
}
}
// JVM bytecode config

// Kotlin config
sourceCompatibility = javaTargetLevel
targetCompatibility = javaTargetLevel

compileKotlin {
kotlinOptions.jvmTarget = "1.8"
kotlinOptions.jvmTarget = kotlinTargetLevel
}

compileTestKotlin {
kotlinOptions.jvmTarget = "1.8"
kotlinOptions.jvmTarget = kotlinTargetLevel
}

// Tests config

test {
useJUnitPlatform()
testLogging {
events "passed", "skipped", "failed", "standardOut", "standardError"
}
}

// Linter config
Expand All @@ -61,4 +92,8 @@ kotlinter {
dokka {
outputFormat = 'html'
outputDirectory = "$buildDir/../../docs/dokka"
}
}

// Custom scripts

apply from: 'gradle/scripts/gradle-maven-push.gradle'
24 changes: 24 additions & 0 deletions kssm/gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# POM project location config
POM_URL=https://github.com/milosmns/kssm
POM_SCM_URL=https://github.com/milosmns/kssm
POM_SCM_CONNECTION=scm:git:git://github.com/milosmns/kssm.git
POM_SCM_DEV_CONNECTION=scm:git:ssh://[email protected]:milosmns/kssm.git
POM_ISSUE_URL=https://github.com/milosmns/kssm/issues

# POM licensing config
POM_LICENCE_NAME=MIT License, Version 3.0
POM_LICENCE_URL=https://opensource.org/licenses/MIT
POM_ALL_LICENCES=['MIT-3.0']
POM_LICENCE_DIST=repo

# POM project labeling
POM_NAME=KSSM
POM_DESCRIPTION=Simple State Machines in Kotlin (KSSM)
POM_ARTIFACT_ID=kssm
POM_PACKAGING=jar
GROUP=me.angrybyte.kssm

# POM developer config
POM_DEVELOPER_ID=milosmns
POM_DEVELOPER_NAME=Milos Marinkovic
POM_DEVELOPER_EMAIL=[email protected]
196 changes: 196 additions & 0 deletions kssm/gradle/scripts/gradle-maven-push.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,196 @@
apply plugin: 'com.jfrog.bintray'
apply plugin: 'com.github.dcendents.android-maven'

// sets the project version
version = VERSION_NAME
group = GROUP

// Bintray deployment config
def projectName = project.rootProject.name
def localPropertiesName = 'local.properties'
def isLocalBuild = project.rootProject.file(localPropertiesName).exists()
def uploadConfig = [
user : '',
apiKey : '',
gpgPassword: '',
ossUser : '',
ossPassword: ''
]
if (!isLocalBuild) {
// load from environment variables
println "# $projectName: '$localPropertiesName' not found, loading deployment config from environment variables"

uploadConfig.user = System.env.BINTRAY_USER
uploadConfig.apiKey = System.env.BINTRAY_API_KEY
uploadConfig.gpgPassword = System.env.BINTRAY_GPG_PASSWORD
uploadConfig.ossUser = System.env.BINTRAY_OSS_USER
uploadConfig.ossPassword = System.env.BINTRAY_OSS_PASSWORD
} else {
// load from local properties
println "# $projectName: '$localPropertiesName' found, loading deployment config from file"
Properties fileProperties = new Properties()
fileProperties.load(project.rootProject.file(localPropertiesName).newDataInputStream())

uploadConfig.user = fileProperties.getProperty('bintray.user')
uploadConfig.apiKey = fileProperties.getProperty('bintray.apikey')
uploadConfig.gpgPassword = fileProperties.getProperty('bintray.gpg.password')
uploadConfig.ossUser = fileProperties.getProperty('bintray.oss.user')
uploadConfig.ossPassword = fileProperties.getProperty('bintray.oss.password')
}

bintray {
user = uploadConfig.user
key = uploadConfig.apiKey

configurations = ['archives']
pkg {
repo = 'maven'
name = POM_ARTIFACT_ID
desc = POM_DESCRIPTION
websiteUrl = POM_URL
issueTrackerUrl = POM_ISSUE_URL
vcsUrl = POM_SCM_URL
licenses = ["Apache-2.0"]
publish = true
publicDownloadNumbers = true
// noinspection GroovyAssignabilityCheck
version {
desc = POM_DESCRIPTION
gpg {
sign = true // Determines whether to GPG sign the files. The default is false
passphrase = uploadConfig.gpgPassword // Optional. The passphrase for GPG signing
}

mavenCentralSync {
sync = true
user = uploadConfig.ossUser
password = uploadConfig.ossPassword
close = '1'
}
}
}
}

if (project.getPlugins().hasPlugin('com.android.application') || project.getPlugins().hasPlugin('com.android.library')) {
install {
repositories.mavenInstaller {
configuration = configurations.archives

pom.groupId = GROUP
pom.artifactId = POM_ARTIFACT_ID
pom.version = VERSION_NAME

pom.project {
name POM_NAME
packaging POM_PACKAGING
description POM_DESCRIPTION
url POM_URL

scm {
url POM_SCM_URL
connection POM_SCM_CONNECTION
developerConnection POM_SCM_DEV_CONNECTION
}

licenses {
license {
name POM_LICENCE_NAME
url POM_LICENCE_URL
distribution POM_LICENCE_DIST
}
}

developers {
developer {
id POM_DEVELOPER_ID
name POM_DEVELOPER_NAME
}
}
}
}
}

task androidJavadocs(type: Javadoc) {
source = android.sourceSets.main.java.source
classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
//failOnError true
println "# $projectName: Configured Android javadocs"
}

task androidJavadocsJar(type: Jar, dependsOn: androidJavadocs) {
classifier = 'javadoc'
from androidJavadocs.destinationDir
}

task androidSourcesJar(type: Jar) {
classifier = 'sources'
from android.sourceSets.main.java.source
}
} else {
install {
repositories.mavenInstaller {
pom.groupId = GROUP
pom.artifactId = POM_ARTIFACT_ID
pom.version = VERSION_NAME

pom.project {
name POM_NAME
packaging POM_PACKAGING
description POM_DESCRIPTION
url POM_URL

scm {
url POM_SCM_URL
connection POM_SCM_CONNECTION
developerConnection POM_SCM_DEV_CONNECTION
}

licenses {
license {
name POM_LICENCE_NAME
url POM_LICENCE_URL
distribution POM_LICENCE_DIST
}
}

developers {
developer {
id POM_DEVELOPER_ID
name POM_DEVELOPER_NAME
email POM_DEVELOPER_EMAIL
}
}
}
}
}

task sourcesJar(type: Jar, dependsOn: classes) {
classifier = 'sources'
from sourceSets.main.allSource
}

task javadocJar(type: Jar, dependsOn: javadoc) {
classifier = 'javadoc'
from javadoc.getDestinationDir()
//failOnError false
println "# $projectName: Configured JAR javadocs"
}
}

if (JavaVersion.current().isJava8Compatible()) {
allprojects {
tasks.withType(Javadoc) {
options.addStringOption('Xdoclint:none', '-quiet')
}
}
}

artifacts {
if (project.getPlugins().hasPlugin('com.android.application') || project.getPlugins().hasPlugin('com.android.library')) {
archives androidSourcesJar
archives androidJavadocsJar
} else {
archives sourcesJar
archives javadocJar
}
}

0 comments on commit 3b12321

Please sign in to comment.