Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clean up bundling of project(":core") #38

Merged
merged 1 commit into from
Dec 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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")