Skip to content
This repository was archived by the owner on Oct 18, 2024. It is now read-only.

Commit f40593a

Browse files
committed
fix(gradle-plugin): do not apply gradle plugin to projects without buildscript (fixes #1491)
1 parent 433201b commit f40593a

File tree

8 files changed

+122
-8
lines changed

8 files changed

+122
-8
lines changed

gradle-plugin/src/main/java/com/itsaky/androidide/gradle/AndroidIDEInitScriptPlugin.kt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,13 @@ class AndroidIDEInitScriptPlugin : Plugin<Gradle> {
5555

5656
target.projectsLoaded { gradle ->
5757
gradle.rootProject.subprojects { sub ->
58+
if (!sub.buildFile.exists()) {
59+
// For subproject ':nested:module',
60+
// ':nested' represented as a 'Project', but it may or may not have a buildscript file
61+
// if the project doesn't have a buildscript, then the plugins should not be applied
62+
return@subprojects
63+
}
64+
5865
sub.buildscript.dependencies.apply {
5966
add("classpath", sub.ideDependency("gradle-plugin"))
6067
}

gradle-plugin/src/test/java/com/itsaky/androidide/gradle/AndroidIDEInitScriptPluginTest.kt

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,8 @@ package com.itsaky.androidide.gradle
1919

2020
import com.google.common.truth.Truth.assertThat
2121
import com.itsaky.androidide.buildinfo.BuildInfo
22-
import com.itsaky.androidide.utils.FileProvider
2322
import org.gradle.testkit.runner.BuildResult
24-
import org.gradle.testkit.runner.GradleRunner
25-
import org.gradle.testkit.runner.internal.PluginUnderTestMetadataReading
2623
import org.junit.jupiter.api.Test
27-
import java.io.File
28-
import java.io.FileNotFoundException
29-
import kotlin.io.path.pathString
3024

3125
/**
3226
* @author Akash Yadav
@@ -60,7 +54,9 @@ class AndroidIDEInitScriptPluginTest {
6054
for ((project, variants) in mapOf(":app" to arrayOf("demoDebug", "fullDebug"))) {
6155
for (variant in variants) {
6256
assertThat(result.output).contains(
63-
"Adding LogSender dependency (version '${depVersion(true)}') to variant '${variant}' of project '${project}'"
57+
"Adding LogSender dependency (version '${
58+
depVersion(true)
59+
}') to variant '${variant}' of project '${project}'"
6460
)
6561
}
6662
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/build
2+
build.gradle.kts
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
2+
plugins {
3+
id("com.android.application")
4+
@@PLUGINS@@
5+
}
6+
7+
android {
8+
namespace = "com.example.myapplication2"
9+
compileSdk = 33
10+
buildToolsVersion = "33.0.2"
11+
12+
defaultConfig {
13+
applicationId = "com.example.myapplication2"
14+
minSdk = 21
15+
targetSdk = 33
16+
versionCode = 1
17+
versionName = "1.0"
18+
19+
vectorDrawables {
20+
useSupportLibrary = true
21+
}
22+
}
23+
24+
compileOptions {
25+
sourceCompatibility = JavaVersion.VERSION_11
26+
targetCompatibility = JavaVersion.VERSION_11
27+
}
28+
29+
buildTypes {
30+
release {
31+
isMinifyEnabled = true
32+
proguardFiles(getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro")
33+
}
34+
}
35+
36+
buildFeatures {
37+
viewBinding = true
38+
39+
}
40+
41+
// LogSender must be applied to all the debuggable product flavors
42+
flavorDimensions += "version"
43+
productFlavors {
44+
create("demo") {
45+
dimension = "version"
46+
applicationIdSuffix = ".demo"
47+
versionNameSuffix = "-demo"
48+
}
49+
50+
create("full") {
51+
dimension = "version"
52+
applicationIdSuffix = ".full"
53+
versionNameSuffix = "-full"
54+
}
55+
}
56+
}
57+
58+
dependencies {
59+
implementation("androidx.appcompat:appcompat:1.6.1")
60+
implementation("androidx.constraintlayout:constraintlayout:2.1.4")
61+
implementation("com.google.android.material:material:1.9.0")
62+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Add project specific ProGuard rules here.
2+
# You can control the set of applied configuration files using the
3+
# proguardFiles setting in build.gradle.
4+
#
5+
# For more details, see
6+
# http://developer.android.com/guide/developing/tools/proguard.html
7+
8+
# If your project uses WebView with JS, uncomment the following
9+
# and specify the fully qualified class name to the JavaScript interface
10+
# class:
11+
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12+
# public *;
13+
#}
14+
15+
# Uncomment this to preserve the line number information for
16+
# debugging stack traces.
17+
#-keepattributes SourceFile,LineNumberTable
18+
19+
# If you keep the line number information, uncomment this to
20+
# hide the original source file name.
21+
#-renamesourcefileattribute SourceFile
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest
3+
xmlns:android="http://schemas.android.com/apk/res/android">
4+
<application android:label="@string/app_name"/>
5+
</manifest>
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<!--
2+
~ This file is part of AndroidIDE.
3+
~
4+
~ AndroidIDE is free software: you can redistribute it and/or modify
5+
~ it under the terms of the GNU General Public License as published by
6+
~ the Free Software Foundation, either version 3 of the License, or
7+
~ (at your option) any later version.
8+
~
9+
~ AndroidIDE is distributed in the hope that it will be useful,
10+
~ but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
~ GNU General Public License for more details.
13+
~
14+
~ You should have received a copy of the GNU General Public License
15+
~ along with AndroidIDE. If not, see <https://www.gnu.org/licenses/>.
16+
-->
17+
18+
<resources>
19+
<string name="app_name">Sample app</string>
20+
</resources>

gradle-plugin/src/test/resources/sample-project/settings.gradle.kts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@ dependencyResolutionManagement {
33
}
44

55
rootProject.name = "Sample App"
6-
include(":app")
6+
include(":app")
7+
include(":nested:app")

0 commit comments

Comments
 (0)