Skip to content

Commit

Permalink
Merge pull request #9 from makeevrserg/updated-info-root
Browse files Browse the repository at this point in the history
add auto hierarchy group
  • Loading branch information
makeevrserg committed Jun 8, 2024
2 parents ed0eab3 + 160d930 commit 4357f3a
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 5 deletions.
1 change: 1 addition & 0 deletions build-logic/plugins/convention/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ kotlin {
}

dependencies {
compileOnly(libs.android.toolsBuild)
compileOnly(libs.kotlin.gradlePlugin)
compileOnly(files(libs.javaClass.superclass.protectionDomain.codeSource.location))
implementation(libs.lint.detekt.gradle)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,32 @@
package ru.astrainteractive.gradleplugin

import com.android.build.gradle.BaseExtension
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.kotlin.dsl.findByType
import ru.astrainteractive.gradleplugin.property.extension.ModelPropertyValueExt.hierarchyGroup
import ru.astrainteractive.gradleplugin.property.extension.ModelPropertyValueExt.requireProjectInfo

class InfoRootPlugin : Plugin<Project> {
override fun apply(target: Project) {
val projectInfo = target.requireProjectInfo
target.rootProject.allprojects {
group = projectInfo.group
version = projectInfo.versionString
description = projectInfo.description
if (target.rootProject.group.toString().isEmpty()) {
target.rootProject.group = projectInfo.group
}
if (target.group.toString().isEmpty()) {
target.group = target.hierarchyGroup
}
if (target.version.toString().isEmpty()) {
target.version = projectInfo.versionString
}
if (target.description.isNullOrBlank()) {
target.description = projectInfo.description
}
target.afterEvaluate {
val baseExtension = extensions.findByType<BaseExtension>()
if (baseExtension?.namespace.isNullOrBlank()) {
baseExtension?.namespace = target.hierarchyGroup
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,25 @@ object ModelPropertyValueExt {
// Developers
val PropertyValue.developers: Result<List<Developer>>
get() = value.mapCatching(DeveloperMapper::parseDevelopers)

val PropertyValue.requireDevelopers: List<Developer>
get() = developers.getOrThrow()

/**
* This value will automatically create group based on folders names
*
* e.x :components:core:resource -> (com.example).components.core.resource
*/
val Project.hierarchyGroup: String
get() {
val currentParent = parent
val group = when {
project == rootProject -> requireProjectInfo.group
currentParent == null -> "${requireProjectInfo.group}.$name"
else -> "${currentParent.hierarchyGroup}.$name"
}
return group
.replace("-", ".")
.lowercase()
}
}
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ project-description = "GradlePlugin for my kotlin projects"
project-group = "ru.astrainteractive.gradleplugin"
project-web = "https://github.com/makeevrserg/gradle-plugin"
project-version-code = "4"
project-version-string = "1.2.0"
project-version-string = "1.3.0"
# Kotlin
kotlin-version = "2.0.0" # https://github.com/JetBrains/kotlin
kotlin-dokka = "1.9.20" # https://github.com/Kotlin/dokka
Expand Down

0 comments on commit 4357f3a

Please sign in to comment.