Skip to content

Commit

Permalink
Fix issue with kotlin-kapt plugin during project build process.
Browse files Browse the repository at this point in the history
  • Loading branch information
vsnappy1 committed Nov 23, 2024
1 parent 6937e1e commit 836361d
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 22 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ plugins {
id("com.android.application") version "8.0.1" apply false
id("org.jetbrains.kotlin.android") version "1.8.21" apply false
...
id("dev.randos.resourcemanager") version "0.0.6" apply false // Add ResourceManager plugin
id("dev.randos.resourcemanager") version "0.0.7" apply false // Add ResourceManager plugin
}
```
- If your project uses the buildscript block.
Expand All @@ -25,7 +25,7 @@ buildScripts {
classpath "com.android.tools.build:gradle:8.0.1"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.8.21"
...
classpath 'dev.randos:resourcemanager:0.0.6' // Add ResourceManager plugin
classpath 'dev.randos:resourcemanager:0.0.7' // Add ResourceManager plugin
}
}
```
Expand Down
4 changes: 0 additions & 4 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,4 @@
plugins {
alias(libs.plugins.jetbrains.kotlin.jvm) apply false
alias(libs.plugins.ktlint) apply false
}

ext {
set("agp", "7.0.0")
}
11 changes: 7 additions & 4 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
[versions]
jetbrainsKotlinJvm = "1.9.0"
kotlin = "1.9.22"
ktlint = "12.1.1"
junit = "4.12"
mockk = "1.13.13"
agp = "7.0.0"
gradlePluginPublish = "1.3.0"

[libraries]
junit = { group = "junit", name = "junit", version.ref = "junit" }
mockk = {group = "io.mockk", name = "mockk", version.ref = "mockk"}
android-tools = {group = "com.android.tools.build", name = "gradle", version.ref = "agp" }
kotlin-gradle-plugin = {group = "org.jetbrains.kotlin", name = "kotlin-gradle-plugin", version.ref = "kotlin"}

[plugins]
jetbrains-kotlin-jvm = { id = "org.jetbrains.kotlin.jvm", version.ref = "jetbrainsKotlinJvm" }
jetbrains-kotlin-jvm = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin" }
ktlint = { id = "org.jlleitschuh.gradle.ktlint", version.ref = "ktlint" }


gradle-plugin-publish = { id = "com.gradle.plugin-publish", version.ref = "gradlePluginPublish" }
20 changes: 11 additions & 9 deletions resourcemanager/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,25 +1,27 @@
import org.jlleitschuh.gradle.ktlint.reporter.ReporterType

plugins {
`java-gradle-plugin`
`kotlin-dsl`
kotlin("jvm")
id("java-gradle-plugin")
id("com.gradle.plugin-publish") version "1.3.0"
id("maven-publish")
id("org.jlleitschuh.gradle.ktlint")
`maven-publish`
alias(libs.plugins.gradle.plugin.publish)
alias(libs.plugins.jetbrains.kotlin.jvm)
alias(libs.plugins.ktlint)
jacoco
}
apply(from = "../gradle/jacoco.gradle.kts")

val agp: String by project
val kotlinVersion: String by project
val pluginGroup = "dev.randos"
val pluginVersion = "0.0.6"
val pluginVersion = "0.0.7"
val pluginName = "resourcemanager"

dependencies {
implementation(gradleApi())
implementation(localGroovy())
compileOnly("com.android.tools.build:gradle:$agp")
compileOnly(gradleApi())
compileOnly(localGroovy())
compileOnly(libs.android.tools)
compileOnly(libs.kotlin.gradle.plugin)
testImplementation(libs.junit)
testImplementation(libs.mockk)
testImplementation(gradleTestKit())
Expand Down
17 changes: 15 additions & 2 deletions resourcemanager/src/main/kotlin/ResourceManagerPlugin.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ import dev.randos.resourcemanager.manager.ModuleManager
import dev.randos.resourcemanager.manager.ResourceManager
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.api.tasks.compile.JavaCompile
import org.gradle.kotlin.dsl.withType
import org.jetbrains.kotlin.gradle.tasks.KaptGenerateStubs
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
import task.ResourceManagerMigrationTask
import java.io.File

Expand Down Expand Up @@ -38,10 +42,19 @@ class ResourceManagerPlugin : Plugin<Project> {
}

// Ensure that the "generateResourceManager" task runs before any compile task.
project.tasks.matching { it.name.startsWith("compile") }
.configureEach {
project.tasks.withType<KotlinCompile>().configureEach {
dependsOn(generateResourceManagerTask)
}
project.tasks.withType<JavaCompile>().configureEach {
dependsOn(generateResourceManagerTask)
}

// Specifically handle kapt stubs generation in case if consuming project has kotlin-kapt plugin applied.
project.pluginManager.withPlugin("kotlin-kapt") {
project.tasks.withType<KaptGenerateStubs>().configureEach {
dependsOn(generateResourceManagerTask)
}
}

// Add the generated file to the Kotlin source sets so that it can be used as part of the build.
project.extensions.getByType(BaseExtension::class.java)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,8 @@ internal class MigrationManager(
if (matchResultImport?.groups?.size == 2) {
currentResourceImportStatement = matchResultImport.groups[0]?.value.orEmpty()
currentResourceImportStatementIndex = index
// Since we may be including a new line, increment index.
index++
}

var matchResultResources: Sequence<MatchResult>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ internal class ResourceManager(
list.add(
Resource(
type = ResourceType.DRAWABLES,
moduleDetails = ModuleDetails(module, namespace, File(resFile, "drawable"))
moduleDetails = ModuleDetails(module, namespace, File(resFile, drawableDirectory.name))
)
)
}
Expand Down

0 comments on commit 836361d

Please sign in to comment.