summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--autofill-parser/build.gradle.kts64
-rw-r--r--buildSrc/src/main/java/BintrayPublishing.kt102
-rw-r--r--buildSrc/src/main/java/PasswordStorePlugin.kt5
3 files changed, 107 insertions, 64 deletions
diff --git a/autofill-parser/build.gradle.kts b/autofill-parser/build.gradle.kts
index 35169989..9a4d423a 100644
--- a/autofill-parser/build.gradle.kts
+++ b/autofill-parser/build.gradle.kts
@@ -5,20 +5,6 @@ plugins {
`aps-plugin`
}
-// Type safety can sometimes suck
-fun getCredential(type: String): String {
- return when (type) {
- // Attempt to find credentials passed by -Pmaven.$type=
- "user", "password" -> (findProperty("maven.$type")
- // Fall back to MAVEN_$type from env
- ?: System.getenv("MAVEN_${type.toUpperCase()}"))?.toString()
- // Finally fallthrough to an empty string to let task configuration complete
- // even if actual publishing is going to fail
- ?: ""
- else -> throw IllegalArgumentException("Invalid credential type: $type")
- }
-}
-
android {
defaultConfig {
versionCode = 2
@@ -37,56 +23,6 @@ android {
}
}
-afterEvaluate {
- publishing {
- repositories {
- maven {
- name = "aps"
- url = uri("https://maven.msfjarvis.dev/android-password-store/${findProperty("POM_ARTIFACT_ID")}")
- credentials {
- username = getCredential("user")
- password = getCredential("password")
- }
- }
- }
- publications {
- create<MavenPublication>("apsMaven") {
- fun getKey(propertyName: String): String {
- return findProperty(propertyName)?.toString() ?: error("Failed to find property for $propertyName")
- }
-
- from(components.getByName("release"))
- groupId = getKey("GROUP")
- artifactId = getKey("POM_ARTIFACT_ID")
- version = getKey("VERSION_NAME")
- pom {
- name.set(getKey("POM_ARTIFACT_ID"))
- description.set(getKey("POM_ARTIFACT_DESCRIPTION"))
- url.set(getKey("POM_URL"))
- licenses {
- license {
- name.set(getKey("POM_LICENSE_NAME"))
- url.set(getKey("POM_LICENSE_URL"))
- }
- }
- developers {
- developer {
- id.set(getKey("POM_DEVELOPER_ID"))
- name.set(getKey("POM_DEVELOPER_NAME"))
- email.set(getKey("POM_DEVELOPER_EMAIL"))
- }
- }
- scm {
- connection.set(getKey("POM_SCM_CONNECTION"))
- developerConnection.set(getKey("POM_SCM_DEV_CONNECTION"))
- url.set(getKey("POM_SCM_URL"))
- }
- }
- }
- }
- }
-}
-
dependencies {
compileOnly(Dependencies.AndroidX.annotation)
implementation(Dependencies.AndroidX.autofill)
diff --git a/buildSrc/src/main/java/BintrayPublishing.kt b/buildSrc/src/main/java/BintrayPublishing.kt
new file mode 100644
index 00000000..6567a5ea
--- /dev/null
+++ b/buildSrc/src/main/java/BintrayPublishing.kt
@@ -0,0 +1,102 @@
+/*
+ * Copyright © 2014-2020 The Android Password Store Authors. All Rights Reserved.
+ * SPDX-License-Identifier: GPL-3.0-only
+ */
+
+import com.android.build.gradle.TestedExtension
+import java.util.Locale
+import org.gradle.api.Project
+import org.gradle.api.publish.PublishingExtension
+import org.gradle.api.publish.maven.MavenPublication
+import org.gradle.jvm.tasks.Jar
+import org.gradle.kotlin.dsl.create
+import org.gradle.kotlin.dsl.register
+
+/**
+ * Register the `sourcesJar` task so that our published artifacts can include them.
+ */
+internal fun TestedExtension.registerSourcesJarTask(project: Project) {
+ project.tasks.register<Jar>("sourcesJar") {
+ archiveClassifier.set("sources")
+ from(sourceSets.getByName("main").java.srcDirs)
+ }
+}
+
+/**
+ * Configures the `apsMaven` and `bintray` repositories along with an `aps` publication
+ */
+internal fun PublishingExtension.configureMavenPublication(project: Project) {
+ repositories {
+ maven {
+ name = "apsMaven"
+ url = project.uri("https://maven.msfjarvis.dev/android-password-store/${project.getKey("POM_ARTIFACT_ID")}")
+ credentials {
+ username = project.getCredential("user")
+ password = project.getCredential("password")
+ }
+ }
+ maven {
+ val artifactId = project.getKey("POM_ARTIFACT_ID")
+ name = "bintray"
+ url = project.uri("https://api.bintray.com/maven/android-password-store/$artifactId/$artifactId/;publish=1;override=0")
+ credentials {
+ username = project.getCredential("user")
+ password = project.getCredential("password")
+ }
+ }
+ }
+ publications {
+ create<MavenPublication>("aps") {
+ from(project.components.getByName("release"))
+ groupId = project.getKey("GROUP")
+ artifactId = project.getKey("POM_ARTIFACT_ID")
+ version = project.getKey("VERSION_NAME")
+ artifact(project.tasks.getByName("sourcesJar"))
+ configurePom(project)
+ }
+ }
+}
+
+private fun Project.getCredential(type: String): String {
+ return when (type) {
+ // Attempt to find credentials passed by -Pmaven.$type=
+ "user", "password" -> (findProperty("maven.$type")
+ // Fall back to MAVEN_$type from env
+ ?: System.getenv("MAVEN_${type.toUpperCase(Locale.ROOT)}"))?.toString()
+ // Finally fallthrough to an empty string to let task configuration complete
+ // even if actual publishing is going to fail
+ ?: ""
+ else -> throw IllegalArgumentException("Invalid credential type: $type")
+ }
+}
+
+private fun Project.getKey(propertyName: String): String {
+ return findProperty(propertyName)?.toString()
+ ?: error("Failed to find value for property: $propertyName")
+}
+
+private fun MavenPublication.configurePom(project: Project) {
+ pom {
+ name.set(project.getKey("POM_ARTIFACT_ID"))
+ description.set(project.getKey("POM_ARTIFACT_DESCRIPTION"))
+ url.set(project.getKey("POM_URL"))
+ licenses {
+ license {
+ name.set(project.getKey("POM_LICENSE_NAME"))
+ url.set(project.getKey("POM_LICENSE_URL"))
+ }
+ }
+ developers {
+ developer {
+ id.set(project.getKey("POM_DEVELOPER_ID"))
+ name.set(project.getKey("POM_DEVELOPER_NAME"))
+ email.set(project.getKey("POM_DEVELOPER_EMAIL"))
+ }
+ }
+ scm {
+ connection.set(project.getKey("POM_SCM_CONNECTION"))
+ developerConnection.set(project.getKey("POM_SCM_DEV_CONNECTION"))
+ url.set(project.getKey("POM_SCM_URL"))
+ }
+ }
+}
diff --git a/buildSrc/src/main/java/PasswordStorePlugin.kt b/buildSrc/src/main/java/PasswordStorePlugin.kt
index b8271f65..12cd764e 100644
--- a/buildSrc/src/main/java/PasswordStorePlugin.kt
+++ b/buildSrc/src/main/java/PasswordStorePlugin.kt
@@ -11,6 +11,7 @@ import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.api.plugins.JavaLibraryPlugin
import org.gradle.api.plugins.JavaPlugin
+import org.gradle.api.publish.PublishingExtension
import org.gradle.api.tasks.compile.JavaCompile
import org.gradle.kotlin.dsl.getByType
import org.gradle.kotlin.dsl.withType
@@ -35,6 +36,10 @@ class PasswordStorePlugin : Plugin<Project> {
}
is LibraryPlugin -> {
project.extensions.getByType<TestedExtension>().configureCommonAndroidOptions()
+ project.extensions.getByType<TestedExtension>().registerSourcesJarTask(project)
+ project.afterEvaluate {
+ project.extensions.getByType<PublishingExtension>().configureMavenPublication(project)
+ }
}
is AppPlugin -> {
project.extensions.getByType<BaseAppModuleExtension>().configureAndroidApplicationOptions(project)