Skip to content

Commit

Permalink
Merge pull request #1 from MobileUpLLC/feature/publish-to-maven-central
Browse files Browse the repository at this point in the history
Publish to maven central
  • Loading branch information
aartikov authored Mar 5, 2021
2 parents 73e8c7d + 6b2acd9 commit d76c7fe
Show file tree
Hide file tree
Showing 7 changed files with 144 additions and 80 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Code Quality for Android
[ ![Download](https://api.bintray.com/packages/1117847002272/CodeQuality-Android/CodeQuality-Android/images/download.svg?version=1.0.0) ](https://bintray.com/1117847002272/CodeQuality-Android/CodeQuality-Android/1.0.0/link)[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
[![Maven Central](https://img.shields.io/maven-central/v/ru.mobileup/code-quality-android)](https://repo1.maven.org/maven2/ru/mobileup/code-quality-android) [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)

Gradle Plugin for integration of code quality tools with Gitlab CI.
It converts Detekt and Lint reports to compatible with [Gitlab Code Quality](https://docs.gitlab.com/ee/user/project/merge_requests/code_quality.html) format.
Expand All @@ -11,12 +11,12 @@ It converts Detekt and Lint reports to compatible with [Gitlab Code Quality](htt
buildscript {
repositories {
...
jcenter()
mavenCentral()
}
dependencies {
...
classpath 'ru.mobileup:code-quality-android:1.0.0'
classpath 'ru.mobileup:code-quality-android:1.0.1'
}
}
```
Expand Down
15 changes: 8 additions & 7 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
buildscript {
ext.kotlinVersion = '1.3.71'
ext.bintrayVersion = '1.8.5'
ext.kotlinVersion = '1.4.31'
ext.nexusStagingVersion = '0.22.0'
ext.dokkaVersion = '1.4.20'

repositories {
google()
Expand All @@ -9,15 +10,15 @@ buildscript {

dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion"
classpath "com.jfrog.bintray.gradle:gradle-bintray-plugin:$bintrayVersion"
classpath "io.codearte.gradle.nexus:gradle-nexus-staging-plugin:$nexusStagingVersion"
classpath("org.jetbrains.dokka:dokka-gradle-plugin:$dokkaVersion")
}
}

plugins {
id 'java-gradle-plugin'
}

apply plugin: 'kotlin'
apply plugin: 'java-gradle-plugin'
apply plugin: 'io.codearte.nexus-staging'
apply plugin: 'org.jetbrains.dokka'

repositories {
google()
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.4-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-6.8-all.zip
Empty file modified gradlew
100644 → 100755
Empty file.
182 changes: 120 additions & 62 deletions publish.gradle
Original file line number Diff line number Diff line change
@@ -1,95 +1,153 @@
apply plugin: 'maven-publish'
apply plugin: 'com.jfrog.bintray'
apply plugin: 'signing'

/**
* Publish:
* Fill local.properties according to template-for-local.properties
* ./gradlew build
* ./gradlew publishReleasePublicationToSonatypeRepository
* ./gradlew closeAndReleaseRepository
*
* More info: https://getstream.io/blog/publishing-libraries-to-mavencentral-2021/
*/

ext {
bintrayRepo = 'CodeQuality-Android'
bintrayName = 'CodeQuality-Android'
PUBLISH_GROUP_ID = 'ru.mobileup'
PUBLISH_ARTIFACT_ID = 'code-quality-android'
PUBLISH_VERSION = '1.0.1'
DESCRIPTION = 'Gradle plugin for integration with Gitlab Code Quality'

publishedGroupId = 'ru.mobileup'
libraryName = 'CodeQuality-Android'
artifact = 'code-quality-android'
GITHUB_USER = 'MobileUpLLC'
GITHUB_PROJECT = 'CodeQuality-Android'
LICENSE_NAME = 'MIT License'
LICENSE_URL = "https://github.com/${GITHUB_USER}/${GITHUB_PROJECT}/blob/master/LICENSE"

libraryDescription = 'Gradle plugin for integration with Gitlab Code Quality'
libraryVersion = '1.0.0'
DEVELOPER_ID = 'MobileUp'
DEVELOPER_NAME = 'MobileUp'
DEVELOPER_EMAIL = 'dev@mobileup.ru'
}

siteUrl = 'https://github.com/MobileUpLLC/CodeQuality-Android/'
gitUrl = 'https://github.com/MobileUpLLC/CodeQuality-Android.git'
task androidSourcesJar(type: Jar) {
archiveClassifier.set('sources')
if (project.plugins.findPlugin("com.android.library")) {
from android.sourceSets.main.java.srcDirs
from android.sourceSets.main.kotlin.srcDirs
} else {
from sourceSets.main.java.srcDirs
from sourceSets.main.kotlin.srcDirs
}
}

developerId = 'MobileUp'
developerName = 'MobileUp'
developerEmail = 'dev@mobileup.ru'
task javadocJar(type: Jar, dependsOn: dokkaJavadoc) {
archiveClassifier.set('javadoc')
from dokkaJavadoc.outputDirectory
}

licenseName = 'The MIT License'
licenseUrl = 'https://github.com/MobileUpLLC/CodeQuality-Android/blob/master/LICENSE'
allLicenses = ['MIT']
artifacts {
archives androidSourcesJar
archives javadocJar
}

java {
withJavadocJar()
withSourcesJar()
group = PUBLISH_GROUP_ID
version = PUBLISH_VERSION

ext["signing.keyId"] = ''
ext["signing.password"] = ''
ext["signing.secretKeyRingFile"] = ''
ext["ossrhUsername"] = ''
ext["ossrhPassword"] = ''
ext["sonatypeStagingProfileId"] = ''

File secretPropsFile = project.rootProject.file('local.properties')
if (secretPropsFile.exists()) {
Properties p = new Properties()
p.load(new FileInputStream(secretPropsFile))
p.each { name, value ->
ext[name] = value
}
} else {
ext["signing.keyId"] = System.getenv('SIGNING_KEY_ID')
ext["signing.password"] = System.getenv('SIGNING_PASSWORD')
ext["signing.secretKeyRingFile"] = System.getenv('SIGNING_SECRET_KEY_RING_FILE')
ext["ossrhUsername"] = System.getenv('OSSRH_USERNAME')
ext["ossrhPassword"] = System.getenv('OSSRH_PASSWORD')
ext["sonatypeStagingProfileId"] = System.getenv('SONATYPE_STAGING_PROFILE_ID')
}

// Create Maven Artifact
publishing {
publications {
codeQualityAndroid(MavenPublication) {
from components.java
groupId publishedGroupId
artifactId artifact
version libraryVersion
release(MavenPublication) {
groupId PUBLISH_GROUP_ID
artifactId PUBLISH_ARTIFACT_ID
version PUBLISH_VERSION
if (project.plugins.findPlugin("com.android.library")) {
artifact("$buildDir/outputs/aar/${project.getName()}-release.aar")
} else {
artifact("$buildDir/libs/${project.getName()}-${version}.jar")
}

artifact androidSourcesJar
artifact javadocJar

pom {
name = libraryName
description = libraryDescription
url = siteUrl
name = PUBLISH_ARTIFACT_ID
description = DESCRIPTION
url = "https://github.com/${GITHUB_USER}/${GITHUB_PROJECT}"
licenses {
license {
name = licenseName
url = licenseUrl
name = LICENSE_NAME
url = LICENSE_URL
}
}
developers {
developer {
id = developerId
name = developerName
email = developerEmail
id = DEVELOPER_ID
name = DEVELOPER_NAME
email = DEVELOPER_EMAIL
}
}
scm {
connection = gitUrl
developerConnection = gitUrl
url = siteUrl
connection = "scm:git:github.com/${GITHUB_USER}/${GITHUB_PROJECT}.git"
developerConnection = "scm:git:ssh://github.com/${GITHUB_USER}/${GITHUB_PROJECT}.git"
url = "https://github.com/${GITHUB_USER}/${GITHUB_PROJECT}/tree/main"
}
withXml {
def dependenciesNode = asNode().appendNode('dependencies')

project.configurations.implementation.allDependencies.each {
if (it.name != 'unspecified') {
def dependencyNode = dependenciesNode.appendNode('dependency')
dependencyNode.appendNode('groupId', it.group)
dependencyNode.appendNode('artifactId', it.name)
dependencyNode.appendNode('version', it.version)
}
}
}
}
}
}
}
repositories {
maven {
name = "sonatype"
def releasesRepoUrl = "https://oss.sonatype.org/service/local/staging/deploy/maven2/"
def snapshotsRepoUrl = "https://oss.sonatype.org/content/repositories/snapshots/"
url = version.endsWith('SNAPSHOT') ? snapshotsRepoUrl : releasesRepoUrl

// Publish to Bintray. Use "./gradlew bintrayUpload" to run it.
Properties properties = new Properties()
properties.load(file('local.properties').newDataInputStream())

bintray {
user = properties.getProperty('bintray.user')
key = properties.getProperty('bintray.apikey')
publications = ['codeQualityAndroid']

pkg {
repo = bintrayRepo
name = bintrayName
desc = libraryDescription
websiteUrl = siteUrl
vcsUrl = gitUrl
licenses = allLicenses
userOrg = properties.getProperty('bintray.userOrg')
publish = true
publicDownloadNumbers = true
version {
name = libraryVersion
desc = libraryDescription
gpg {
sign = true
passphrase = properties.getProperty('bintray.gpg.password')
credentials {
username ossrhUsername
password ossrhPassword
}
}
}
}

nexusStaging {
packageGroup = PUBLISH_GROUP_ID
stagingProfileId = sonatypeStagingProfileId
username = ossrhUsername
password = ossrhPassword
}

signing {
sign publishing.publications
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import ru.mobileup.codequality.issueconverter.Issue
import java.io.File
import java.io.OutputStreamWriter
import java.security.MessageDigest
import javax.xml.bind.DatatypeConverter

private class IssueJson(
val description: String,
Expand Down Expand Up @@ -52,8 +51,12 @@ class IssuesWriter {
}

private fun md5Hash(input: String): String {
val bytes = MessageDigest.getInstance("MD5")
return MessageDigest.getInstance("MD5")
.digest(input.toByteArray())
return DatatypeConverter.printHexBinary(bytes)
.toHexString()
}

private fun ByteArray.toHexString() = joinToString("") {
(0xFF and it.toInt()).toString(16).padStart(2, '0')
}
}
10 changes: 6 additions & 4 deletions template-for-local.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
sdk.dir=

bintray.user=
bintray.apikey=
bintray.userOrg=
bintray.gpg.password=
signing.keyId=
signing.password=
signing.secretKeyRingFile=
ossrhUsername=
ossrhPassword=
sonatypeStagingProfileId=ed1d05bd2f90

0 comments on commit d76c7fe

Please sign in to comment.