Skip to content

Commit

Permalink
Merge pull request #38 from androidx/cleanup
Browse files Browse the repository at this point in the history
Clean up bundling of project(":core")
  • Loading branch information
liutikas authored Dec 21, 2023
2 parents d222202 + 134a2dd commit 3089544
Show file tree
Hide file tree
Showing 6 changed files with 101 additions and 10 deletions.
30 changes: 30 additions & 0 deletions buildlogic/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* Copyright 2023 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
*
* http://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.
*
*/

plugins {
id("java-gradle-plugin")
alias(libs.plugins.kotlin.jvm)
}

gradlePlugin {
plugins {
create("bundlePlugin") {
id = "bundle"
implementationClass = "androidx.build.BundlePlugin"
}
}
}
18 changes: 18 additions & 0 deletions buildlogic/settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
dependencyResolutionManagement {
versionCatalogs {
create("libs") {
from(files("../gradle/libs.versions.toml"))
}
}
repositoriesMode = RepositoriesMode.FAIL_ON_PROJECT_REPOS
repositories {
mavenCentral()
}
}

pluginManagement {
repositories {
mavenCentral()
gradlePluginPortal()
}
}
45 changes: 45 additions & 0 deletions buildlogic/src/main/kotlin/androidx/build/BundlePlugin.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* Copyright 2023 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
*
* http://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.
*
*/

package androidx.build

import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.api.tasks.bundling.Jar
import org.gradle.plugin.devel.tasks.PluginUnderTestMetadata

class BundlePlugin : Plugin<Project> {
override fun apply(project: Project) {
val bundleInside = project.configurations.create("bundleInside") {
it.isTransitive = false
it.isVisible = false
it.isCanBeResolved = true
}
project.afterEvaluate {
project.configurations.getByName("compileOnly").extendsFrom(bundleInside)
project.configurations.getByName("testImplementation").extendsFrom(bundleInside)
val jarsToBundle = bundleInside.incoming.artifactView { }.files
project.tasks.named("jar").configure { jarTask ->
jarTask as Jar
jarTask.from(project.provider { jarsToBundle.map { if (it.isDirectory) { it } else { project.zipTree(it) } } })
}
project.tasks.withType(PluginUnderTestMetadata::class.java).configureEach {
it.pluginClasspath.from(jarsToBundle)
}
}
}
}
8 changes: 3 additions & 5 deletions gcpbuildcache/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,14 @@
plugins {
id("maven-publish")
id("signing")
id("bundle")
alias(libs.plugins.gradle.publish)
alias(libs.plugins.kotlin.jvm)
}

// Bundle core library directly as we only get to publish one jar per plugin in Gradle Plugin Portal
sourceSets.main {
java.srcDir("../core/src/main/kotlin")
}

dependencies {
// Bundle core library directly as we only get to publish one jar per plugin in Gradle Plugin Portal
bundleInside(project(":core"))
implementation(libs.google.cloud.storage)
implementation(libs.retrofit.core)
implementation(libs.retrofit.converter.gson)
Expand Down
8 changes: 3 additions & 5 deletions s3buildcache/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,14 @@
plugins {
id("maven-publish")
id("signing")
id("bundle")
alias(libs.plugins.gradle.publish)
alias(libs.plugins.kotlin.jvm)
}

// Bundle core library directly as we only get to publish one jar per plugin in Gradle Plugin Portal
sourceSets.main {
java.srcDir("../core/src/main/kotlin")
}

dependencies {
// Bundle core library directly as we only get to publish one jar per plugin in Gradle Plugin Portal
bundleInside(project(":core"))
implementation(libs.retrofit.core)
implementation(libs.retrofit.converter.gson)
implementation(platform(libs.amazon.bom))
Expand Down
2 changes: 2 additions & 0 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,5 @@ rootProject.name = "gcp-gradle-build-cache"
include("core")
include("gcpbuildcache")
include("s3buildcache")

includeBuild("buildlogic")

0 comments on commit 3089544

Please sign in to comment.