Skip to content

Commit

Permalink
Add published library convention plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
bentrengrove committed Nov 26, 2024
1 parent d7ae815 commit d54e2b5
Show file tree
Hide file tree
Showing 15 changed files with 66 additions and 81 deletions.
11 changes: 1 addition & 10 deletions adaptive/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,8 @@
plugins {
alias(libs.plugins.accompanist.android.library)
alias(libs.plugins.accompanist.android.library.compose)
alias(libs.plugins.accompanist.android.library.published)
alias(libs.plugins.accompanist.android.lint)

id(libs.plugins.jetbrains.dokka.get().pluginId)
id(libs.plugins.gradle.metalava.get().pluginId)
id(libs.plugins.vanniktech.maven.publish.get().pluginId)
}

android {
Expand All @@ -40,12 +37,6 @@ android {
}
}

metalava {
sourcePaths.setFrom("src/main")
filename.set("api/current.api")
reportLintsAsErrors.set(true)
}

dependencies {
api(libs.compose.foundation.foundation)
api(libs.compose.ui.ui)
Expand Down
5 changes: 5 additions & 0 deletions build-logic/convention/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ dependencies {
compileOnly(libs.android.tools.common)
compileOnly(libs.compose.gradlePlugin)
compileOnly(libs.kotlin.gradlePlugin)
compileOnly(libs.metalavaGradle)
implementation(libs.truth)
}

Expand All @@ -63,6 +64,10 @@ gradlePlugin {
id = "accompanist.android.lint"
implementationClass = "AndroidLintConventionPlugin"
}
register("androidLibraryPublished") {
id = "accompanist.android.library.published"
implementationClass = "AndroidLibraryPublishedConventionPlugin"
}
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

import com.android.build.gradle.LibraryExtension
import com.google.accompanist.configureKotlinAndroid
import com.google.accompanist.libs
import me.tylerbwong.gradle.metalava.extension.MetalavaExtension
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.kotlin.dsl.configure
Expand All @@ -34,13 +36,15 @@ class AndroidLibraryConventionPlugin : Plugin<Project> {
configureKotlinAndroid(this)
defaultConfig.targetSdk = 34
defaultConfig.testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"

buildFeatures.buildConfig = false

testOptions.animationsDisabled = true
// The resource prefix is derived from the module name,
// so resources inside ":core:module1" must be prefixed with "core_module1_"
resourcePrefix = path.split("""\W""".toRegex()).drop(1).distinct().joinToString(separator = "_").lowercase() + "_"
}

dependencies {
add("androidTestImplementation", kotlin("test"))
add("testImplementation", kotlin("test"))
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import me.tylerbwong.gradle.metalava.extension.MetalavaExtension
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.kotlin.dsl.configure

/*
* Copyright 2024 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

class AndroidLibraryPublishedConventionPlugin : Plugin<Project> {
override fun apply(target: Project) {
with(target) {
with(pluginManager) {
apply("me.tylerbwong.gradle.metalava")
apply("org.jetbrains.dokka")
apply("com.vanniktech.maven.publish")
}

extensions.configure<MetalavaExtension> {
sourcePaths.setFrom("src/main")
filename.set("api/current.api")
reportLintsAsErrors.set(true)
}
}
}
}
1 change: 1 addition & 0 deletions build-logic/settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ dependencyResolutionManagement {
repositories {
google()
mavenCentral()
gradlePluginPortal()
}
versionCatalogs {
create("libs") {
Expand Down
18 changes: 8 additions & 10 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import org.jetbrains.dokka.gradle.DokkaMultiModuleTask

/*
* Copyright 2020 The Android Open Source Project
*
Expand All @@ -18,35 +20,31 @@ buildscript {
repositories {
google()
mavenCentral()
gradlePluginPortal()
}

dependencies {
classpath libs.android.tools.build.gradle
classpath libs.android.gradlePlugin
classpath libs.kotlin.gradlePlugin

classpath libs.gradleMavenPublishPlugin

classpath libs.metalavaGradle

classpath libs.affectedmoduledetector
}
}

plugins {
id "com.diffplug.spotless" version "6.5.2"
alias(libs.plugins.android.library) apply false
alias(libs.plugins.android.kotlin) apply false
alias(libs.plugins.jetbrains.dokka)
alias(libs.plugins.compose.plugin) apply false
alias(libs.plugins.accompanist.android.library) apply false
alias(libs.plugins.accompanist.android.library.compose) apply false
alias(libs.plugins.accompanist.android.library.published) apply false
alias(libs.plugins.accompanist.android.lint) apply false
alias(libs.plugins.gradle.metalava) apply false
alias(libs.plugins.vanniktech.maven.publish) apply false
}

apply plugin: 'com.dropbox.affectedmoduledetector'
apply plugin: 'com.diffplug.spotless'

tasks.withType(org.jetbrains.dokka.gradle.DokkaMultiModuleTask).configureEach {
tasks.withType(DokkaMultiModuleTask).configureEach {
outputDirectory = rootProject.file('docs/api')
failOnWarning = true
}
Expand Down
11 changes: 1 addition & 10 deletions drawablepainter/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -18,23 +18,14 @@
plugins {
alias(libs.plugins.accompanist.android.library)
alias(libs.plugins.accompanist.android.library.compose)
alias(libs.plugins.accompanist.android.library.published)
alias(libs.plugins.accompanist.android.lint)

id(libs.plugins.jetbrains.dokka.get().pluginId)
id(libs.plugins.gradle.metalava.get().pluginId)
id(libs.plugins.vanniktech.maven.publish.get().pluginId)
}

android {
namespace = "com.google.accompanist.drawablepainter"
}

metalava {
sourcePaths.setFrom("src/main")
filename.set("api/current.api")
reportLintsAsErrors.set(true)
}

dependencies {
implementation(libs.compose.ui.ui)
implementation(libs.kotlin.coroutines.android)
Expand Down
4 changes: 2 additions & 2 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ androidxtest = "1.6.1"
androidxnavigation = "2.7.7"
androidxWindow = "1.0.0"

metalava = "0.3.2"
metalava = "0.3.5"
vanniktechPublish = "0.25.2"

[libraries]
Expand Down Expand Up @@ -118,7 +118,7 @@ vanniktech-maven-publish = { id = "com.vanniktech.maven.publish", version.ref =
compose-plugin = { id = "org.jetbrains.kotlin.plugin.compose", version.ref = "kotlin" }

#build-logic plugins
accompanist-android-application-compose = { id = "accompanist.android.application.compose" }
accompanist-android-library = { id = "accompanist.android.library" }
accompanist-android-library-compose = { id = "accompanist.android.library.compose" }
accompanist-android-library-published = { id = "accompanist.android.library.published" }
accompanist-android-lint = { id = "accompanist.android.lint" }
11 changes: 1 addition & 10 deletions navigation-animation/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -18,23 +18,14 @@
plugins {
alias(libs.plugins.accompanist.android.library)
alias(libs.plugins.accompanist.android.library.compose)
alias(libs.plugins.accompanist.android.library.published)
alias(libs.plugins.accompanist.android.lint)

id(libs.plugins.jetbrains.dokka.get().pluginId)
id(libs.plugins.gradle.metalava.get().pluginId)
id(libs.plugins.vanniktech.maven.publish.get().pluginId)
}

android {
namespace = "com.google.accompanist.navigation.animation"
}

metalava {
sourcePaths.setFrom("src/main")
filename.set("api/current.api")
reportLintsAsErrors.set(true)
}

dependencies {
api(libs.androidx.navigation.compose)
implementation(libs.compose.animation.animation)
Expand Down
11 changes: 1 addition & 10 deletions navigation-material/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -18,23 +18,14 @@
plugins {
alias(libs.plugins.accompanist.android.library)
alias(libs.plugins.accompanist.android.library.compose)
alias(libs.plugins.accompanist.android.library.published)
alias(libs.plugins.accompanist.android.lint)

id(libs.plugins.jetbrains.dokka.get().pluginId)
id(libs.plugins.gradle.metalava.get().pluginId)
id(libs.plugins.vanniktech.maven.publish.get().pluginId)
}

android {
namespace = "com.google.accompanist.navigation.material"
}

metalava {
sourcePaths.setFrom("src/main")
filename.set("api/current.api")
reportLintsAsErrors.set(true)
}

dependencies {
api(libs.androidx.navigation.compose)
implementation(libs.compose.foundation.foundation)
Expand Down
10 changes: 1 addition & 9 deletions permissions/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,8 @@
plugins {
alias(libs.plugins.accompanist.android.library)
alias(libs.plugins.accompanist.android.library.compose)
alias(libs.plugins.accompanist.android.library.published)
alias(libs.plugins.accompanist.android.lint)
id(libs.plugins.jetbrains.dokka.get().pluginId)
id(libs.plugins.gradle.metalava.get().pluginId)
id(libs.plugins.vanniktech.maven.publish.get().pluginId)
}

android {
Expand All @@ -32,12 +30,6 @@ android {
}
}

metalava {
sourcePaths.setFrom("src/main")
filename.set("api/current.api")
reportLintsAsErrors.set(true)
}

dependencies {
implementation(libs.androidx.activity.compose)
implementation(libs.compose.foundation.foundation)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ class MainActivity : ListActivity() {
data += temp
}

@Deprecated("Deprecated in Java")
override fun onListItemClick(l: ListView, v: View, position: Int, id: Long) {
val map = l.getItemAtPosition(position) as Map<*, *>
val intent = map["intent"] as Intent?
Expand Down
1 change: 0 additions & 1 deletion settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ pluginManagement {
}

dependencyResolutionManagement {
repositoriesMode = RepositoriesMode.FAIL_ON_PROJECT_REPOS
repositories {
google()
mavenCentral()
Expand Down
11 changes: 1 addition & 10 deletions systemuicontroller/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,8 @@
plugins {
alias(libs.plugins.accompanist.android.library)
alias(libs.plugins.accompanist.android.library.compose)
alias(libs.plugins.accompanist.android.library.published)
alias(libs.plugins.accompanist.android.lint)

id(libs.plugins.jetbrains.dokka.get().pluginId)
id(libs.plugins.gradle.metalava.get().pluginId)
id(libs.plugins.vanniktech.maven.publish.get().pluginId)
}

android {
Expand All @@ -48,12 +45,6 @@ android {
}
}

metalava {
sourcePaths.setFrom("src/main")
filename.set("api/current.api")
reportLintsAsErrors.set(true)
}

dependencies {
implementation(libs.androidx.core)
implementation(libs.compose.ui.ui)
Expand Down
10 changes: 1 addition & 9 deletions testharness/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,8 @@
plugins {
alias(libs.plugins.accompanist.android.library)
alias(libs.plugins.accompanist.android.library.compose)
alias(libs.plugins.accompanist.android.library.published)
alias(libs.plugins.accompanist.android.lint)
id(libs.plugins.jetbrains.dokka.get().pluginId)
id(libs.plugins.gradle.metalava.get().pluginId)
id(libs.plugins.vanniktech.maven.publish.get().pluginId)
}

android {
Expand Down Expand Up @@ -53,12 +51,6 @@ android {
}
}

metalava {
sourcePaths.setFrom("src/main")
filename.set("api/current.api")
reportLintsAsErrors.set(true)
}

dependencies {
implementation(libs.compose.foundation.foundation)
implementation(libs.androidx.core)
Expand Down

0 comments on commit d54e2b5

Please sign in to comment.