From 89620ab0adef601456f08e1fd0754fbc7201b6d0 Mon Sep 17 00:00:00 2001 From: Jeziel Lago Date: Tue, 19 May 2020 09:52:12 -0300 Subject: [PATCH] Configure artifact publish --- README.md | 23 ++++++++----- app/build.gradle | 9 ----- build.gradle | 2 +- gradle.properties | 6 ++++ lintversioncheck/build.gradle.kts | 34 +++++++++++++++++++ .../versioncheck/VersionCheckerGradleLint.kt | 5 ++- 6 files changed, 59 insertions(+), 20 deletions(-) diff --git a/README.md b/README.md index 90fa606..eff5a52 100644 --- a/README.md +++ b/README.md @@ -3,6 +3,20 @@ Warning on new versions available even when using Kotlin-DSL plugin. ![](example.png) +## How to use? +- Add lint dependency +```groovy +dependencies { + lintChecks "com.picpay.gradlelint:version-checker:VERSION" +} +``` +- Enable lint with `lintOptions` +```groovy +lintOptions { + enable "VersionCheckerGradleLint" +} +``` + ## `buildSrc` module with kotlin-dsl plugin - `buildSrc/src/main/java/Dependencies.kt` ```kotlin @@ -24,13 +38,4 @@ object TestLibs { val junit4 = "junit:junit:${Versions.junit4Version}" } -``` - -## How install? -- Copy latest release `.jar` to `${USER_DIR}/.android/lint/` -- Enable lint with `lintOptions` -```groovy - lintOptions { - enable "VersionCheckerGradleLint" - } ``` \ No newline at end of file diff --git a/app/build.gradle b/app/build.gradle index 30c2917..b373e12 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -1,6 +1,4 @@ apply plugin: 'com.android.application' -apply plugin: 'kotlin-android' -apply plugin: 'kotlin-android-extensions' android { compileSdkVersion 29 @@ -30,17 +28,10 @@ android { } dependencies { - implementation fileTree(dir: 'libs', include: ['*.jar']) - implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" implementation Libs.appCompat implementation Libs.retrofit implementation Libs.playServiceLocation implementation Libs.koinCore implementation Libs.mpchart - implementation 'androidx.core:core-ktx:1.2.0' - implementation 'androidx.constraintlayout:constraintlayout:1.1.3' testImplementation TestLibs.junit - androidTestImplementation 'androidx.test.ext:junit:1.1.1' - androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0' - } diff --git a/build.gradle b/build.gradle index 48895e7..cb9ba6a 100644 --- a/build.gradle +++ b/build.gradle @@ -1,7 +1,7 @@ // Top-level build file where you can add configuration options common to all sub-projects/modules. buildscript { - ext.kotlin_version = '1.3.71' + ext.kotlin_version = '1.3.72' repositories { google() jcenter() diff --git a/gradle.properties b/gradle.properties index 23339e0..b29e6c9 100644 --- a/gradle.properties +++ b/gradle.properties @@ -19,3 +19,9 @@ android.useAndroidX=true android.enableJetifier=true # Kotlin code style for this project: "official" or "obsolete": kotlin.code.style=official + +# Info to Maven Publish +library.version=0.1.0 +library.groupId=com.picpay.gradlelint +library.artifactId=version-checker +library.repository=version-checker-gradle-lint diff --git a/lintversioncheck/build.gradle.kts b/lintversioncheck/build.gradle.kts index 39c5257..a40f871 100644 --- a/lintversioncheck/build.gradle.kts +++ b/lintversioncheck/build.gradle.kts @@ -1,7 +1,11 @@ +import java.text.SimpleDateFormat +import java.util.Date + plugins { id("java-library") id("kotlin") id("jacoco") + id("maven-publish") } repositories { @@ -54,3 +58,33 @@ tasks { executionData.from("$buildDir/jacoco/test.exec") } } + +publishing { + publications { + register("publishArtifact", MavenPublication::class) { + from(components["java"]) + groupId = project.findProperty("library.groupId") as String + artifactId = project.findProperty("library.artifactId") as String + version = (project.findProperty("library.version") as String) + versionSuffix() + } + } + repositories { + maven { + name = "GitHubPackages" + val repository = project.findProperty("library.repository") + url = uri("https://maven.pkg.github.com/PicPay/$repository") + credentials { + username = System.getenv("GITHUB_USER") + password = System.getenv("GITHUB_USER_TOKEN") + } + } + } +} + +fun versionSuffix(): String { + val sufix = System.getenv("VERSION_SUFIX").orEmpty() + if (sufix.isNotEmpty()) { + return "$sufix-${SimpleDateFormat("yyyyMMddHHmmss").format(Date())}" + } + return sufix +} diff --git a/lintversioncheck/src/main/java/com/picpay/gradlelint/versioncheck/VersionCheckerGradleLint.kt b/lintversioncheck/src/main/java/com/picpay/gradlelint/versioncheck/VersionCheckerGradleLint.kt index fb44928..572a052 100644 --- a/lintversioncheck/src/main/java/com/picpay/gradlelint/versioncheck/VersionCheckerGradleLint.kt +++ b/lintversioncheck/src/main/java/com/picpay/gradlelint/versioncheck/VersionCheckerGradleLint.kt @@ -87,7 +87,10 @@ class VersionCheckerGradleLint : Detector(), Detector.GradleScanner { val linesFromDependencyFile = getDependenciesFileLines( dependenciesFile = File( getBuildSrcDir(context.project.dir).absolutePath, - "src/main/java/$dependenciesFileName.kt" + "src${File.separator}" + + "main${File.separator}" + + "java${File.separator}" + + "$dependenciesFileName.kt" ) )