fix(gradle-plugin): do not apply gradle plugin to projects without buildscript (fixes #1491)

This commit is contained in:
Akash Yadav
2023-11-24 13:55:38 +05:30
parent 433201bd4d
commit f40593a177
8 changed files with 122 additions and 8 deletions
@@ -55,6 +55,13 @@ class AndroidIDEInitScriptPlugin : Plugin<Gradle> {
target.projectsLoaded { gradle ->
gradle.rootProject.subprojects { sub ->
if (!sub.buildFile.exists()) {
// For subproject ':nested:module',
// ':nested' represented as a 'Project', but it may or may not have a buildscript file
// if the project doesn't have a buildscript, then the plugins should not be applied
return@subprojects
}
sub.buildscript.dependencies.apply {
add("classpath", sub.ideDependency("gradle-plugin"))
}
@@ -19,14 +19,8 @@ package com.itsaky.androidide.gradle
import com.google.common.truth.Truth.assertThat
import com.itsaky.androidide.buildinfo.BuildInfo
import com.itsaky.androidide.utils.FileProvider
import org.gradle.testkit.runner.BuildResult
import org.gradle.testkit.runner.GradleRunner
import org.gradle.testkit.runner.internal.PluginUnderTestMetadataReading
import org.junit.jupiter.api.Test
import java.io.File
import java.io.FileNotFoundException
import kotlin.io.path.pathString
/**
* @author Akash Yadav
@@ -60,7 +54,9 @@ class AndroidIDEInitScriptPluginTest {
for ((project, variants) in mapOf(":app" to arrayOf("demoDebug", "fullDebug"))) {
for (variant in variants) {
assertThat(result.output).contains(
"Adding LogSender dependency (version '${depVersion(true)}') to variant '${variant}' of project '${project}'"
"Adding LogSender dependency (version '${
depVersion(true)
}') to variant '${variant}' of project '${project}'"
)
}
}
@@ -0,0 +1,2 @@
/build
build.gradle.kts
@@ -0,0 +1,62 @@
plugins {
id("com.android.application")
@@PLUGINS@@
}
android {
namespace = "com.example.myapplication2"
compileSdk = 33
buildToolsVersion = "33.0.2"
defaultConfig {
applicationId = "com.example.myapplication2"
minSdk = 21
targetSdk = 33
versionCode = 1
versionName = "1.0"
vectorDrawables {
useSupportLibrary = true
}
}
compileOptions {
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
}
buildTypes {
release {
isMinifyEnabled = true
proguardFiles(getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro")
}
}
buildFeatures {
viewBinding = true
}
// LogSender must be applied to all the debuggable product flavors
flavorDimensions += "version"
productFlavors {
create("demo") {
dimension = "version"
applicationIdSuffix = ".demo"
versionNameSuffix = "-demo"
}
create("full") {
dimension = "version"
applicationIdSuffix = ".full"
versionNameSuffix = "-full"
}
}
}
dependencies {
implementation("androidx.appcompat:appcompat:1.6.1")
implementation("androidx.constraintlayout:constraintlayout:2.1.4")
implementation("com.google.android.material:material:1.9.0")
}
@@ -0,0 +1,21 @@
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html
# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}
# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable
# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest
xmlns:android="http://schemas.android.com/apk/res/android">
<application android:label="@string/app_name"/>
</manifest>
@@ -0,0 +1,20 @@
<!--
~ This file is part of AndroidIDE.
~
~ AndroidIDE is free software: you can redistribute it and/or modify
~ it under the terms of the GNU General Public License as published by
~ the Free Software Foundation, either version 3 of the License, or
~ (at your option) any later version.
~
~ AndroidIDE is distributed in the hope that it will be useful,
~ but WITHOUT ANY WARRANTY; without even the implied warranty of
~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
~ GNU General Public License for more details.
~
~ You should have received a copy of the GNU General Public License
~ along with AndroidIDE. If not, see <https://www.gnu.org/licenses/>.
-->
<resources>
<string name="app_name">Sample app</string>
</resources>
@@ -3,4 +3,5 @@ dependencyResolutionManagement {
}
rootProject.name = "Sample App"
include(":app")
include(":app")
include(":nested:app")