diff --git a/.github/workflows/call-publish-validation.yml b/.github/workflows/call-publish-validation.yml index 6d7f4f1..655ab2d 100644 --- a/.github/workflows/call-publish-validation.yml +++ b/.github/workflows/call-publish-validation.yml @@ -18,9 +18,8 @@ jobs: strategy: matrix: target: - - ":build-logic:plugins:convention:publishToMavenLocal" - - ":build-logic:plugins:android:publishToMavenLocal" - - ":build-logic:plugins:minecraft:publishToMavenLocal" + - ":build-logic:convention:publishToMavenLocal" + - ":build-logic:property:publishToMavenLocal" name: "Validate local publish" runs-on: ubuntu-latest env: diff --git a/.github/workflows/call-release.yml b/.github/workflows/call-release.yml index a845539..b6deb50 100644 --- a/.github/workflows/call-release.yml +++ b/.github/workflows/call-release.yml @@ -35,7 +35,7 @@ jobs: - name: Run publish uses: gradle/gradle-build-action@v3 with: - arguments: :build-logic:plugins:convention:publishAllPublicationsToMavenCentralRepository :build-logic:plugins:android:publishAllPublicationsToMavenCentralRepository :build-logic:plugins:minecraft:publishAllPublicationsToMavenCentralRepository --stacktrace + arguments: :build-logic:convention:publishAllPublicationsToMavenCentralRepository :build-logic:property:publishAllPublicationsToMavenCentralRepository --stacktrace release: needs: [ publish ] name: Create GitHub release diff --git a/.github/workflows/release-mkdocs.yml b/.github/workflows/release-mkdocs.yml new file mode 100644 index 0000000..4448d4b --- /dev/null +++ b/.github/workflows/release-mkdocs.yml @@ -0,0 +1,35 @@ +name: Build and deploy material mkdocs to gh-pages +on: + push: + branches: + - master + workflow_dispatch: +jobs: + check_gradle_files_change: + name: "Check docs files changed" + runs-on: ubuntu-latest + outputs: + DOCS_FILES_CHANGED: ${{ steps.docs_changed.outputs.any_changed }} + steps: + - uses: actions/checkout@6d193bf28034eafb982f37bd894289fe649468fc # v4 + with: + submodules: 'recursive' + - name: Check that docs changed + id: docs_changed + uses: tj-actions/changed-files@c3a1bb2c992d77180ae65be6ae6c166cf40f857c # v45.0.3 + with: + files: | + docs/** + mkdocs.yml + deploy: + needs: [ check_gradle_files_change ] + if: needs.check_gradle_files_change.outputs.GRADLE_FILES_CHANGED == 'true' + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-python@v5 + with: + python-version: 3.x + - run: pip install mkdocs-material + - run: pip install mkdocs-minify-plugin + - run: mkdocs gh-deploy --force diff --git a/README.md b/README.md index 7a4b114..f4a0670 100644 --- a/README.md +++ b/README.md @@ -1,61 +1,72 @@ -![version](https://img.shields.io/maven-central/v/ru.astrainteractive.gradleplugin/convention?style=flat-square) +# Gradle Plugin Suite -## 🌟 Gradle Plugin Suite - -A collection of useful, modular Gradle plugins — designed to keep your builds clean, focused, and flexible. - ---- - -📘 For wiki: please navigate to [GitHub Pages](https://makeevrserg.github.io/gradle-plugin/) +A modular collection of Gradle plugins for Kotlin projects. --- -## 🔍 What Is This Project? +## What Is This Project This **Gradle Plugin suite** is a modular build-logic plugins library for Kotlin projects. Instead of having one monolithic plugin, it's split into sub-plugins to provide focused functionality: -- ⚙️ `convention` - basic utilities for any gradle-related project -- 📱 `android` - plugins and tasks for Android projects -- ⛏️ `minecraft` - plugins and tasks related for Minecraft development - -This modular structure allows you to pick and use only the parts of the plugin you need, keeping your builds clean and -focused. +- `property` - property management system for `gradle.properties`, `local.properties`, and environment variables +- `convention` - core plugins for Java, Kotlin, Detekt, Dokka, publication, and more +- `android` - plugins for Android SDK, Compose, APK signing, namespacing +- `minecraft` - resource processor for Bukkit, Fabric, Forge, and Velocity --- -## 🚀 How to Use +## How to Use -### 1️⃣ Define the required plugins +### Define required plugins -In your `libs.version.toml` +In your `libs.versions.toml` ```toml [versions] -# klibs klibs-gradleplugin = "" [plugins] # Core klibs-gradle-detekt = { id = "ru.astrainteractive.gradleplugin.detekt", version.ref = "klibs-gradleplugin" } -klibs-gradle-detekt-compose = { id = "ru.astrainteractive.gradleplugin.detekt.compose", version.ref = "klibs-gradleplugin" } klibs-gradle-dokka-module = { id = "ru.astrainteractive.gradleplugin.dokka.module", version.ref = "klibs-gradleplugin" } klibs-gradle-dokka-root = { id = "ru.astrainteractive.gradleplugin.dokka.root", version.ref = "klibs-gradleplugin" } klibs-gradle-java-version = { id = "ru.astrainteractive.gradleplugin.java.version", version.ref = "klibs-gradleplugin" } klibs-gradle-java-utf8 = { id = "ru.astrainteractive.gradleplugin.java.utf8", version.ref = "klibs-gradleplugin" } -klibs-gradle-rootinfo = { id = "ru.astrainteractive.gradleplugin.root.info", version.ref = "klibs-gradleplugin" } +klibs-gradle-rootinfo = { id = "ru.astrainteractive.gradleplugin.rootinfo", version.ref = "klibs-gradleplugin" } klibs-gradle-publication = { id = "ru.astrainteractive.gradleplugin.publication", version.ref = "klibs-gradleplugin" } +# JavaScript +klibs-gradle-js-kobweb-resources = { id = "ru.astrainteractive.gradleplugin.js.kobweb.resources", version.ref = "klibs-gradleplugin" } +klibs-gradle-js-webpack-nosourcemaps = { id = "ru.astrainteractive.gradleplugin.js.webpack.nosourcemaps", version.ref = "klibs-gradleplugin" } +# Minecraft +klibs-gradle-minecraft-resource-processor = { id = "ru.astrainteractive.gradleplugin.minecraft.resource.processor", version.ref = "klibs-gradleplugin" } # Android +klibs-gradle-android-java = { id = "ru.astrainteractive.gradleplugin.android.java", version.ref = "klibs-gradleplugin" } klibs-gradle-android-sdk = { id = "ru.astrainteractive.gradleplugin.android.sdk", version.ref = "klibs-gradleplugin" } klibs-gradle-android-namespace = { id = "ru.astrainteractive.gradleplugin.android.namespace", version.ref = "klibs-gradleplugin" } klibs-gradle-android-compose = { id = "ru.astrainteractive.gradleplugin.android.compose", version.ref = "klibs-gradleplugin" } klibs-gradle-android-apk-sign = { id = "ru.astrainteractive.gradleplugin.android.apk.sign", version.ref = "klibs-gradleplugin" } klibs-gradle-android-apk-name = { id = "ru.astrainteractive.gradleplugin.android.apk.name", version.ref = "klibs-gradleplugin" } -# Minecrat -klibs-gradle-minecraft-resource-processor = { id = "ru.astrainteractive.gradleplugin.minecraft.resource-processor", version.ref = "klibs-gradleplugin" } ``` -### 2️⃣ Set up your Gradle plugins +### Configure your `gradle.properties` + +```properties +# Java +klibs.java.source=11 +klibs.java.target=11 +klibs.java.ktarget=11 + +# Project +klibs.project.name=MyProject +klibs.project.group=com.example.project +klibs.project.version.string=1.0.0 +klibs.project.description=My project description +klibs.project.url=https://github.com/username/project +klibs.project.developers=username|Full Name|email@example.com +``` + +### Setup your gradle plugins Your root `build.gradle.kts` @@ -63,21 +74,32 @@ Your root `build.gradle.kts` plugins { // klibs - core alias(libs.plugins.klibs.gradle.detekt) apply false - alias(libs.plugins.klibs.gradle.detekt.compose) apply false alias(libs.plugins.klibs.gradle.dokka.module) apply false alias(libs.plugins.klibs.gradle.dokka.root) apply false alias(libs.plugins.klibs.gradle.java.version) apply false alias(libs.plugins.klibs.gradle.java.utf8) apply false alias(libs.plugins.klibs.gradle.rootinfo) apply false alias(libs.plugins.klibs.gradle.publication) apply false + // klibs - javascript + alias(libs.plugins.klibs.gradle.js.kobweb.resources) apply false + alias(libs.plugins.klibs.gradle.js.webpack.nosourcemaps) apply false + // klibs - minecraft + alias(libs.plugins.klibs.gradle.minecraft.resource.processor) apply false // klibs - android + alias(libs.plugins.klibs.gradle.android.java) apply false alias(libs.plugins.klibs.gradle.android.sdk) apply false alias(libs.plugins.klibs.gradle.android.namespace) apply false alias(libs.plugins.klibs.gradle.android.compose) apply false alias(libs.plugins.klibs.gradle.android.apk.sign) apply false alias(libs.plugins.klibs.gradle.android.apk.name) apply false - // klibs - minecraft - alias(libs.plugins.klibs.gradle.minecraft.resource.processor) apply false } ``` +--- + +## Documentation + +- [Convention Module](convention.md) - Core plugins, properties reference, tasks, and custom property access +- [Android Plugins](android.md) - Android SDK, Compose, signing, namespace, and APK naming plugins +- [Minecraft Plugins](minecraft.md) - Resource processor for Bukkit, Fabric, Forge, and Velocity +- [Property Module](property.md) - Property management system (`PropertyValue`, lookup order, caching) diff --git a/build-logic/build.gradle.kts b/build-logic/build.gradle.kts index 1fcbb3d..c424bb1 100644 --- a/build-logic/build.gradle.kts +++ b/build-logic/build.gradle.kts @@ -3,7 +3,7 @@ import org.jetbrains.kotlin.gradle.dsl.KotlinBaseExtension plugins { `kotlin-dsl` alias(libs.plugins.vaniktech) apply false - id("ru.astrainteractive.gradleplugin.detekt") version "1.13.2" apply true + id("ru.astrainteractive.gradleplugin.detekt") version "1.15.0" apply true } private fun requireProperty(key: String): String { @@ -12,6 +12,12 @@ private fun requireProperty(key: String): String { ?: throw GradleException("Could not find property $key") } +private fun canSignPublication(): Boolean { + val hasEnvMavenUsername = System.getenv("ORG_GRADLE_PROJECT_mavenCentralUsername") != null + val hasGradlePropertyUsername = providers.gradleProperty("mavenCentralUsername").isPresent + return hasEnvMavenUsername || hasGradlePropertyUsername +} + data class ProjectConfiguration( val projectName: String = requireProperty("project.name"), val projectDescription: String = requireProperty("project.description"), @@ -32,12 +38,6 @@ allprojects { subprojects { val project = this - val whitelist = listOf( - "android", - "convention", - "minecraft", - ) - if (!whitelist.contains(project.name)) return@subprojects project.apply(plugin = "java-gradle-plugin") project.apply(plugin = "com.vanniktech.maven.publish") @@ -88,6 +88,8 @@ subprojects { url.set(projectConfiguration.projectWeb) } } - signAllPublications() + if (canSignPublication()) { + signAllPublications() + } } } diff --git a/build-logic/convention/build.gradle.kts b/build-logic/convention/build.gradle.kts new file mode 100755 index 0000000..cf7724f --- /dev/null +++ b/build-logic/convention/build.gradle.kts @@ -0,0 +1,143 @@ +plugins { + `kotlin-dsl` + id("java-gradle-plugin") + id("com.vanniktech.maven.publish") +} + +dependencies { + compileOnly(files(libs.javaClass.superclass.protectionDomain.codeSource.location)) + compileOnly(libs.android.gradle) + compileOnly(libs.kotlin.gradle) + + implementation(libs.detekt.gradle) + implementation(libs.dokka.base) + implementation(libs.dokka.core) + implementation(libs.dokka.gradle) + implementation(libs.kobweb.gradle) + implementation(libs.vaniktech) + implementation(projects.buildLogic.property) + implementation(projects.property) +} + +gradlePlugin { + website.set(projectWeb) + vcsUrl.set(projectWeb) + description = projectDescription + plugins { + create("detekt") { + id = "$projectGroup.$name" + implementationClass = "$projectGroup.plugin.detekt.DetektPlugin" + displayName = "Detekt Code Analysis Plugin" + description = + "Automatically applies detekt with KLibs configuration for static code analysis with Kotlin linting rules" + tags.set(listOf("kotlin", "static-analysis", "klibs")) + } + create("dokka.module") { + id = "$projectGroup.$name" + implementationClass = "$projectGroup.plugin.dokka.DokkaModulePlugin" + displayName = "Dokka Module Documentation Plugin" + description = + "Configures Dokka for individual modules with JDK version detection and documentation settings" + tags.set(listOf("documentation", "kotlin", "klibs")) + } + create("dokka.root") { + id = "$projectGroup.$name" + implementationClass = "$projectGroup.plugin.dokka.DokkaRootPlugin" + displayName = "Dokka Root Documentation Plugin" + description = "Configures Dokka multi-module documentation generation for root projects" + tags.set(listOf("documentation", "kotlin", "klibs")) + } + create("java.version") { + id = "$projectGroup.$name" + implementationClass = "$projectGroup.plugin.JavaVersionPlugin" + displayName = "Java Version Configuration Plugin" + description = "Sets Java source/target compatibility and Kotlin JVM target versions from project properties" + tags.set(listOf("java", "kotlin", "klibs")) + } + create("java.utf8") { + id = "$projectGroup.$name" + implementationClass = "$projectGroup.plugin.JavaUtf8Plugin" + displayName = "Java UTF-8 Encoding Plugin" + description = "Configures UTF-8 encoding for Java compilation tasks" + tags.set(listOf("java", "encoding", "klibs")) + } + create("rootinfo") { + id = "$projectGroup.$name" + implementationClass = "$projectGroup.plugin.ModuleInfoPlugin" + displayName = "Module Info Plugin" + description = "Applies project group, version, and description from gradle.properties to root project" + tags.set(listOf("configuration", "klibs")) + } + create("publication") { + id = "$projectGroup.$name" + implementationClass = "$projectGroup.plugin.PublicationPlugin" + displayName = "Maven Publication Plugin" + description = "Configures Maven Central publication with POM metadata from project properties" + tags.set(listOf("publication", "maven", "klibs")) + } + create("js.kobweb.resources") { + id = "$projectGroup.$name" + implementationClass = "$projectGroup.plugin.KobwebResourcesPlugin" + displayName = "Kobweb JavaScript Resources Plugin" + description = "Manages JavaScript resources copying for Kobweb applications" + tags.set(listOf("javascript", "kobweb", "klibs")) + } + create("js.webpack.nosourcemaps") { + id = "$projectGroup.$name" + implementationClass = "$projectGroup.plugin.WebpackNoSourceMapsPlugin" + displayName = "Webpack No Source Maps Plugin" + description = "Disables source maps in Kotlin/JS Webpack builds for production optimization" + tags.set(listOf("javascript", "webpack", "klibs")) + } + create("minecraft.resource.processor") { + id = "$projectGroup.$name" + implementationClass = "$projectGroup.plugin.ResourceProcessorPlugin" + displayName = "Minecraft Resource Processor Plugin" + description = "Provides resource processor scope for Minecraft mod development" + tags.set(listOf("minecraft", "resources", "klibs")) + } + create("android.java") { + id = "$projectGroup.$name" + implementationClass = "$projectGroup.plugin.AndroidJavaPlugin" + displayName = "Android Java Configuration Plugin" + description = + "Configures Java/Kotlin JVM target versions for Android and Kotlin Multiplatform Android targets" + tags.set(listOf("android", "java", "kotlin", "klibs")) + } + create("android.sdk") { + id = "$projectGroup.$name" + implementationClass = "$projectGroup.plugin.AndroidSdkPlugin" + displayName = "Android SDK Configuration Plugin" + description = "Sets compileSdk, minSdk, and targetSdk versions for Android projects from gradle.properties" + tags.set(listOf("android", "sdk", "klibs")) + } + create("android.namespace") { + id = "$projectGroup.$name" + implementationClass = "$projectGroup.plugin.AndroidNamespacePlugin" + displayName = "Android Namespace Plugin" + description = "Automatically generates Android namespace based on module path hierarchy" + tags.set(listOf("android", "configuration", "klibs")) + } + create("android.compose") { + id = "$projectGroup.$name" + implementationClass = "$projectGroup.plugin.AndroidComposePlugin" + displayName = "Android Compose Plugin" + description = "Enables and configures Jetpack Compose for Android projects" + tags.set(listOf("android", "compose", "klibs")) + } + create("android.apk.sign") { + id = "$projectGroup.$name" + implementationClass = "$projectGroup.plugin.ApkSigningPlugin" + displayName = "Android APK Signing Plugin" + description = "Configures APK signing for debug and release builds using keystore from gradle properties" + tags.set(listOf("android", "signing", "klibs")) + } + create("android.apk.name") { + id = "$projectGroup.$name" + implementationClass = "$projectGroup.plugin.ApkNamePlugin" + displayName = "Android APK Naming Plugin" + description = "Automatically names APK files with project name, version, and build variant" + tags.set(listOf("android", "apk", "klibs")) + } + } +} diff --git a/build-logic/plugins/android/src/main/kotlin/ru/astrainteractive/gradleplugin/plugin/AndroidComposePlugin.kt b/build-logic/convention/src/main/kotlin/ru/astrainteractive/gradleplugin/plugin/AndroidComposePlugin.kt similarity index 66% rename from build-logic/plugins/android/src/main/kotlin/ru/astrainteractive/gradleplugin/plugin/AndroidComposePlugin.kt rename to build-logic/convention/src/main/kotlin/ru/astrainteractive/gradleplugin/plugin/AndroidComposePlugin.kt index 7790502..3e9ad54 100644 --- a/build-logic/plugins/android/src/main/kotlin/ru/astrainteractive/gradleplugin/plugin/AndroidComposePlugin.kt +++ b/build-logic/convention/src/main/kotlin/ru/astrainteractive/gradleplugin/plugin/AndroidComposePlugin.kt @@ -1,22 +1,22 @@ -package ru.astrainteractive.gradleplugin.plugin - -import com.android.build.api.dsl.CommonExtension -import org.gradle.api.Plugin -import org.gradle.api.Project -import org.gradle.kotlin.dsl.configure -import ru.astrainteractive.gradleplugin.property.baseGradleProperty -import ru.astrainteractive.gradleplugin.property.extension.PrimitivePropertyValueExt.stringOrNull - -class AndroidComposePlugin : Plugin { - - override fun apply(target: Project) { - val compilerVersion = target - .baseGradleProperty(path = "android.kotlinCompilerExtensionVersion") - .stringOrNull - - target.extensions.configure { - buildFeatures.compose = true - composeOptions.kotlinCompilerExtensionVersion = compilerVersion - } - } -} +package ru.astrainteractive.gradleplugin.plugin + +import com.android.build.api.dsl.CommonExtension +import org.gradle.api.Plugin +import org.gradle.api.Project +import org.gradle.kotlin.dsl.configure +import ru.astrainteractive.gradle.property.api.klibsGradleProperty +import ru.astrainteractive.gradleplugin.property.util.stringOrNull + +class AndroidComposePlugin : Plugin { + + override fun apply(target: Project) { + val compilerVersion = target + .klibsGradleProperty(path = "android.kotlinCompilerExtensionVersion") + .stringOrNull + + target.extensions.configure { + buildFeatures.compose = true + composeOptions.kotlinCompilerExtensionVersion = compilerVersion + } + } +} diff --git a/build-logic/plugins/android/src/main/kotlin/ru/astrainteractive/gradleplugin/plugin/AndroidJavaPlugin.kt b/build-logic/convention/src/main/kotlin/ru/astrainteractive/gradleplugin/plugin/AndroidJavaPlugin.kt similarity index 94% rename from build-logic/plugins/android/src/main/kotlin/ru/astrainteractive/gradleplugin/plugin/AndroidJavaPlugin.kt rename to build-logic/convention/src/main/kotlin/ru/astrainteractive/gradleplugin/plugin/AndroidJavaPlugin.kt index 8515b79..21f38b4 100644 --- a/build-logic/plugins/android/src/main/kotlin/ru/astrainteractive/gradleplugin/plugin/AndroidJavaPlugin.kt +++ b/build-logic/convention/src/main/kotlin/ru/astrainteractive/gradleplugin/plugin/AndroidJavaPlugin.kt @@ -8,7 +8,7 @@ import org.jetbrains.kotlin.gradle.dsl.HasConfigurableKotlinCompilerOptions import org.jetbrains.kotlin.gradle.dsl.JvmTarget import org.jetbrains.kotlin.gradle.dsl.KotlinJvmCompilerOptions import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension -import ru.astrainteractive.gradleplugin.property.extension.ModelPropertyValueExt.requireJinfo +import ru.astrainteractive.gradleplugin.property.util.requireJinfo import ru.astrainteractive.gradleplugin.util.hasAndroidPlugin class AndroidJavaPlugin : Plugin { diff --git a/build-logic/plugins/android/src/main/kotlin/ru/astrainteractive/gradleplugin/plugin/AndroidNamespacePlugin.kt b/build-logic/convention/src/main/kotlin/ru/astrainteractive/gradleplugin/plugin/AndroidNamespacePlugin.kt similarity index 90% rename from build-logic/plugins/android/src/main/kotlin/ru/astrainteractive/gradleplugin/plugin/AndroidNamespacePlugin.kt rename to build-logic/convention/src/main/kotlin/ru/astrainteractive/gradleplugin/plugin/AndroidNamespacePlugin.kt index e5404e9..d8460dd 100644 --- a/build-logic/plugins/android/src/main/kotlin/ru/astrainteractive/gradleplugin/plugin/AndroidNamespacePlugin.kt +++ b/build-logic/convention/src/main/kotlin/ru/astrainteractive/gradleplugin/plugin/AndroidNamespacePlugin.kt @@ -1,35 +1,35 @@ -package ru.astrainteractive.gradleplugin.plugin - -import com.android.build.api.dsl.CommonExtension -import com.android.build.api.dsl.KotlinMultiplatformAndroidLibraryTarget -import org.gradle.api.Plugin -import org.gradle.api.Project -import org.gradle.kotlin.dsl.configure -import org.gradle.kotlin.dsl.withType -import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension -import ru.astrainteractive.gradleplugin.property.extension.ModelPropertyValueExt.hierarchyGroup -import ru.astrainteractive.gradleplugin.util.hasAndroidPlugin - -class AndroidNamespacePlugin : Plugin { - private fun configureAndroidKmpPlugin(target: Project) { - target.pluginManager.withPlugin("org.jetbrains.kotlin.multiplatform") { - target.configure { - targets.withType { - namespace = target.hierarchyGroup - } - } - } - } - - private fun configureAndroidPlugin(target: Project) { - if (!target.hasAndroidPlugin) return - target.extensions.configure { - this.namespace = target.hierarchyGroup - } - } - - override fun apply(target: Project) { - configureAndroidPlugin(target) - configureAndroidKmpPlugin(target) - } -} +package ru.astrainteractive.gradleplugin.plugin + +import com.android.build.api.dsl.CommonExtension +import com.android.build.api.dsl.KotlinMultiplatformAndroidLibraryTarget +import org.gradle.api.Plugin +import org.gradle.api.Project +import org.gradle.kotlin.dsl.configure +import org.gradle.kotlin.dsl.withType +import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension +import ru.astrainteractive.gradleplugin.util.hasAndroidPlugin +import ru.astrainteractive.gradleplugin.util.hierarchyGroup + +class AndroidNamespacePlugin : Plugin { + private fun configureAndroidKmpPlugin(target: Project) { + target.pluginManager.withPlugin("org.jetbrains.kotlin.multiplatform") { + target.configure { + targets.withType { + namespace = target.hierarchyGroup + } + } + } + } + + private fun configureAndroidPlugin(target: Project) { + if (!target.hasAndroidPlugin) return + target.extensions.configure { + this.namespace = target.hierarchyGroup + } + } + + override fun apply(target: Project) { + configureAndroidPlugin(target) + configureAndroidKmpPlugin(target) + } +} diff --git a/build-logic/plugins/android/src/main/kotlin/ru/astrainteractive/gradleplugin/plugin/AndroidSdkPlugin.kt b/build-logic/convention/src/main/kotlin/ru/astrainteractive/gradleplugin/plugin/AndroidSdkPlugin.kt similarity index 93% rename from build-logic/plugins/android/src/main/kotlin/ru/astrainteractive/gradleplugin/plugin/AndroidSdkPlugin.kt rename to build-logic/convention/src/main/kotlin/ru/astrainteractive/gradleplugin/plugin/AndroidSdkPlugin.kt index 114dabf..783b97b 100644 --- a/build-logic/plugins/android/src/main/kotlin/ru/astrainteractive/gradleplugin/plugin/AndroidSdkPlugin.kt +++ b/build-logic/convention/src/main/kotlin/ru/astrainteractive/gradleplugin/plugin/AndroidSdkPlugin.kt @@ -1,64 +1,64 @@ -package ru.astrainteractive.gradleplugin.plugin - -import com.android.build.api.dsl.ApplicationExtension -import com.android.build.api.dsl.KotlinMultiplatformAndroidLibraryTarget -import com.android.build.api.dsl.LibraryExtension -import org.gradle.api.Plugin -import org.gradle.api.Project -import org.gradle.kotlin.dsl.configure -import org.gradle.kotlin.dsl.withType -import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension -import ru.astrainteractive.gradleplugin.property.extension.AndroidModelPropertyValueExt.requireAndroidSdkInfo -import ru.astrainteractive.gradleplugin.util.hasAndroidAppPlugin -import ru.astrainteractive.gradleplugin.util.hasAndroidKmpPlugin -import ru.astrainteractive.gradleplugin.util.hasAndroidLibPlugin - -class AndroidSdkPlugin : Plugin { - - private fun configureAndroidKmpPlugin(target: Project) { - if (!target.hasAndroidKmpPlugin) return - val androidSdkInfo = target.requireAndroidSdkInfo - target.pluginManager.withPlugin("org.jetbrains.kotlin.multiplatform") { - target.configure { - targets.withType { - compileSdk = androidSdkInfo.compile - minSdk = androidSdkInfo.min - // todo current version of Jetbrains Compose Resources - // todo doesn't handle new android resourceless plugin - androidResources.enable = true - } - } - } - } - - private fun configureAndroidLibraryExtension(target: Project) { - if (!target.hasAndroidLibPlugin) return - val androidSdkInfo = target.requireAndroidSdkInfo - target.extensions.configure { - compileSdk = androidSdkInfo.compile - - defaultConfig { - minSdk = androidSdkInfo.min - } - } - } - - private fun configureAndroidApplicationExtension(target: Project) { - if (!target.hasAndroidAppPlugin) return - val androidSdkInfo = target.requireAndroidSdkInfo - target.extensions.configure { - compileSdk = androidSdkInfo.compile - - defaultConfig { - minSdk = androidSdkInfo.min - targetSdk = androidSdkInfo.target - } - } - } - - override fun apply(target: Project) { - configureAndroidLibraryExtension(target) - configureAndroidApplicationExtension(target) - configureAndroidKmpPlugin(target) - } -} +package ru.astrainteractive.gradleplugin.plugin + +import com.android.build.api.dsl.ApplicationExtension +import com.android.build.api.dsl.KotlinMultiplatformAndroidLibraryTarget +import com.android.build.api.dsl.LibraryExtension +import org.gradle.api.Plugin +import org.gradle.api.Project +import org.gradle.kotlin.dsl.configure +import org.gradle.kotlin.dsl.withType +import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension +import ru.astrainteractive.gradleplugin.property.util.requireAndroidSdkInfo +import ru.astrainteractive.gradleplugin.util.hasAndroidAppPlugin +import ru.astrainteractive.gradleplugin.util.hasAndroidKmpPlugin +import ru.astrainteractive.gradleplugin.util.hasAndroidLibPlugin + +class AndroidSdkPlugin : Plugin { + + private fun configureAndroidKmpPlugin(target: Project) { + if (!target.hasAndroidKmpPlugin) return + val androidSdkInfo = target.requireAndroidSdkInfo + target.pluginManager.withPlugin("org.jetbrains.kotlin.multiplatform") { + target.configure { + targets.withType { + compileSdk = androidSdkInfo.compile + minSdk = androidSdkInfo.min + // todo current version of Jetbrains Compose Resources + // todo doesn't handle new android resourceless plugin + androidResources.enable = true + } + } + } + } + + private fun configureAndroidLibraryExtension(target: Project) { + if (!target.hasAndroidLibPlugin) return + val androidSdkInfo = target.requireAndroidSdkInfo + target.extensions.configure { + compileSdk = androidSdkInfo.compile + + defaultConfig { + minSdk = androidSdkInfo.min + } + } + } + + private fun configureAndroidApplicationExtension(target: Project) { + if (!target.hasAndroidAppPlugin) return + val androidSdkInfo = target.requireAndroidSdkInfo + target.extensions.configure { + compileSdk = androidSdkInfo.compile + + defaultConfig { + minSdk = androidSdkInfo.min + targetSdk = androidSdkInfo.target + } + } + } + + override fun apply(target: Project) { + configureAndroidLibraryExtension(target) + configureAndroidApplicationExtension(target) + configureAndroidKmpPlugin(target) + } +} diff --git a/build-logic/plugins/android/src/main/kotlin/ru/astrainteractive/gradleplugin/plugin/ApkNamePlugin.kt b/build-logic/convention/src/main/kotlin/ru/astrainteractive/gradleplugin/plugin/ApkNamePlugin.kt similarity index 87% rename from build-logic/plugins/android/src/main/kotlin/ru/astrainteractive/gradleplugin/plugin/ApkNamePlugin.kt rename to build-logic/convention/src/main/kotlin/ru/astrainteractive/gradleplugin/plugin/ApkNamePlugin.kt index 77789b2..b98aaec 100644 --- a/build-logic/plugins/android/src/main/kotlin/ru/astrainteractive/gradleplugin/plugin/ApkNamePlugin.kt +++ b/build-logic/convention/src/main/kotlin/ru/astrainteractive/gradleplugin/plugin/ApkNamePlugin.kt @@ -1,25 +1,25 @@ -package ru.astrainteractive.gradleplugin.plugin - -import com.android.build.api.variant.ApplicationAndroidComponentsExtension -import com.android.build.api.variant.impl.VariantOutputImpl -import org.gradle.api.Plugin -import org.gradle.api.Project -import org.gradle.kotlin.dsl.configure -import ru.astrainteractive.gradleplugin.property.extension.ModelPropertyValueExt.requireProjectInfo - -class ApkNamePlugin : Plugin { - override fun apply(target: Project) { - val projectInfo = target.requireProjectInfo - target.configure { - onVariants { variant -> - variant.outputs.onEach { output -> - if (output is VariantOutputImpl) { - val name = projectInfo.name - val version = projectInfo.versionString - output.outputFileName.set("${name}_${version}_${variant.name}.apk") - } - } - } - } - } -} +package ru.astrainteractive.gradleplugin.plugin + +import com.android.build.api.variant.ApplicationAndroidComponentsExtension +import com.android.build.api.variant.impl.VariantOutputImpl +import org.gradle.api.Plugin +import org.gradle.api.Project +import org.gradle.kotlin.dsl.configure +import ru.astrainteractive.gradleplugin.property.util.requireProjectInfo + +class ApkNamePlugin : Plugin { + override fun apply(target: Project) { + val projectInfo = target.requireProjectInfo + target.configure { + onVariants { variant -> + variant.outputs.onEach { output -> + if (output is VariantOutputImpl) { + val name = projectInfo.name + val version = projectInfo.versionString + output.outputFileName.set("${name}_${version}_${variant.name}.apk") + } + } + } + } + } +} diff --git a/build-logic/plugins/android/src/main/kotlin/ru/astrainteractive/gradleplugin/plugin/ApkSigningPlugin.kt b/build-logic/convention/src/main/kotlin/ru/astrainteractive/gradleplugin/plugin/ApkSigningPlugin.kt similarity index 87% rename from build-logic/plugins/android/src/main/kotlin/ru/astrainteractive/gradleplugin/plugin/ApkSigningPlugin.kt rename to build-logic/convention/src/main/kotlin/ru/astrainteractive/gradleplugin/plugin/ApkSigningPlugin.kt index 3d5eed8..e0d099c 100644 --- a/build-logic/plugins/android/src/main/kotlin/ru/astrainteractive/gradleplugin/plugin/ApkSigningPlugin.kt +++ b/build-logic/convention/src/main/kotlin/ru/astrainteractive/gradleplugin/plugin/ApkSigningPlugin.kt @@ -1,85 +1,85 @@ -package ru.astrainteractive.gradleplugin.plugin - -import com.android.build.api.dsl.ApplicationVariantDimension -import com.android.build.api.dsl.CommonExtension -import com.android.build.api.dsl.LibraryVariantDimension -import org.gradle.api.Plugin -import org.gradle.api.Project -import org.gradle.kotlin.dsl.configure -import ru.astrainteractive.gradleplugin.property.baseSecretProperty -import ru.astrainteractive.gradleplugin.property.extension.PrimitivePropertyValueExt.stringOrEmpty - -class ApkSigningPlugin : Plugin { - private val Project.keyPassword: String - get() = baseSecretProperty(KEY_PASSWORD_PATH).stringOrEmpty - private val Project.keyAlias: String - get() = baseSecretProperty(KEY_ALIAS_PATH).stringOrEmpty - private val Project.storePassword: String - get() = baseSecretProperty(STORE_PASSWORD_PATH).stringOrEmpty - - override fun apply(target: Project) { - target.extensions.configure { - val secretKeyAlias = target.keyAlias - val secretKeyPassword = target.keyPassword - val secretStorePassword = target.storePassword - - val signingFile = target.file(SIGNING_FILE_NAME) - - if (!signingFile.exists()) { - target.logger.error("Signing file named $SIGNING_FILE_NAME not found in ${target.path}") - return@configure - } - if (secretKeyAlias.isEmpty()) { - target.logger.error("Secret key named $KEY_ALIAS_PATH in local.properties is empty") - return@configure - } - - if (secretKeyPassword.isEmpty()) { - target.logger.error("Secret key named $KEY_PASSWORD_PATH in local.properties is empty") - return@configure - } - - if (secretStorePassword.isEmpty()) { - target.logger.error("Secret key named $STORE_PASSWORD_PATH in local.properties is empty") - return@configure - } - - signingConfigs.getByName("debug") { - keyAlias = secretKeyAlias - keyPassword = secretKeyPassword - storePassword = secretStorePassword - storeFile = signingFile - } - signingConfigs.create("release") { - keyAlias = secretKeyAlias - keyPassword = secretKeyPassword - storePassword = secretStorePassword - storeFile = signingFile - } - - buildTypes.named("release") { - if (this is LibraryVariantDimension) { - signingConfig = signingConfigs.getByName("release") - } - if (this is ApplicationVariantDimension) { - signingConfig = signingConfigs.getByName("release") - } - } - buildTypes.named("debug") { - if (this is LibraryVariantDimension) { - signingConfig = signingConfigs.getByName("debug") - } - if (this is ApplicationVariantDimension) { - signingConfig = signingConfigs.getByName("debug") - } - } - } - } - - companion object { - private const val SIGNING_FILE_NAME = "keystore.jks" - private const val KEY_PASSWORD_PATH = "KEY_PASSWORD" - private const val KEY_ALIAS_PATH = "KEY_ALIAS" - private const val STORE_PASSWORD_PATH = "STORE_PASSWORD" - } -} +package ru.astrainteractive.gradleplugin.plugin + +import com.android.build.api.dsl.ApplicationVariantDimension +import com.android.build.api.dsl.CommonExtension +import com.android.build.api.dsl.LibraryVariantDimension +import org.gradle.api.Plugin +import org.gradle.api.Project +import org.gradle.kotlin.dsl.configure +import ru.astrainteractive.gradle.property.api.klibsSecretProperty +import ru.astrainteractive.gradleplugin.property.util.stringOrEmpty + +class ApkSigningPlugin : Plugin { + private val Project.keyPassword: String + get() = klibsSecretProperty(KEY_PASSWORD_PATH).stringOrEmpty + private val Project.keyAlias: String + get() = klibsSecretProperty(KEY_ALIAS_PATH).stringOrEmpty + private val Project.storePassword: String + get() = klibsSecretProperty(STORE_PASSWORD_PATH).stringOrEmpty + + override fun apply(target: Project) { + target.extensions.configure { + val secretKeyAlias = target.keyAlias + val secretKeyPassword = target.keyPassword + val secretStorePassword = target.storePassword + + val signingFile = target.file(SIGNING_FILE_NAME) + + if (!signingFile.exists()) { + target.logger.error("Signing file named $SIGNING_FILE_NAME not found in ${target.path}") + return@configure + } + if (secretKeyAlias.isEmpty()) { + target.logger.error("Secret key named $KEY_ALIAS_PATH in local.properties is empty") + return@configure + } + + if (secretKeyPassword.isEmpty()) { + target.logger.error("Secret key named $KEY_PASSWORD_PATH in local.properties is empty") + return@configure + } + + if (secretStorePassword.isEmpty()) { + target.logger.error("Secret key named $STORE_PASSWORD_PATH in local.properties is empty") + return@configure + } + + signingConfigs.getByName("debug") { + keyAlias = secretKeyAlias + keyPassword = secretKeyPassword + storePassword = secretStorePassword + storeFile = signingFile + } + signingConfigs.create("release") { + keyAlias = secretKeyAlias + keyPassword = secretKeyPassword + storePassword = secretStorePassword + storeFile = signingFile + } + + buildTypes.named("release") { + if (this is LibraryVariantDimension) { + signingConfig = signingConfigs.getByName("release") + } + if (this is ApplicationVariantDimension) { + signingConfig = signingConfigs.getByName("release") + } + } + buildTypes.named("debug") { + if (this is LibraryVariantDimension) { + signingConfig = signingConfigs.getByName("debug") + } + if (this is ApplicationVariantDimension) { + signingConfig = signingConfigs.getByName("debug") + } + } + } + } + + companion object { + private const val SIGNING_FILE_NAME = "keystore.jks" + private const val KEY_PASSWORD_PATH = "KEY_PASSWORD" + private const val KEY_ALIAS_PATH = "KEY_ALIAS" + private const val STORE_PASSWORD_PATH = "STORE_PASSWORD" + } +} diff --git a/build-logic/plugins/convention/src/main/kotlin/ru/astrainteractive/gradleplugin/plugin/JavaUtf8Plugin.kt b/build-logic/convention/src/main/kotlin/ru/astrainteractive/gradleplugin/plugin/JavaUtf8Plugin.kt similarity index 100% rename from build-logic/plugins/convention/src/main/kotlin/ru/astrainteractive/gradleplugin/plugin/JavaUtf8Plugin.kt rename to build-logic/convention/src/main/kotlin/ru/astrainteractive/gradleplugin/plugin/JavaUtf8Plugin.kt diff --git a/build-logic/plugins/convention/src/main/kotlin/ru/astrainteractive/gradleplugin/plugin/JavaVersionPlugin.kt b/build-logic/convention/src/main/kotlin/ru/astrainteractive/gradleplugin/plugin/JavaVersionPlugin.kt similarity index 89% rename from build-logic/plugins/convention/src/main/kotlin/ru/astrainteractive/gradleplugin/plugin/JavaVersionPlugin.kt rename to build-logic/convention/src/main/kotlin/ru/astrainteractive/gradleplugin/plugin/JavaVersionPlugin.kt index 8d21900..e9a25e3 100644 --- a/build-logic/plugins/convention/src/main/kotlin/ru/astrainteractive/gradleplugin/plugin/JavaVersionPlugin.kt +++ b/build-logic/convention/src/main/kotlin/ru/astrainteractive/gradleplugin/plugin/JavaVersionPlugin.kt @@ -6,7 +6,7 @@ import org.gradle.api.plugins.JavaPluginExtension import org.gradle.kotlin.dsl.configure import org.gradle.kotlin.dsl.withType import org.jetbrains.kotlin.gradle.tasks.KotlinCompile -import ru.astrainteractive.gradleplugin.property.extension.ModelPropertyValueExt.requireJinfo +import ru.astrainteractive.gradleplugin.property.util.requireJinfo /** * Set javaSource, javaTarget and kotlinJvmTarget versions diff --git a/build-logic/convention/src/main/kotlin/ru/astrainteractive/gradleplugin/plugin/KobwebResourcesPlugin.kt b/build-logic/convention/src/main/kotlin/ru/astrainteractive/gradleplugin/plugin/KobwebResourcesPlugin.kt new file mode 100644 index 0000000..e86976f --- /dev/null +++ b/build-logic/convention/src/main/kotlin/ru/astrainteractive/gradleplugin/plugin/KobwebResourcesPlugin.kt @@ -0,0 +1,57 @@ +package ru.astrainteractive.gradleplugin.plugin + +import com.varabyte.kobweb.gradle.application.tasks.KobwebCacheAppFrontendDataTask +import com.varabyte.kobweb.gradle.application.tasks.KobwebCopySupplementalResourcesTask +import com.varabyte.kobweb.gradle.application.tasks.KobwebCopyWorkerJsOutputTask +import com.varabyte.kobweb.gradle.application.tasks.KobwebGenerateSiteEntryTask +import com.varabyte.kobweb.gradle.application.tasks.KobwebGenerateSiteIndexTask +import com.varabyte.kobweb.gradle.application.tasks.KobwebStartTask +import com.varabyte.kobweb.gradle.application.tasks.KobwebUnpackServerJarTask +import org.gradle.api.Plugin +import org.gradle.api.Project +import org.gradle.api.tasks.Copy +import org.gradle.api.tasks.Sync +import org.gradle.kotlin.dsl.create +import org.gradle.kotlin.dsl.register + +abstract class KobwebResourcesPlugin : Plugin { + + override fun apply(target: Project) { + val scope = target.extensions.create( + name = "jsResources", + type = JsResourcesScope::class, + ) + + val copySharedResources = target.tasks.register("copyJsResources") { + from( + scope.projectsPaths + .map { projectPath -> + project.project(projectPath) + .file("src/jsMain/resources/public") + } + ) + into(project.layout.buildDirectory.dir("processedResources/js/main/public")) + } + + target.tasks + .matching { task -> + when (task) { + is KobwebStartTask, + is KobwebUnpackServerJarTask, + is Sync, + is KobwebGenerateSiteEntryTask, + is KobwebCacheAppFrontendDataTask, + is KobwebGenerateSiteIndexTask, + is KobwebCopyWorkerJsOutputTask, + is KobwebCopySupplementalResourcesTask -> true + + else -> false + } + } + .configureEach { dependsOn(copySharedResources) } + } + + open class JsResourcesScope { + var projectsPaths: List = emptyList() + } +} diff --git a/build-logic/plugins/convention/src/main/kotlin/ru/astrainteractive/gradleplugin/plugin/ModuleInfoPlugin.kt b/build-logic/convention/src/main/kotlin/ru/astrainteractive/gradleplugin/plugin/ModuleInfoPlugin.kt similarity index 86% rename from build-logic/plugins/convention/src/main/kotlin/ru/astrainteractive/gradleplugin/plugin/ModuleInfoPlugin.kt rename to build-logic/convention/src/main/kotlin/ru/astrainteractive/gradleplugin/plugin/ModuleInfoPlugin.kt index d530c71..c7d09ff 100644 --- a/build-logic/plugins/convention/src/main/kotlin/ru/astrainteractive/gradleplugin/plugin/ModuleInfoPlugin.kt +++ b/build-logic/convention/src/main/kotlin/ru/astrainteractive/gradleplugin/plugin/ModuleInfoPlugin.kt @@ -2,7 +2,7 @@ package ru.astrainteractive.gradleplugin.plugin import org.gradle.api.Plugin import org.gradle.api.Project -import ru.astrainteractive.gradleplugin.property.extension.ModelPropertyValueExt.requireProjectInfo +import ru.astrainteractive.gradleplugin.property.util.requireProjectInfo /** * Sets group, version and description of module from gradle.properties diff --git a/build-logic/plugins/convention/src/main/kotlin/ru/astrainteractive/gradleplugin/plugin/PublicationPlugin.kt b/build-logic/convention/src/main/kotlin/ru/astrainteractive/gradleplugin/plugin/PublicationPlugin.kt similarity index 91% rename from build-logic/plugins/convention/src/main/kotlin/ru/astrainteractive/gradleplugin/plugin/PublicationPlugin.kt rename to build-logic/convention/src/main/kotlin/ru/astrainteractive/gradleplugin/plugin/PublicationPlugin.kt index ad3ea36..489b37e 100644 --- a/build-logic/plugins/convention/src/main/kotlin/ru/astrainteractive/gradleplugin/plugin/PublicationPlugin.kt +++ b/build-logic/convention/src/main/kotlin/ru/astrainteractive/gradleplugin/plugin/PublicationPlugin.kt @@ -3,8 +3,8 @@ package ru.astrainteractive.gradleplugin.plugin import org.gradle.api.Plugin import org.gradle.api.Project import org.gradle.kotlin.dsl.configure -import ru.astrainteractive.gradleplugin.property.extension.ModelPropertyValueExt.requireProjectInfo -import ru.astrainteractive.gradleplugin.property.extension.ModelPropertyValueExt.requirePublishInfo +import ru.astrainteractive.gradleplugin.property.util.requireProjectInfo +import ru.astrainteractive.gradleplugin.property.util.requirePublishInfo class PublicationPlugin : Plugin { diff --git a/build-logic/plugins/minecraft/src/main/kotlin/ru/astrainteractive/gradleplugin/processor/plugin/ResourceProcessorPlugin.kt b/build-logic/convention/src/main/kotlin/ru/astrainteractive/gradleplugin/plugin/ResourceProcessorPlugin.kt similarity index 64% rename from build-logic/plugins/minecraft/src/main/kotlin/ru/astrainteractive/gradleplugin/processor/plugin/ResourceProcessorPlugin.kt rename to build-logic/convention/src/main/kotlin/ru/astrainteractive/gradleplugin/plugin/ResourceProcessorPlugin.kt index 984a6fc..74a3b90 100644 --- a/build-logic/plugins/minecraft/src/main/kotlin/ru/astrainteractive/gradleplugin/processor/plugin/ResourceProcessorPlugin.kt +++ b/build-logic/convention/src/main/kotlin/ru/astrainteractive/gradleplugin/plugin/ResourceProcessorPlugin.kt @@ -1,9 +1,10 @@ -package ru.astrainteractive.gradleplugin.processor.plugin +package ru.astrainteractive.gradleplugin.plugin import org.gradle.api.Plugin import org.gradle.api.Project import org.gradle.kotlin.dsl.create -import ru.astrainteractive.gradleplugin.property.extension.ModelPropertyValueExt.requireProjectInfo +import ru.astrainteractive.gradleplugin.plugin.mcresprocessor.ResourceProcessorScope +import ru.astrainteractive.gradleplugin.property.util.requireProjectInfo class ResourceProcessorPlugin : Plugin { override fun apply(target: Project) { diff --git a/build-logic/convention/src/main/kotlin/ru/astrainteractive/gradleplugin/plugin/WebpackNoSourceMapsPlugin.kt b/build-logic/convention/src/main/kotlin/ru/astrainteractive/gradleplugin/plugin/WebpackNoSourceMapsPlugin.kt new file mode 100644 index 0000000..05aae95 --- /dev/null +++ b/build-logic/convention/src/main/kotlin/ru/astrainteractive/gradleplugin/plugin/WebpackNoSourceMapsPlugin.kt @@ -0,0 +1,16 @@ +package ru.astrainteractive.gradleplugin.plugin + +import org.gradle.api.Plugin +import org.gradle.api.Project +import org.gradle.kotlin.dsl.withType +import org.jetbrains.kotlin.gradle.targets.js.webpack.KotlinWebpack + +/** + * Disable source maps in webpack builds + */ +class WebpackNoSourceMapsPlugin : Plugin { + override fun apply(target: Project) { + target.tasks.withType() + .configureEach { sourceMaps = false } + } +} diff --git a/build-logic/plugins/convention/src/main/kotlin/ru/astrainteractive/gradleplugin/plugin/detekt/DetektPlugin.kt b/build-logic/convention/src/main/kotlin/ru/astrainteractive/gradleplugin/plugin/detekt/DetektPlugin.kt similarity index 95% rename from build-logic/plugins/convention/src/main/kotlin/ru/astrainteractive/gradleplugin/plugin/detekt/DetektPlugin.kt rename to build-logic/convention/src/main/kotlin/ru/astrainteractive/gradleplugin/plugin/detekt/DetektPlugin.kt index a7c96aa..3d3238b 100644 --- a/build-logic/plugins/convention/src/main/kotlin/ru/astrainteractive/gradleplugin/plugin/detekt/DetektPlugin.kt +++ b/build-logic/convention/src/main/kotlin/ru/astrainteractive/gradleplugin/plugin/detekt/DetektPlugin.kt @@ -6,7 +6,7 @@ import org.gradle.api.Project import org.gradle.kotlin.dsl.dependencies import org.gradle.kotlin.dsl.register import org.gradle.kotlin.dsl.withType -import ru.astrainteractive.gradleplugin.property.extension.ModelPropertyValueExt.requireJinfo +import ru.astrainteractive.gradleplugin.property.util.requireJinfo class DetektPlugin : Plugin { override fun apply(target: Project) { diff --git a/build-logic/plugins/convention/src/main/kotlin/ru/astrainteractive/gradleplugin/plugin/dokka/DokkaModulePlugin.kt b/build-logic/convention/src/main/kotlin/ru/astrainteractive/gradleplugin/plugin/dokka/DokkaModulePlugin.kt similarity index 93% rename from build-logic/plugins/convention/src/main/kotlin/ru/astrainteractive/gradleplugin/plugin/dokka/DokkaModulePlugin.kt rename to build-logic/convention/src/main/kotlin/ru/astrainteractive/gradleplugin/plugin/dokka/DokkaModulePlugin.kt index 5fa7aaa..e6121cd 100644 --- a/build-logic/plugins/convention/src/main/kotlin/ru/astrainteractive/gradleplugin/plugin/dokka/DokkaModulePlugin.kt +++ b/build-logic/convention/src/main/kotlin/ru/astrainteractive/gradleplugin/plugin/dokka/DokkaModulePlugin.kt @@ -5,7 +5,7 @@ import org.gradle.api.Project import org.gradle.kotlin.dsl.named import org.gradle.kotlin.dsl.withType import org.jetbrains.dokka.gradle.DokkaTaskPartial -import ru.astrainteractive.gradleplugin.property.extension.ModelPropertyValueExt.requireJinfo +import ru.astrainteractive.gradleplugin.property.util.requireJinfo class DokkaModulePlugin : Plugin { override fun apply(target: Project) { diff --git a/build-logic/plugins/convention/src/main/kotlin/ru/astrainteractive/gradleplugin/plugin/dokka/DokkaRootPlugin.kt b/build-logic/convention/src/main/kotlin/ru/astrainteractive/gradleplugin/plugin/dokka/DokkaRootPlugin.kt similarity index 100% rename from build-logic/plugins/convention/src/main/kotlin/ru/astrainteractive/gradleplugin/plugin/dokka/DokkaRootPlugin.kt rename to build-logic/convention/src/main/kotlin/ru/astrainteractive/gradleplugin/plugin/dokka/DokkaRootPlugin.kt diff --git a/build-logic/plugins/minecraft/src/main/kotlin/ru/astrainteractive/gradleplugin/processor/plugin/ResourceProcessorScope.kt b/build-logic/convention/src/main/kotlin/ru/astrainteractive/gradleplugin/plugin/mcresprocessor/ResourceProcessorScope.kt similarity index 66% rename from build-logic/plugins/minecraft/src/main/kotlin/ru/astrainteractive/gradleplugin/processor/plugin/ResourceProcessorScope.kt rename to build-logic/convention/src/main/kotlin/ru/astrainteractive/gradleplugin/plugin/mcresprocessor/ResourceProcessorScope.kt index 5ee893b..7a64ca9 100644 --- a/build-logic/plugins/minecraft/src/main/kotlin/ru/astrainteractive/gradleplugin/processor/plugin/ResourceProcessorScope.kt +++ b/build-logic/convention/src/main/kotlin/ru/astrainteractive/gradleplugin/plugin/mcresprocessor/ResourceProcessorScope.kt @@ -1,14 +1,14 @@ -package ru.astrainteractive.gradleplugin.processor.plugin +package ru.astrainteractive.gradleplugin.plugin.mcresprocessor import org.gradle.api.Project import org.gradle.api.tasks.TaskProvider import org.gradle.kotlin.dsl.named import org.gradle.language.jvm.tasks.ProcessResources -import ru.astrainteractive.gradleplugin.model.ProjectInfo -import ru.astrainteractive.gradleplugin.processor.platform.BukkitResourceProcessor -import ru.astrainteractive.gradleplugin.processor.platform.FabricResourceProcessor -import ru.astrainteractive.gradleplugin.processor.platform.ForgeResourceProcessor -import ru.astrainteractive.gradleplugin.processor.platform.VelocityResourceProcessor +import ru.astrainteractive.gradleplugin.plugin.mcresprocessor.platform.BukkitResourceProcessor +import ru.astrainteractive.gradleplugin.plugin.mcresprocessor.platform.FabricResourceProcessor +import ru.astrainteractive.gradleplugin.plugin.mcresprocessor.platform.ForgeResourceProcessor +import ru.astrainteractive.gradleplugin.plugin.mcresprocessor.platform.VelocityResourceProcessor +import ru.astrainteractive.gradleplugin.property.model.ProjectInfo open class ResourceProcessorScope(private val projectInfo: ProjectInfo) { val Project.task: TaskProvider diff --git a/build-logic/plugins/minecraft/src/main/kotlin/ru/astrainteractive/gradleplugin/processor/core/ResourceProcessor.kt b/build-logic/convention/src/main/kotlin/ru/astrainteractive/gradleplugin/plugin/mcresprocessor/api/ResourceProcessor.kt similarity index 90% rename from build-logic/plugins/minecraft/src/main/kotlin/ru/astrainteractive/gradleplugin/processor/core/ResourceProcessor.kt rename to build-logic/convention/src/main/kotlin/ru/astrainteractive/gradleplugin/plugin/mcresprocessor/api/ResourceProcessor.kt index 142a3e3..0e51886 100644 --- a/build-logic/plugins/minecraft/src/main/kotlin/ru/astrainteractive/gradleplugin/processor/core/ResourceProcessor.kt +++ b/build-logic/convention/src/main/kotlin/ru/astrainteractive/gradleplugin/plugin/mcresprocessor/api/ResourceProcessor.kt @@ -1,4 +1,4 @@ -package ru.astrainteractive.gradleplugin.processor.core +package ru.astrainteractive.gradleplugin.plugin.mcresprocessor.api import org.gradle.api.tasks.TaskProvider import org.gradle.language.jvm.tasks.ProcessResources diff --git a/build-logic/plugins/minecraft/src/main/kotlin/ru/astrainteractive/gradleplugin/processor/platform/BukkitResourceProcessor.kt b/build-logic/convention/src/main/kotlin/ru/astrainteractive/gradleplugin/plugin/mcresprocessor/platform/BukkitResourceProcessor.kt similarity index 87% rename from build-logic/plugins/minecraft/src/main/kotlin/ru/astrainteractive/gradleplugin/processor/platform/BukkitResourceProcessor.kt rename to build-logic/convention/src/main/kotlin/ru/astrainteractive/gradleplugin/plugin/mcresprocessor/platform/BukkitResourceProcessor.kt index 833618c..59c0d9f 100644 --- a/build-logic/plugins/minecraft/src/main/kotlin/ru/astrainteractive/gradleplugin/processor/platform/BukkitResourceProcessor.kt +++ b/build-logic/convention/src/main/kotlin/ru/astrainteractive/gradleplugin/plugin/mcresprocessor/platform/BukkitResourceProcessor.kt @@ -1,67 +1,67 @@ -package ru.astrainteractive.gradleplugin.processor.platform - -import org.gradle.api.file.DuplicatesStrategy -import org.gradle.api.tasks.TaskProvider -import org.gradle.language.jvm.tasks.ProcessResources -import ru.astrainteractive.gradleplugin.model.Developer -import ru.astrainteractive.gradleplugin.model.ProjectInfo -import ru.astrainteractive.gradleplugin.processor.core.ResourceProcessor - -internal class BukkitResourceProcessor( - private val projectInfo: ProjectInfo -) : ResourceProcessor { - - data class Info( - val main: String, - val name: String, - val prefix: String, - val version: String, - val description: String, - val url: String, - val author: Developer, - val authors: List, - val libraries: List - ) : ResourceProcessor.ProcessorInfo - - override fun getProcessorInfo(): Info { - return Info( - main = "${projectInfo.group}.${projectInfo.name}", - name = projectInfo.name, - prefix = projectInfo.name, - version = projectInfo.versionString, - description = projectInfo.description, - url = projectInfo.url, - author = projectInfo.developersList.first(), - authors = projectInfo.developersList, - libraries = emptyList() - ) - } - - override fun getDefaultProperties(): Map { - val processorInfo = getProcessorInfo() - return mapOf( - "main" to processorInfo.main, - "name" to processorInfo.name, - "prefix" to processorInfo.prefix, - "version" to processorInfo.version, - "description" to processorInfo.description, - "url" to processorInfo.url, - "author" to processorInfo.author.id, - "authors" to processorInfo.authors.map(Developer::id).joinToString("\",\""), - "libraries" to processorInfo.libraries.joinToString("\",\""), - ) - } - - override fun process( - task: TaskProvider, - customProperties: Map, - ) { - task.configure { - filteringCharset = "UTF-8" - duplicatesStrategy = DuplicatesStrategy.WARN - filesMatching("plugin.yml") { - expand(getDefaultProperties().plus(customProperties)) - } - } - } -} +package ru.astrainteractive.gradleplugin.plugin.mcresprocessor.platform + +import org.gradle.api.file.DuplicatesStrategy +import org.gradle.api.tasks.TaskProvider +import org.gradle.language.jvm.tasks.ProcessResources +import ru.astrainteractive.gradleplugin.plugin.mcresprocessor.api.ResourceProcessor +import ru.astrainteractive.gradleplugin.property.model.Developer +import ru.astrainteractive.gradleplugin.property.model.ProjectInfo + +internal class BukkitResourceProcessor( + private val projectInfo: ProjectInfo +) : ResourceProcessor { + + data class Info( + val main: String, + val name: String, + val prefix: String, + val version: String, + val description: String, + val url: String, + val author: Developer, + val authors: List, + val libraries: List + ) : ResourceProcessor.ProcessorInfo + + override fun getProcessorInfo(): Info { + return Info( + main = "${projectInfo.group}.${projectInfo.name}", + name = projectInfo.name, + prefix = projectInfo.name, + version = projectInfo.versionString, + description = projectInfo.description, + url = projectInfo.url, + author = projectInfo.developersList.first(), + authors = projectInfo.developersList, + libraries = emptyList() + ) + } + + override fun getDefaultProperties(): Map { + val processorInfo = getProcessorInfo() + return mapOf( + "main" to processorInfo.main, + "name" to processorInfo.name, + "prefix" to processorInfo.prefix, + "version" to processorInfo.version, + "description" to processorInfo.description, + "url" to processorInfo.url, + "author" to processorInfo.author.id, + "authors" to processorInfo.authors.map(Developer::id).joinToString("\",\""), + "libraries" to processorInfo.libraries.joinToString("\",\""), + ) + } + + override fun process( + task: TaskProvider, + customProperties: Map, + ) { + task.configure { + filteringCharset = "UTF-8" + duplicatesStrategy = DuplicatesStrategy.WARN + filesMatching("plugin.yml") { + expand(getDefaultProperties().plus(customProperties)) + } + } + } +} diff --git a/build-logic/plugins/minecraft/src/main/kotlin/ru/astrainteractive/gradleplugin/processor/platform/FabricResourceProcessor.kt b/build-logic/convention/src/main/kotlin/ru/astrainteractive/gradleplugin/plugin/mcresprocessor/platform/FabricResourceProcessor.kt similarity index 83% rename from build-logic/plugins/minecraft/src/main/kotlin/ru/astrainteractive/gradleplugin/processor/platform/FabricResourceProcessor.kt rename to build-logic/convention/src/main/kotlin/ru/astrainteractive/gradleplugin/plugin/mcresprocessor/platform/FabricResourceProcessor.kt index a839675..51b4bd9 100644 --- a/build-logic/plugins/minecraft/src/main/kotlin/ru/astrainteractive/gradleplugin/processor/platform/FabricResourceProcessor.kt +++ b/build-logic/convention/src/main/kotlin/ru/astrainteractive/gradleplugin/plugin/mcresprocessor/platform/FabricResourceProcessor.kt @@ -1,10 +1,10 @@ -package ru.astrainteractive.gradleplugin.processor.platform +package ru.astrainteractive.gradleplugin.plugin.mcresprocessor.platform import org.gradle.api.file.DuplicatesStrategy import org.gradle.api.tasks.TaskProvider import org.gradle.language.jvm.tasks.ProcessResources -import ru.astrainteractive.gradleplugin.model.ProjectInfo -import ru.astrainteractive.gradleplugin.processor.core.ResourceProcessor +import ru.astrainteractive.gradleplugin.plugin.mcresprocessor.api.ResourceProcessor +import ru.astrainteractive.gradleplugin.property.model.ProjectInfo internal class FabricResourceProcessor( private val projectInfo: ProjectInfo diff --git a/build-logic/plugins/minecraft/src/main/kotlin/ru/astrainteractive/gradleplugin/processor/platform/ForgeResourceProcessor.kt b/build-logic/convention/src/main/kotlin/ru/astrainteractive/gradleplugin/plugin/mcresprocessor/platform/ForgeResourceProcessor.kt similarity index 84% rename from build-logic/plugins/minecraft/src/main/kotlin/ru/astrainteractive/gradleplugin/processor/platform/ForgeResourceProcessor.kt rename to build-logic/convention/src/main/kotlin/ru/astrainteractive/gradleplugin/plugin/mcresprocessor/platform/ForgeResourceProcessor.kt index 22eb449..08323fa 100644 --- a/build-logic/plugins/minecraft/src/main/kotlin/ru/astrainteractive/gradleplugin/processor/platform/ForgeResourceProcessor.kt +++ b/build-logic/convention/src/main/kotlin/ru/astrainteractive/gradleplugin/plugin/mcresprocessor/platform/ForgeResourceProcessor.kt @@ -1,13 +1,14 @@ -package ru.astrainteractive.gradleplugin.processor.platform +package ru.astrainteractive.gradleplugin.plugin.mcresprocessor.platform import org.gradle.api.file.DuplicatesStrategy import org.gradle.api.file.SourceDirectorySet import org.gradle.api.tasks.SourceSet +import org.gradle.api.tasks.SourceSetContainer import org.gradle.api.tasks.TaskProvider import org.gradle.language.jvm.tasks.ProcessResources -import ru.astrainteractive.gradleplugin.model.Developer -import ru.astrainteractive.gradleplugin.model.ProjectInfo -import ru.astrainteractive.gradleplugin.processor.core.ResourceProcessor +import ru.astrainteractive.gradleplugin.plugin.mcresprocessor.api.ResourceProcessor +import ru.astrainteractive.gradleplugin.property.model.Developer +import ru.astrainteractive.gradleplugin.property.model.ProjectInfo internal class ForgeResourceProcessor( private val projectInfo: ProjectInfo @@ -49,7 +50,7 @@ internal class ForgeResourceProcessor( task.configure { filteringCharset = "UTF-8" duplicatesStrategy = DuplicatesStrategy.WARN - val sourceSets = project.extensions.getByName("sourceSets") as org.gradle.api.tasks.SourceSetContainer + val sourceSets = project.extensions.getByName("sourceSets") as SourceSetContainer val resDirs = sourceSets .map(SourceSet::getResources) .map(SourceDirectorySet::getSrcDirs) diff --git a/build-logic/plugins/minecraft/src/main/kotlin/ru/astrainteractive/gradleplugin/processor/platform/VelocityResourceProcessor.kt b/build-logic/convention/src/main/kotlin/ru/astrainteractive/gradleplugin/plugin/mcresprocessor/platform/VelocityResourceProcessor.kt similarity index 85% rename from build-logic/plugins/minecraft/src/main/kotlin/ru/astrainteractive/gradleplugin/processor/platform/VelocityResourceProcessor.kt rename to build-logic/convention/src/main/kotlin/ru/astrainteractive/gradleplugin/plugin/mcresprocessor/platform/VelocityResourceProcessor.kt index df5754a..e851fc3 100644 --- a/build-logic/plugins/minecraft/src/main/kotlin/ru/astrainteractive/gradleplugin/processor/platform/VelocityResourceProcessor.kt +++ b/build-logic/convention/src/main/kotlin/ru/astrainteractive/gradleplugin/plugin/mcresprocessor/platform/VelocityResourceProcessor.kt @@ -1,11 +1,11 @@ -package ru.astrainteractive.gradleplugin.processor.platform +package ru.astrainteractive.gradleplugin.plugin.mcresprocessor.platform import org.gradle.api.file.DuplicatesStrategy import org.gradle.api.tasks.TaskProvider import org.gradle.language.jvm.tasks.ProcessResources -import ru.astrainteractive.gradleplugin.model.Developer -import ru.astrainteractive.gradleplugin.model.ProjectInfo -import ru.astrainteractive.gradleplugin.processor.core.ResourceProcessor +import ru.astrainteractive.gradleplugin.plugin.mcresprocessor.api.ResourceProcessor +import ru.astrainteractive.gradleplugin.property.model.Developer +import ru.astrainteractive.gradleplugin.property.model.ProjectInfo import java.util.Locale internal class VelocityResourceProcessor( diff --git a/build-logic/plugins/convention/src/main/kotlin/ru/astrainteractive/gradleplugin/property/mapping/DeveloperMapper.kt b/build-logic/convention/src/main/kotlin/ru/astrainteractive/gradleplugin/property/mapping/DeveloperMapper.kt similarity index 88% rename from build-logic/plugins/convention/src/main/kotlin/ru/astrainteractive/gradleplugin/property/mapping/DeveloperMapper.kt rename to build-logic/convention/src/main/kotlin/ru/astrainteractive/gradleplugin/property/mapping/DeveloperMapper.kt index de82534..8219898 100644 --- a/build-logic/plugins/convention/src/main/kotlin/ru/astrainteractive/gradleplugin/property/mapping/DeveloperMapper.kt +++ b/build-logic/convention/src/main/kotlin/ru/astrainteractive/gradleplugin/property/mapping/DeveloperMapper.kt @@ -1,9 +1,10 @@ package ru.astrainteractive.gradleplugin.property.mapping import org.gradle.api.GradleException -import ru.astrainteractive.gradleplugin.model.Developer +import ru.astrainteractive.gradleplugin.property.model.Developer object DeveloperMapper { + @Suppress("MagicNumber") fun parseDeveloper(value: String): Developer { val items: List = value.split("|").map(String::trim) if (items.size != 3) { diff --git a/build-logic/plugins/android/src/main/kotlin/ru/astrainteractive/gradleplugin/model/AndroidSdkInfo.kt b/build-logic/convention/src/main/kotlin/ru/astrainteractive/gradleplugin/property/model/AndroidSdkInfo.kt similarity index 61% rename from build-logic/plugins/android/src/main/kotlin/ru/astrainteractive/gradleplugin/model/AndroidSdkInfo.kt rename to build-logic/convention/src/main/kotlin/ru/astrainteractive/gradleplugin/property/model/AndroidSdkInfo.kt index 0a45d59..1221f69 100644 --- a/build-logic/plugins/android/src/main/kotlin/ru/astrainteractive/gradleplugin/model/AndroidSdkInfo.kt +++ b/build-logic/convention/src/main/kotlin/ru/astrainteractive/gradleplugin/property/model/AndroidSdkInfo.kt @@ -1,4 +1,4 @@ -package ru.astrainteractive.gradleplugin.model +package ru.astrainteractive.gradleplugin.property.model data class AndroidSdkInfo( val min: Int, diff --git a/build-logic/plugins/convention/src/main/kotlin/ru/astrainteractive/gradleplugin/model/Developer.kt b/build-logic/convention/src/main/kotlin/ru/astrainteractive/gradleplugin/property/model/Developer.kt similarity index 61% rename from build-logic/plugins/convention/src/main/kotlin/ru/astrainteractive/gradleplugin/model/Developer.kt rename to build-logic/convention/src/main/kotlin/ru/astrainteractive/gradleplugin/property/model/Developer.kt index fa59115..04390d7 100644 --- a/build-logic/plugins/convention/src/main/kotlin/ru/astrainteractive/gradleplugin/model/Developer.kt +++ b/build-logic/convention/src/main/kotlin/ru/astrainteractive/gradleplugin/property/model/Developer.kt @@ -1,4 +1,4 @@ -package ru.astrainteractive.gradleplugin.model +package ru.astrainteractive.gradleplugin.property.model data class Developer( val id: String, diff --git a/build-logic/plugins/convention/src/main/kotlin/ru/astrainteractive/gradleplugin/model/JInfo.kt b/build-logic/convention/src/main/kotlin/ru/astrainteractive/gradleplugin/property/model/JInfo.kt similarity index 77% rename from build-logic/plugins/convention/src/main/kotlin/ru/astrainteractive/gradleplugin/model/JInfo.kt rename to build-logic/convention/src/main/kotlin/ru/astrainteractive/gradleplugin/property/model/JInfo.kt index 53c678e..07d5207 100644 --- a/build-logic/plugins/convention/src/main/kotlin/ru/astrainteractive/gradleplugin/model/JInfo.kt +++ b/build-logic/convention/src/main/kotlin/ru/astrainteractive/gradleplugin/property/model/JInfo.kt @@ -1,4 +1,4 @@ -package ru.astrainteractive.gradleplugin.model +package ru.astrainteractive.gradleplugin.property.model import org.gradle.api.JavaVersion import org.jetbrains.kotlin.gradle.dsl.JvmTarget diff --git a/build-logic/plugins/convention/src/main/kotlin/ru/astrainteractive/gradleplugin/model/ProjectInfo.kt b/build-logic/convention/src/main/kotlin/ru/astrainteractive/gradleplugin/property/model/ProjectInfo.kt similarity index 77% rename from build-logic/plugins/convention/src/main/kotlin/ru/astrainteractive/gradleplugin/model/ProjectInfo.kt rename to build-logic/convention/src/main/kotlin/ru/astrainteractive/gradleplugin/property/model/ProjectInfo.kt index 3ef6627..e6cfe0a 100644 --- a/build-logic/plugins/convention/src/main/kotlin/ru/astrainteractive/gradleplugin/model/ProjectInfo.kt +++ b/build-logic/convention/src/main/kotlin/ru/astrainteractive/gradleplugin/property/model/ProjectInfo.kt @@ -1,4 +1,4 @@ -package ru.astrainteractive.gradleplugin.model +package ru.astrainteractive.gradleplugin.property.model data class ProjectInfo( val name: String, diff --git a/build-logic/plugins/convention/src/main/kotlin/ru/astrainteractive/gradleplugin/model/PublishInfo.kt b/build-logic/convention/src/main/kotlin/ru/astrainteractive/gradleplugin/property/model/PublishInfo.kt similarity index 86% rename from build-logic/plugins/convention/src/main/kotlin/ru/astrainteractive/gradleplugin/model/PublishInfo.kt rename to build-logic/convention/src/main/kotlin/ru/astrainteractive/gradleplugin/property/model/PublishInfo.kt index 74dbb16..bdab3bc 100644 --- a/build-logic/plugins/convention/src/main/kotlin/ru/astrainteractive/gradleplugin/model/PublishInfo.kt +++ b/build-logic/convention/src/main/kotlin/ru/astrainteractive/gradleplugin/property/model/PublishInfo.kt @@ -1,4 +1,4 @@ -package ru.astrainteractive.gradleplugin.model +package ru.astrainteractive.gradleplugin.property.model data class PublishInfo( val libraryName: String, diff --git a/build-logic/convention/src/main/kotlin/ru/astrainteractive/gradleplugin/property/util/ProjectPropertyValueExt.kt b/build-logic/convention/src/main/kotlin/ru/astrainteractive/gradleplugin/property/util/ProjectPropertyValueExt.kt new file mode 100644 index 0000000..0bd6af4 --- /dev/null +++ b/build-logic/convention/src/main/kotlin/ru/astrainteractive/gradleplugin/property/util/ProjectPropertyValueExt.kt @@ -0,0 +1,84 @@ +package ru.astrainteractive.gradleplugin.property.util + +import org.gradle.api.JavaVersion +import org.gradle.api.Project +import org.jetbrains.kotlin.gradle.dsl.JvmTarget +import ru.astrainteractive.gradle.property.api.PropertyValue +import ru.astrainteractive.gradle.property.api.klibsGradleProperty +import ru.astrainteractive.gradleplugin.property.mapping.DeveloperMapper +import ru.astrainteractive.gradleplugin.property.model.AndroidSdkInfo +import ru.astrainteractive.gradleplugin.property.model.Developer +import ru.astrainteractive.gradleplugin.property.model.JInfo +import ru.astrainteractive.gradleplugin.property.model.ProjectInfo +import ru.astrainteractive.gradleplugin.property.model.PublishInfo + +val PropertyValue.stringOrNull: String? + get() = getValue().getOrNull() +val PropertyValue.stringOrEmpty: String + get() = stringOrNull.orEmpty() +val PropertyValue.requireString: String + get() = getValue().getOrThrow() + +val PropertyValue.int: Result + get() = getValue().mapCatching { it.toInt() } + +val PropertyValue.intOrNull: Int? + get() = int.getOrNull() + +val PropertyValue.requireInt: Int + get() = int.getOrThrow() + +val PropertyValue.jvmTarget: Result + get() = getValue().mapCatching { JvmTarget.fromTarget(requireString) } + +val PropertyValue.requireJvmTarget: JvmTarget + get() = jvmTarget.getOrThrow() + +val PropertyValue.javaVersion: Result + get() = getValue().mapCatching { JavaVersion.toVersion(requireInt) } + +val PropertyValue.requireJavaVersion: JavaVersion + get() = javaVersion.getOrThrow() + +val Project.requireAndroidSdkInfo: AndroidSdkInfo + get() = AndroidSdkInfo( + compile = klibsGradleProperty("android.sdk.compile").requireInt, + min = klibsGradleProperty("android.sdk.min").requireInt, + target = klibsGradleProperty("android.sdk.target").requireInt + ) + +val Project.requireJinfo: JInfo + get() = JInfo( + ktarget = klibsGradleProperty("java.ktarget").requireJvmTarget, + jtarget = klibsGradleProperty("java.target").requireJavaVersion, + jsource = klibsGradleProperty("java.source").requireJavaVersion + ) + +val Project.requireProjectInfo: ProjectInfo + get() = ProjectInfo( + name = klibsGradleProperty("project.name").requireString, + group = klibsGradleProperty("project.group").requireString, + versionString = klibsGradleProperty("project.version.string").requireString, + description = klibsGradleProperty("project.description").requireString, + url = klibsGradleProperty("project.url").requireString, + developersList = klibsGradleProperty("project.developers").requireDevelopers, + ) + +val Project.requireVersionCode: Int + get() = klibsGradleProperty("project.version.code").requireInt + +val Project.requirePublishInfo: PublishInfo + get() = PublishInfo( + libraryName = klibsGradleProperty("publish.name").requireString, + description = klibsGradleProperty("publish.description").requireString, + gitHubOrganization = klibsGradleProperty("publish.repo.org").requireString, + gitHubName = klibsGradleProperty("publish.repo.name").requireString, + license = klibsGradleProperty("publish.license").requireString, + publishGroupId = klibsGradleProperty("publish.groupId").requireString, + ) + +val PropertyValue.developers: Result> + get() = getValue().mapCatching(DeveloperMapper::parseDevelopers) + +val PropertyValue.requireDevelopers: List + get() = developers.getOrThrow() diff --git a/build-logic/plugins/convention/src/main/kotlin/ru/astrainteractive/gradleplugin/plugin/secretfile/SecretFileTask.kt b/build-logic/convention/src/main/kotlin/ru/astrainteractive/gradleplugin/task/SecretFileTask.kt similarity index 93% rename from build-logic/plugins/convention/src/main/kotlin/ru/astrainteractive/gradleplugin/plugin/secretfile/SecretFileTask.kt rename to build-logic/convention/src/main/kotlin/ru/astrainteractive/gradleplugin/task/SecretFileTask.kt index 6279a78..5739736 100644 --- a/build-logic/plugins/convention/src/main/kotlin/ru/astrainteractive/gradleplugin/plugin/secretfile/SecretFileTask.kt +++ b/build-logic/convention/src/main/kotlin/ru/astrainteractive/gradleplugin/task/SecretFileTask.kt @@ -1,4 +1,4 @@ -package ru.astrainteractive.gradleplugin.plugin.secretfile +package ru.astrainteractive.gradleplugin.task import org.gradle.api.DefaultTask import org.gradle.api.provider.Property diff --git a/build-logic/plugins/android/src/main/kotlin/ru/astrainteractive/gradleplugin/util/ProjectExt.kt b/build-logic/convention/src/main/kotlin/ru/astrainteractive/gradleplugin/util/ProjectExt.kt similarity index 55% rename from build-logic/plugins/android/src/main/kotlin/ru/astrainteractive/gradleplugin/util/ProjectExt.kt rename to build-logic/convention/src/main/kotlin/ru/astrainteractive/gradleplugin/util/ProjectExt.kt index fef5f65..5c61843 100644 --- a/build-logic/plugins/android/src/main/kotlin/ru/astrainteractive/gradleplugin/util/ProjectExt.kt +++ b/build-logic/convention/src/main/kotlin/ru/astrainteractive/gradleplugin/util/ProjectExt.kt @@ -1,10 +1,12 @@ package ru.astrainteractive.gradleplugin.util import org.gradle.api.Project +import ru.astrainteractive.gradleplugin.property.util.requireProjectInfo internal val Project.hasAndroidKmpPlugin: Boolean get() = plugins .hasPlugin("com.android.kotlin.multiplatform.library") + internal val Project.hasAndroidLibPlugin: Boolean get() = plugins.hasPlugin("com.android.library") @@ -13,3 +15,15 @@ internal val Project.hasAndroidAppPlugin: Boolean internal val Project.hasAndroidPlugin: Boolean get() = hasAndroidAppPlugin || hasAndroidLibPlugin + +/** + * 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() = "${requireProjectInfo.group}.$path" + .replace("-", ".") + .replace(":", ".") + .replace("..", ".") + .lowercase() diff --git a/build-logic/plugins/convention/src/main/resources/detekt.yml b/build-logic/convention/src/main/resources/detekt.yml similarity index 100% rename from build-logic/plugins/convention/src/main/resources/detekt.yml rename to build-logic/convention/src/main/resources/detekt.yml diff --git a/build-logic/plugins/android/build.gradle.kts b/build-logic/plugins/android/build.gradle.kts deleted file mode 100755 index 5cf02e1..0000000 --- a/build-logic/plugins/android/build.gradle.kts +++ /dev/null @@ -1,63 +0,0 @@ -plugins { - `kotlin-dsl` - id("java-gradle-plugin") - id("com.vanniktech.maven.publish") -} - -dependencies { - compileOnly(libs.kotlin.gradle) - compileOnly(libs.android.gradle) - compileOnly(files(libs.javaClass.superclass.protectionDomain.codeSource.location)) - implementation(projects.buildLogic.plugins.convention) -} - -gradlePlugin { - website.set(projectWeb) - vcsUrl.set(projectWeb) - description = projectDescription - plugins { - create("android.java") { - id = "$projectGroup.$name" - implementationClass = "$projectGroup.plugin.AndroidJavaPlugin" - displayName = "KLibs java android plugin" - description = "Plugin provides basic android configuration" - tags.set(listOf("klibs")) - } - create("android.sdk") { - id = "$projectGroup.$name" - implementationClass = "$projectGroup.plugin.AndroidSdkPlugin" - displayName = "KLibs core android plugin" - description = "Plugin provides basic android configuration" - tags.set(listOf("klibs")) - } - create("android.namespace") { - id = "$projectGroup.$name" - implementationClass = "$projectGroup.plugin.AndroidNamespacePlugin" - displayName = "Generate android namespace" - description = "Plugin will automatically create namespace for android extension based ot folder path" - tags.set(listOf("klibs")) - } - create("android.compose") { - id = "$projectGroup.$name" - implementationClass = "$projectGroup.plugin.AndroidComposePlugin" - displayName = "KLibs core android-compose plugin" - description = "Plugin provides basic android compose setup" - tags.set(listOf("klibs")) - } - create("android.apk.sign") { - id = "$projectGroup.$name" - implementationClass = "$projectGroup.plugin.ApkSigningPlugin" - displayName = "KLibs android apk sign plugin" - description = "Plugin provides basic android sign" - - tags.set(listOf("klibs")) - } - create("android.apk.name") { - id = "$projectGroup.$name" - implementationClass = "$projectGroup.plugin.ApkNamePlugin" - displayName = "KLibs android apk name plugin" - description = "Plugin provides basic android naming setup" - tags.set(listOf("klibs")) - } - } -} diff --git a/build-logic/plugins/android/src/main/kotlin/ru/astrainteractive/gradleplugin/property/extension/AndroidModelPropertyValueExt.kt b/build-logic/plugins/android/src/main/kotlin/ru/astrainteractive/gradleplugin/property/extension/AndroidModelPropertyValueExt.kt deleted file mode 100644 index 8ebd0b6..0000000 --- a/build-logic/plugins/android/src/main/kotlin/ru/astrainteractive/gradleplugin/property/extension/AndroidModelPropertyValueExt.kt +++ /dev/null @@ -1,15 +0,0 @@ -package ru.astrainteractive.gradleplugin.property.extension - -import org.gradle.api.Project -import ru.astrainteractive.gradleplugin.model.AndroidSdkInfo -import ru.astrainteractive.gradleplugin.property.baseGradleProperty -import ru.astrainteractive.gradleplugin.property.extension.PrimitivePropertyValueExt.requireInt - -object AndroidModelPropertyValueExt { - val Project.requireAndroidSdkInfo: AndroidSdkInfo - get() = AndroidSdkInfo( - compile = baseGradleProperty("android.sdk.compile").requireInt, - min = baseGradleProperty("android.sdk.min").requireInt, - target = baseGradleProperty("android.sdk.target").requireInt - ) -} diff --git a/build-logic/plugins/android/src/main/kotlin/ru/astrainteractive/gradleplugin/property/extension/ExtendedAndroidPropertyExt.kt b/build-logic/plugins/android/src/main/kotlin/ru/astrainteractive/gradleplugin/property/extension/ExtendedAndroidPropertyExt.kt deleted file mode 100644 index db1cc61..0000000 --- a/build-logic/plugins/android/src/main/kotlin/ru/astrainteractive/gradleplugin/property/extension/ExtendedAndroidPropertyExt.kt +++ /dev/null @@ -1,10 +0,0 @@ -package ru.astrainteractive.gradleplugin.property.extension - -import org.gradle.api.Project -import ru.astrainteractive.gradleplugin.property.baseGradleProperty -import ru.astrainteractive.gradleplugin.property.extension.PrimitivePropertyValueExt.requireInt - -object ExtendedAndroidPropertyExt { - val Project.requireVersionCode: Int - get() = baseGradleProperty("project.version.code").requireInt -} diff --git a/build-logic/plugins/convention/build.gradle.kts b/build-logic/plugins/convention/build.gradle.kts deleted file mode 100755 index 3528638..0000000 --- a/build-logic/plugins/convention/build.gradle.kts +++ /dev/null @@ -1,72 +0,0 @@ -plugins { - `kotlin-dsl` - id("java-gradle-plugin") - id("com.vanniktech.maven.publish") -} - -dependencies { - compileOnly(libs.kotlin.gradle) - compileOnly(files(libs.javaClass.superclass.protectionDomain.codeSource.location)) - implementation(libs.detekt.gradle) - implementation(libs.dokka.gradle) - implementation(libs.dokka.core) - implementation(libs.dokka.base) - implementation(libs.vaniktech) -} - -gradlePlugin { - website.set(projectWeb) - vcsUrl.set(projectWeb) - description = projectDescription - plugins { - create("detekt") { - id = "$projectGroup.$name" - implementationClass = "$projectGroup.plugin.detekt.DetektPlugin" - displayName = "KLibs detekt plugin" - description = "Default setup for detekt plugin" - tags.set(listOf("klibs")) - } - create("dokka.module") { - id = "$projectGroup.$name" - implementationClass = "$projectGroup.plugin.dokka.DokkaModulePlugin" - displayName = "KLibs dokka for module configuration" - description = "Dokka generation for project module" - tags.set(listOf("klibs")) - } - create("dokka.root") { - id = "$projectGroup.$name" - implementationClass = "$projectGroup.plugin.dokka.DokkaRootPlugin" - displayName = "KLibs Dokka for root project" - description = "Dokka generator for root project" - tags.set(listOf("klibs")) - } - create("java.version") { - id = "$projectGroup.$name" - implementationClass = "$projectGroup.plugin.JavaVersionPlugin" - displayName = "KLibs java configuration" - description = "Default java configuration" - tags.set(listOf("klibs")) - } - create("java.utf8") { - id = "$projectGroup.$name" - implementationClass = "$projectGroup.plugin.JavaUtf8Plugin" - displayName = "KLibs java utf8 configuration" - description = "Default java utf8 configuration" - tags.set(listOf("klibs")) - } - create("root.info") { - id = "$projectGroup.$name" - implementationClass = "$projectGroup.plugin.ModuleInfoPlugin" - displayName = "KLibs root info plugin" - description = "Generates version, description for module" - tags.set(listOf("klibs")) - } - create("publication") { - id = "$projectGroup.$name" - implementationClass = "$projectGroup.plugin.PublicationPlugin" - displayName = "KLibs publication plugin" - description = "Default pulbication plugin" - tags.set(listOf("klibs")) - } - } -} diff --git a/build-logic/plugins/convention/src/main/kotlin/ru/astrainteractive/gradleplugin/property/PropertyValue.kt b/build-logic/plugins/convention/src/main/kotlin/ru/astrainteractive/gradleplugin/property/PropertyValue.kt deleted file mode 100644 index ec544dc..0000000 --- a/build-logic/plugins/convention/src/main/kotlin/ru/astrainteractive/gradleplugin/property/PropertyValue.kt +++ /dev/null @@ -1,42 +0,0 @@ -package ru.astrainteractive.gradleplugin.property - -import org.gradle.api.Project -import org.gradle.api.plugins.ExtensionContainer -import ru.astrainteractive.gradleplugin.property.internal.CachedPropertyValue -import ru.astrainteractive.gradleplugin.property.internal.ProjectPropertyValue -import ru.astrainteractive.gradleplugin.property.internal.SecretPropertyValue - -/** - * This interface will load [String] value from property file - */ -interface PropertyValue { - val key: String - fun getValue(): Result -} - -private const val BASE_PREFIX = "makeevrserg" - -fun Project.gradleProperty(path: String): ProjectPropertyValue { - return ProjectPropertyValue(this, path) -} - -fun Project.secretProperty(path: String): SecretPropertyValue { - return SecretPropertyValue(this, path) -} - -fun Project.baseGradleProperty(path: String): ProjectPropertyValue { - return ProjectPropertyValue(this, "$BASE_PREFIX.$path") -} - -fun Project.baseSecretProperty(path: String): SecretPropertyValue { - return SecretPropertyValue(this, "$BASE_PREFIX.$path") -} - -// Don't replace extensionContainer with project -// Different projects have different extensionContainer -fun PropertyValue.asCached(extensionContainer: ExtensionContainer): PropertyValue { - return CachedPropertyValue( - extensionContainer = extensionContainer, - propertyValue = this - ) -} diff --git a/build-logic/plugins/convention/src/main/kotlin/ru/astrainteractive/gradleplugin/property/extension/ExtendedPropertyValueExt.kt b/build-logic/plugins/convention/src/main/kotlin/ru/astrainteractive/gradleplugin/property/extension/ExtendedPropertyValueExt.kt deleted file mode 100644 index 1dc5cda..0000000 --- a/build-logic/plugins/convention/src/main/kotlin/ru/astrainteractive/gradleplugin/property/extension/ExtendedPropertyValueExt.kt +++ /dev/null @@ -1,22 +0,0 @@ -package ru.astrainteractive.gradleplugin.property.extension - -import org.gradle.api.JavaVersion -import org.jetbrains.kotlin.gradle.dsl.JvmTarget -import ru.astrainteractive.gradleplugin.property.PropertyValue -import ru.astrainteractive.gradleplugin.property.extension.PrimitivePropertyValueExt.requireInt -import ru.astrainteractive.gradleplugin.property.extension.PrimitivePropertyValueExt.requireString - -object ExtendedPropertyValueExt { - // JavaVersion - val PropertyValue.javaVersion: Result - get() = getValue().mapCatching { JavaVersion.toVersion(requireInt) } - - val PropertyValue.jvmTarget: Result - get() = getValue().mapCatching { JvmTarget.fromTarget(requireString) } - - val PropertyValue.requireJavaVersion: JavaVersion - get() = javaVersion.getOrThrow() - - val PropertyValue.requireJvmTarget: JvmTarget - get() = jvmTarget.getOrThrow() -} diff --git a/build-logic/plugins/convention/src/main/kotlin/ru/astrainteractive/gradleplugin/property/extension/ModelPropertyValueExt.kt b/build-logic/plugins/convention/src/main/kotlin/ru/astrainteractive/gradleplugin/property/extension/ModelPropertyValueExt.kt deleted file mode 100644 index 30a46ae..0000000 --- a/build-logic/plugins/convention/src/main/kotlin/ru/astrainteractive/gradleplugin/property/extension/ModelPropertyValueExt.kt +++ /dev/null @@ -1,61 +0,0 @@ -package ru.astrainteractive.gradleplugin.property.extension - -import org.gradle.api.Project -import ru.astrainteractive.gradleplugin.model.Developer -import ru.astrainteractive.gradleplugin.model.JInfo -import ru.astrainteractive.gradleplugin.model.ProjectInfo -import ru.astrainteractive.gradleplugin.model.PublishInfo -import ru.astrainteractive.gradleplugin.property.PropertyValue -import ru.astrainteractive.gradleplugin.property.baseGradleProperty -import ru.astrainteractive.gradleplugin.property.extension.ExtendedPropertyValueExt.requireJavaVersion -import ru.astrainteractive.gradleplugin.property.extension.ExtendedPropertyValueExt.requireJvmTarget -import ru.astrainteractive.gradleplugin.property.extension.PrimitivePropertyValueExt.requireString -import ru.astrainteractive.gradleplugin.property.mapping.DeveloperMapper - -object ModelPropertyValueExt { - val Project.requireJinfo: JInfo - get() = JInfo( - ktarget = baseGradleProperty("java.ktarget").requireJvmTarget, - jtarget = baseGradleProperty("java.target").requireJavaVersion, - jsource = baseGradleProperty("java.source").requireJavaVersion - ) - - val Project.requireProjectInfo: ProjectInfo - get() = ProjectInfo( - name = baseGradleProperty("project.name").requireString, - group = baseGradleProperty("project.group").requireString, - versionString = baseGradleProperty("project.version.string").requireString, - description = baseGradleProperty("project.description").requireString, - url = baseGradleProperty("project.url").requireString, - developersList = baseGradleProperty("project.developers").requireDevelopers, - ) - - val Project.requirePublishInfo: PublishInfo - get() = PublishInfo( - libraryName = baseGradleProperty("publish.name").requireString, - description = baseGradleProperty("publish.description").requireString, - gitHubOrganization = baseGradleProperty("publish.repo.org").requireString, - gitHubName = baseGradleProperty("publish.repo.name").requireString, - license = baseGradleProperty("publish.license").requireString, - publishGroupId = baseGradleProperty("publish.groupId").requireString, - ) - - // Developers - val PropertyValue.developers: Result> - get() = getValue().mapCatching(DeveloperMapper::parseDevelopers) - - val PropertyValue.requireDevelopers: List - 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() = "${requireProjectInfo.group}.$path" - .replace("-", ".") - .replace(":", ".") - .replace("..", ".") - .lowercase() -} diff --git a/build-logic/plugins/convention/src/main/kotlin/ru/astrainteractive/gradleplugin/property/extension/PrimitivePropertyValueExt.kt b/build-logic/plugins/convention/src/main/kotlin/ru/astrainteractive/gradleplugin/property/extension/PrimitivePropertyValueExt.kt deleted file mode 100644 index 3c24ca3..0000000 --- a/build-logic/plugins/convention/src/main/kotlin/ru/astrainteractive/gradleplugin/property/extension/PrimitivePropertyValueExt.kt +++ /dev/null @@ -1,21 +0,0 @@ -package ru.astrainteractive.gradleplugin.property.extension - -import ru.astrainteractive.gradleplugin.property.PropertyValue - -object PrimitivePropertyValueExt { - // String - val PropertyValue.stringOrNull: String? - get() = getValue().getOrNull() - val PropertyValue.stringOrEmpty: String - get() = stringOrNull.orEmpty() - val PropertyValue.requireString: String - get() = getValue().getOrThrow() - - // Integer - val PropertyValue.int: Result - get() = getValue().mapCatching { it.toInt() } - val PropertyValue.intOrNull: Int? - get() = int.getOrNull() - val PropertyValue.requireInt: Int - get() = int.getOrThrow() -} diff --git a/build-logic/plugins/minecraft/build.gradle.kts b/build-logic/plugins/minecraft/build.gradle.kts deleted file mode 100755 index 19fbb43..0000000 --- a/build-logic/plugins/minecraft/build.gradle.kts +++ /dev/null @@ -1,27 +0,0 @@ -plugins { - `kotlin-dsl` - id("java-gradle-plugin") - id("com.vanniktech.maven.publish") -} - -dependencies { - compileOnly(libs.kotlin.gradle) - compileOnly(files(libs.javaClass.superclass.protectionDomain.codeSource.location)) - implementation(libs.dokka.gradle) - implementation(projects.buildLogic.plugins.convention) -} - -gradlePlugin { - website.set(projectWeb) - vcsUrl.set(projectWeb) - description = projectDescription - plugins { - create("minecraft.resource-processor") { - id = "$projectGroup.$name" - implementationClass = "$projectGroup.processor.plugin.ResourceProcessorPlugin" - displayName = "KLibs minecraft resource processor plugin" - description = "Minecraft resource processor plugin" - tags.set(listOf("klibs")) - } - } -} diff --git a/build-logic/property/build.gradle.kts b/build-logic/property/build.gradle.kts new file mode 100755 index 0000000..28a1e15 --- /dev/null +++ b/build-logic/property/build.gradle.kts @@ -0,0 +1,9 @@ +plugins { + `kotlin-dsl` + id("com.vanniktech.maven.publish") +} + +dependencies { + compileOnly(files(libs.javaClass.superclass.protectionDomain.codeSource.location)) + compileOnly(libs.kotlin.gradle) +} diff --git a/build-logic/property/src/main/kotlin/ru/astrainteractive/gradle/property/api/PropertyValue.kt b/build-logic/property/src/main/kotlin/ru/astrainteractive/gradle/property/api/PropertyValue.kt new file mode 100644 index 0000000..d296809 --- /dev/null +++ b/build-logic/property/src/main/kotlin/ru/astrainteractive/gradle/property/api/PropertyValue.kt @@ -0,0 +1,45 @@ +package ru.astrainteractive.gradle.property.api + +import org.gradle.api.Project +import org.gradle.api.plugins.ExtensionContainer +import ru.astrainteractive.gradle.property.internal.CachedPropertyValue +import ru.astrainteractive.gradle.property.internal.ProjectPropertyValue +import ru.astrainteractive.gradle.property.internal.SecretPropertyValue + +/** + * This interface will load [String] value from property file + */ +interface PropertyValue { + val key: String + fun getValue(): Result +} + +private const val BASE_PREFIX = "klibs" + +fun Project.gradleProperty(path: String): PropertyValue { + return ProjectPropertyValue(this, path) +} + +fun Project.secretProperty(path: String): PropertyValue { + return SecretPropertyValue(this, path) +} + +fun Project.klibsGradleProperty(path: String): PropertyValue { + return ProjectPropertyValue(this, "$BASE_PREFIX.$path") +} + +fun Project.klibsSecretProperty(path: String): PropertyValue { + return SecretPropertyValue(this, "$BASE_PREFIX.$path") +} + +/** + * Don't replace extensionContainer with project + * + * Different projects have different extensionContainer + */ +fun PropertyValue.asCached(extensionContainer: ExtensionContainer): PropertyValue { + return CachedPropertyValue( + extensionContainer = extensionContainer, + propertyValue = this + ) +} diff --git a/build-logic/plugins/convention/src/main/kotlin/ru/astrainteractive/gradleplugin/property/internal/CachedPropertyValue.kt b/build-logic/property/src/main/kotlin/ru/astrainteractive/gradle/property/internal/CachedPropertyValue.kt similarity index 85% rename from build-logic/plugins/convention/src/main/kotlin/ru/astrainteractive/gradleplugin/property/internal/CachedPropertyValue.kt rename to build-logic/property/src/main/kotlin/ru/astrainteractive/gradle/property/internal/CachedPropertyValue.kt index 93e283a..ff45e22 100644 --- a/build-logic/plugins/convention/src/main/kotlin/ru/astrainteractive/gradleplugin/property/internal/CachedPropertyValue.kt +++ b/build-logic/property/src/main/kotlin/ru/astrainteractive/gradle/property/internal/CachedPropertyValue.kt @@ -1,9 +1,9 @@ -package ru.astrainteractive.gradleplugin.property.internal +package ru.astrainteractive.gradle.property.internal import org.gradle.api.plugins.ExtensionContainer -import ru.astrainteractive.gradleplugin.property.PropertyValue +import ru.astrainteractive.gradle.property.api.PropertyValue -class CachedPropertyValue( +internal class CachedPropertyValue( private val extensionContainer: ExtensionContainer, private val propertyValue: PropertyValue ) : PropertyValue { diff --git a/build-logic/plugins/convention/src/main/kotlin/ru/astrainteractive/gradleplugin/property/internal/ProjectPropertyValue.kt b/build-logic/property/src/main/kotlin/ru/astrainteractive/gradle/property/internal/ProjectPropertyValue.kt similarity index 77% rename from build-logic/plugins/convention/src/main/kotlin/ru/astrainteractive/gradleplugin/property/internal/ProjectPropertyValue.kt rename to build-logic/property/src/main/kotlin/ru/astrainteractive/gradle/property/internal/ProjectPropertyValue.kt index f0c5941..d0a62ab 100644 --- a/build-logic/plugins/convention/src/main/kotlin/ru/astrainteractive/gradleplugin/property/internal/ProjectPropertyValue.kt +++ b/build-logic/property/src/main/kotlin/ru/astrainteractive/gradle/property/internal/ProjectPropertyValue.kt @@ -1,41 +1,41 @@ -package ru.astrainteractive.gradleplugin.property.internal - -import org.gradle.api.GradleException -import org.gradle.api.Project -import ru.astrainteractive.gradleplugin.property.PropertyValue -import ru.astrainteractive.gradleplugin.property.gradleProperties -import ru.astrainteractive.gradleplugin.property.localProperties - -/** - * This class will load property from gradle.properties project file - */ -class ProjectPropertyValue( - private val project: Project, - override val key: String -) : PropertyValue { - private fun getGradleProperty(): Result { - return runCatching { - project.providers.gradleProperty(key) - .orNull - ?: throw GradleException("Required property $key not defined!") - } - } - - private fun getGradleFileProperty(): Result { - return runCatching { project.gradleProperties.getProperty(key) } - } - - private fun getLocalProperty(): Result { - return runCatching { project.localProperties.getProperty(key) } - } - - override fun getValue() = runCatching { - getLocalProperty().getOrNull() - ?: getGradleFileProperty().getOrNull() - ?: getGradleProperty().getOrThrow() - }.onFailure { _ -> - project.logger.warn( - "Couldn't find $key in local.properties, gradle.properties, and project.providers.gradleProperty" - ) - } -} +package ru.astrainteractive.gradle.property.internal + +import org.gradle.api.GradleException +import org.gradle.api.Project +import ru.astrainteractive.gradle.property.api.PropertyValue +import ru.astrainteractive.gradle.util.gradleProperties +import ru.astrainteractive.gradle.util.localProperties + +/** + * This class will load property from gradle.properties project file + */ +internal class ProjectPropertyValue( + private val project: Project, + override val key: String +) : PropertyValue { + private fun getGradleProperty(): Result { + return runCatching { + project.providers.gradleProperty(key) + .orNull + ?: throw GradleException("Required property $key not defined!") + } + } + + private fun getGradleFileProperty(): Result { + return runCatching { project.gradleProperties.getProperty(key) } + } + + private fun getLocalProperty(): Result { + return runCatching { project.localProperties.getProperty(key) } + } + + override fun getValue() = runCatching { + getLocalProperty().getOrNull() + ?: getGradleFileProperty().getOrNull() + ?: getGradleProperty().getOrThrow() + }.onFailure { _ -> + project.logger.warn( + "Couldn't find $key in local.properties, gradle.properties, and project.providers.gradleProperty" + ) + } +} diff --git a/build-logic/plugins/convention/src/main/kotlin/ru/astrainteractive/gradleplugin/property/internal/SecretPropertyValue.kt b/build-logic/property/src/main/kotlin/ru/astrainteractive/gradle/property/internal/SecretPropertyValue.kt similarity index 78% rename from build-logic/plugins/convention/src/main/kotlin/ru/astrainteractive/gradleplugin/property/internal/SecretPropertyValue.kt rename to build-logic/property/src/main/kotlin/ru/astrainteractive/gradle/property/internal/SecretPropertyValue.kt index 564b7e2..d97a660 100644 --- a/build-logic/plugins/convention/src/main/kotlin/ru/astrainteractive/gradleplugin/property/internal/SecretPropertyValue.kt +++ b/build-logic/property/src/main/kotlin/ru/astrainteractive/gradle/property/internal/SecretPropertyValue.kt @@ -1,31 +1,31 @@ -package ru.astrainteractive.gradleplugin.property.internal - -import org.gradle.api.GradleException -import org.gradle.api.Project -import ru.astrainteractive.gradleplugin.property.PropertyValue -import ru.astrainteractive.gradleplugin.property.localProperties - -/** - * This class will load property from local.properties project file - */ -class SecretPropertyValue( - private val project: Project, - override val key: String -) : PropertyValue { - - /** - * System.getenv doesn't allow dots - */ - private val envKey: String = key.replace(".", "_") - - override fun getValue() = runCatching { - // try to get system ci property - val systemEnvProperty = System.getenv(envKey) - if (systemEnvProperty != null) return@runCatching systemEnvProperty - project.logger.warn("System.enviroment $envKey is missing. Getting it from local.properties") - // if not ci getting from local.properties - return@runCatching project.localProperties - .getProperty(key) - ?: throw GradleException("Required property $key not defined!") - } -} +package ru.astrainteractive.gradle.property.internal + +import org.gradle.api.GradleException +import org.gradle.api.Project +import ru.astrainteractive.gradle.property.api.PropertyValue +import ru.astrainteractive.gradle.util.localProperties + +/** + * This class will load property from local.properties project file + */ +internal class SecretPropertyValue( + private val project: Project, + override val key: String +) : PropertyValue { + + /** + * System.getenv doesn't allow dots + */ + private val envKey: String = key.replace(".", "_") + + override fun getValue() = runCatching { + // try to get system ci property + val systemEnvProperty = System.getenv(envKey) + if (systemEnvProperty != null) return@runCatching systemEnvProperty + project.logger.warn("System.enviroment $envKey is missing. Getting it from local.properties") + // if not ci getting from local.properties + return@runCatching project.localProperties + .getProperty(key) + ?: throw GradleException("Required property $key not defined!") + } +} diff --git a/build-logic/plugins/convention/src/main/kotlin/ru/astrainteractive/gradleplugin/property/ProjectExt.kt b/build-logic/property/src/main/kotlin/ru/astrainteractive/gradle/util/ProjectExt.kt similarity index 55% rename from build-logic/plugins/convention/src/main/kotlin/ru/astrainteractive/gradleplugin/property/ProjectExt.kt rename to build-logic/property/src/main/kotlin/ru/astrainteractive/gradle/util/ProjectExt.kt index 3cadfc1..64b3067 100644 --- a/build-logic/plugins/convention/src/main/kotlin/ru/astrainteractive/gradleplugin/property/ProjectExt.kt +++ b/build-logic/property/src/main/kotlin/ru/astrainteractive/gradle/util/ProjectExt.kt @@ -1,4 +1,4 @@ -package ru.astrainteractive.gradleplugin.property +package ru.astrainteractive.gradle.util import org.gradle.api.GradleException import org.gradle.api.Project @@ -8,27 +8,27 @@ import java.nio.file.Files import java.util.Properties import kotlin.io.path.reader -private fun File.takeIfIsLinkOrExist(): File? { +private fun File.takeIfExists(): File? { if (exists() || Files.isSymbolicLink(toPath())) return this return null } -internal fun Project.fileOrParentFile(name: String): File? { +private fun Project.findFileOrParentFile(name: String): File? { val parentOrNull = parent - val projectFileOrNull = file(name).takeIfIsLinkOrExist() + val projectFileOrNull = file(name).takeIfExists() return when { projectFileOrNull != null -> projectFileOrNull - parentOrNull != null -> parentOrNull.fileOrParentFile(name) - else -> rootProject.file(name).takeIfIsLinkOrExist() + parentOrNull != null -> parentOrNull.findFileOrParentFile(name) + else -> rootProject.file(name).takeIfExists() } } -internal fun Project.requireFileOrParentFile(name: String): File { - return fileOrParentFile(name) +private fun Project.requireFileOrParentFile(name: String): File { + return findFileOrParentFile(name) ?: throw GradleException("No $name file found") } -private fun File.defaultOrSymbolicReader(): InputStreamReader { +private fun File.symbolicLinkAwareReader(): InputStreamReader { val file = this val path = file.toPath() return if (Files.isSymbolicLink(path)) { @@ -38,16 +38,16 @@ private fun File.defaultOrSymbolicReader(): InputStreamReader { } } -internal val Project.localProperties: Properties +val Project.localProperties: Properties get() = Properties().apply { requireFileOrParentFile("local.properties") - .defaultOrSymbolicReader() + .symbolicLinkAwareReader() .run(::load) } -internal val Project.gradleProperties: Properties +val Project.gradleProperties: Properties get() = Properties().apply { requireFileOrParentFile("gradle.properties") - .defaultOrSymbolicReader() + .symbolicLinkAwareReader() .run(::load) } diff --git a/build-logic/settings.gradle.kts b/build-logic/settings.gradle.kts index 3a2e7a0..f497f56 100644 --- a/build-logic/settings.gradle.kts +++ b/build-logic/settings.gradle.kts @@ -26,6 +26,5 @@ dependencyResolutionManagement { rootProject.name = "build-logic" -include(":plugins:convention") -include(":plugins:android") -include(":plugins:minecraft") +include(":convention") +include(":property") diff --git a/docs/android.md b/docs/android.md index 8a47a49..51a28b7 100644 --- a/docs/android.md +++ b/docs/android.md @@ -1,76 +1,122 @@ -## Gradle Suite Android plugins +## Android Plugins -*Some functionality may be dependent on [convention.md](convention.md)* +*Depends on properties defined in [convention.md](convention.md)* -### Gradle Suite Android pre-defined properties +--- + +### Properties ```properties -android.sdk.compile=36 -android.sdk.min=22 -android.sdk.target=36 +klibs.android.sdk.compile=36 +klibs.android.sdk.min=24 +klibs.android.sdk.target=36 +klibs.android.kotlinCompilerExtensionVersion=1.5.1 + +klibs.java.source=11 +klibs.java.target=11 +klibs.java.ktarget=11 ``` --- -### Android SDK plugin +### Android SDK + +**ID:** `ru.astrainteractive.gradleplugin.android.sdk` -*Supports both `com.android.kotlin.multiplatform.library` and `com.android.library`* +Sets `compileSdk`, `minSdk`, and `targetSdk` from properties. Supports `com.android.application`, `com.android.library`, and `com.android.kotlin.multiplatform.library`. ```kotlin plugins { - // This will set up all android.sdk from above alias(libs.plugins.klibs.gradle.android.sdk) -} +} ``` -### Android compose plugin +--- + +### Android Java + +**ID:** `ru.astrainteractive.gradleplugin.android.java` + +Configures Java compile options and Kotlin JVM target for Android and KMP Android targets. ```kotlin plugins { - // this will enable buildFeatures.compose - // and will set composeOptions.kotlinCompilerExtensionVersion - id("ru.astrainteractive.gradleplugin.android.compose") -} + alias(libs.plugins.klibs.gradle.android.java) +} ``` -In your gradle.properties +--- -```properties -makeevrserg.android.kotlinCompilerExtensionVersion=1.5.1 +### Android Namespace + +**ID:** `ru.astrainteractive.gradleplugin.android.namespace` + +Automatically generates Android namespace from module path hierarchy. Supports both standard Android and KMP Android targets. + +```kotlin +plugins { + alias(libs.plugins.klibs.gradle.android.namespace) +} +``` + +For a project with path `:instances:module:app` and `klibs.project.group=com.example`, the namespace will be `com.example.instances.module.app`. + +--- + +### Android Compose + +**ID:** `ru.astrainteractive.gradleplugin.android.compose` + +Enables Compose build feature and sets the Kotlin compiler extension version. + +```kotlin +plugins { + alias(libs.plugins.klibs.gradle.android.compose) +} ``` -### Android apk sign plugin +Reads `klibs.android.kotlinCompilerExtensionVersion` from properties. + +--- + +### Android APK Sign + +**ID:** `ru.astrainteractive.gradleplugin.android.apk.sign` -See [Base64 Secret plugin section here](./convention.md) for secret file generation +Configures debug and release signing configs using a `keystore.jks` file and secret properties. ```kotlin plugins { - // this will create default sign config for apk - // keystore.jks will be taken from current project folder - // if no keystore.jks - no signing configs will be applied - id("ru.astrainteractive.gradleplugin.android.apk.sign") -} + alias(libs.plugins.klibs.gradle.android.apk.sign) +} ``` -In your local.properties +Expects `keystore.jks` in the module directory. Secret properties in `local.properties`: ```properties -KEY_PASSWORD=MY_PASSWORD -KEY_ALIAS=MY_ALIAS -STORE_PASSWORD=MY_STORE_PASSWORD +klibs.KEY_PASSWORD=MY_PASSWORD +klibs.KEY_ALIAS=MY_ALIAS +klibs.STORE_PASSWORD=MY_STORE_PASSWORD ``` -### Android namespace plugin +If the keystore file or any secret is missing, signing will be skipped with a warning. + +See [SecretFileTask](convention.md#secretfiletask) for generating `keystore.jks` from Base64 in CI/CD. + +--- + +### Android APK Name -*Supports both `com.android.kotlin.multiplatform.library` and `com.android.library`* +**ID:** `ru.astrainteractive.gradleplugin.android.apk.name` + +Automatically names APK output files using project info. ```kotlin plugins { - // This plugin will auto-generate namespace - // If you project path is :instances:module:app - // And your requireProjectInfo.group=com.example - // You will have "com.example.instances.module.app" - id("ru.astrainteractive.gradleplugin.android.namespace") - + alias(libs.plugins.klibs.gradle.android.apk.name) } -``` \ No newline at end of file +``` + +Output format: `{name}_{version}_{variant}.apk` (e.g. `MyApp_1.0.0_release.apk`). + +Uses `klibs.project.name` and `klibs.project.version.string` from properties. diff --git a/docs/convention.md b/docs/convention.md index 7e8e55d..76286b2 100644 --- a/docs/convention.md +++ b/docs/convention.md @@ -1,148 +1,290 @@ -## Gradle Suite properties +## Convention Module -### Gradle Suite pre-defined properties +The `convention` module provides a suite of Gradle plugins for standard build configurations across Kotlin, Java, Android, JavaScript, and Minecraft projects. + +> See also: [Property Module](property.md) for details on the property system used by these plugins. + +--- + +## Properties + +Most plugins read configuration from `gradle.properties` using the `klibs.` prefix. Below is a complete list of properties used by the convention plugins. + +### Java properties + +```properties +klibs.java.source=8 +klibs.java.target=11 +klibs.java.ktarget=11 +``` + +### Project properties + +```properties +klibs.project.name=MyProject +klibs.project.group=com.example.project +klibs.project.version.string=0.0.1-SNAPSHOT +klibs.project.version.code=1 +klibs.project.description=This is my template project! +klibs.project.url=https://www.yourwebsite.com +# Split by [,] symbol. Format: id|name|email +klibs.project.developers=makeevrserg|Makeev Roman|makeevrserg@gmail.com +``` + +### Publish properties + +```properties +klibs.publish.name=MyProject +klibs.publish.description=My publish project description +klibs.publish.repo.org=Your-Organization +klibs.publish.repo.name=YourRepoName +klibs.publish.license=Apache-2.0 +klibs.publish.groupId=io.github.yourname +``` + +### Android properties ```properties -# JavaInfo -java.source=8 -java.ktarget=11 -java.target=11 +klibs.android.sdk.compile=36 +klibs.android.sdk.min=24 +klibs.android.sdk.target=36 +klibs.android.kotlinCompilerExtensionVersion=1.5.1 +``` -# ProjectInfo -makeevrserg.project.name=MyProject -makeevrserg.project.description=This is my template project! -makeevrserg.project.group=com.example.project -makeevrserg.project.version.string=0.0.1-SNAPSHOT -makeevrserg.project.url=www.yourwebsiute.com -# Split by [,] symbol -makeevrserg.project.developers=makeevrserg|Makeev Roman|makeevrserg@gmail.com,... +### Secret properties (local.properties or environment) -# PublishInfo -publish.name=MyProject -publish.description=My publish project description -publish.repo.org=Your-Organization -publish.repo.name=YourRepoName -publish.license=Apache-2.0 -publish.groupId=io.github.yourname +```properties +klibs.KEY_PASSWORD=MY_PASSWORD +klibs.KEY_ALIAS=MY_ALIAS +klibs.STORE_PASSWORD=MY_STORE_PASSWORD ``` -#### Getting pre-defined properties +> For CI/CD environment variables, replace `.` with `_` (e.g. `klibs_KEY_PASSWORD`). -To get this properties in your project, use: +### Getting pre-defined property models ```kotlin -// ProjectInfo -println(requireProjectInfo) -// PublishInfo -println(requirePublishInfo) -// JavaInfo -println(requireJinfo) +// JInfo - Java version configuration +val jinfo = project.requireJinfo +// jinfo.jsource: JavaVersion, jinfo.jtarget: JavaVersion, jinfo.ktarget: JvmTarget + +// ProjectInfo - Project metadata +val projectInfo = project.requireProjectInfo +// projectInfo.name, .group, .versionString, .description, .url, .developersList + +// PublishInfo - Publication metadata +val publishInfo = project.requirePublishInfo +// publishInfo.libraryName, .description, .gitHubOrganization, .gitHubName, .license, .publishGroupId +// publishInfo.gitHubUrl, .sshUrl (derived) + +// AndroidSdkInfo - Android SDK versions +val androidSdkInfo = project.requireAndroidSdkInfo +// androidSdkInfo.compile, .min, .target + +// Version code +val versionCode: Int = project.requireVersionCode + +// Hierarchy group - auto-generated namespace from module path +val namespace: String = project.hierarchyGroup +// e.g. :components:core:resource -> "com.example.components.core.resource" ``` -### Gradle Suite custom properties +--- + +## Plugins -You can get custom-related properties +### Detekt -#### Getting `gradle-properties` +**ID:** `ru.astrainteractive.gradleplugin.detekt` -This will get properties from `local.properties` first. If not found, from `gradle.properties` +Applies and configures [Detekt](https://detekt.dev/) static code analysis with a bundled `detekt.yml` configuration. ```kotlin -val gradleProperty: PropertyValue = target.gradleProperty("somevar") +plugins { + alias(libs.plugins.klibs.gradle.detekt) +} +``` + +- Applies `dev.detekt` plugin +- Registers `detektFormat` task with auto-correction enabled +- Writes bundled `detekt.yml` to root project build directory +- Configures HTML reports, parallel execution, source includes/excludes +- Adds `detekt-rules-ktlint-wrapper` and `compose-rules:detekt` plugins +- Sets JVM target from `klibs.java.target` + +--- + +### Dokka Module -// The [PropertyValue] looks like this -interface PropertyValue { - val key: String - fun getValue(): Result +**ID:** `ru.astrainteractive.gradleplugin.dokka.module` + +Configures [Dokka](https://github.com/Kotlin/dokka) documentation generation for individual modules. + +```kotlin +plugins { + alias(libs.plugins.klibs.gradle.dokka.module) } -// And it contains a lot of extensions -gradleProperty.stringOrEmpty -gradleProperty.stringOrNull -gradleProperty.intOrNull -gradleProperty.requireInt -// and etc ``` -#### Getting `secret-properties` +- Applies `org.jetbrains.dokka` plugin +- Sets module name from `project.name` +- JDK version from `klibs.java.target` +- Supports `README.md` as module documentation entry point via `DokkaTaskPartial` + +--- + +### Dokka Root + +**ID:** `ru.astrainteractive.gradleplugin.dokka.root` -Secret properties will be taken from your `Environment` or `local.properties` +Configures multi-module Dokka documentation generation for root projects. ```kotlin -val secretProperty: PropertyValue = target.secretProperty("somevar") +plugins { + alias(libs.plugins.klibs.gradle.dokka.root) +} ``` -> [!WARNING] -> Environment variables doesn't allow to use `.` symbols. So for `System.Environment` the `.` replaced by `_` -> -> **Example:** In your `secret.properties` you'll have `property.first` and in `CI env` you'll have `properties_first`. +- Applies `org.jetbrains.dokka` plugin +- Configures `DokkaMultiModuleTask` with `README.md` or `dokka.md` as entry points +- Sets module name from `project.name` --- -## Gradle Suite plugins +### Java Version -### Detekt +**ID:** `ru.astrainteractive.gradleplugin.java.version` + +Configures Java source/target compatibility and Kotlin JVM target. ```kotlin plugins { - // This plugin will apply detekt plugin and it's custom detekt.yml - alias(libs.plugins.klibs.gradle.detekt) - // Or if compose exists in this module use detekt-compose - alias(libs.plugins.klibs.gradle.detekt.compose) + alias(libs.plugins.klibs.gradle.java.version) } ``` -### Dokka +- Sets `JavaPluginExtension.sourceCompatibility` from `klibs.java.source` +- Sets `JavaPluginExtension.targetCompatibility` from `klibs.java.target` +- Configures all `KotlinCompile` tasks JVM target from `klibs.java.ktarget` + +--- + +### Java UTF-8 + +**ID:** `ru.astrainteractive.gradleplugin.java.utf8` + +Sets UTF-8 encoding for all Java compilation tasks. ```kotlin plugins { - // Dokka for root build.gradle.kts - // If there's readme - it will be main page of documentation - alias(libs.plugins.klibs.gradle.dokka.root) apply false - // Dokka for single module - // You can also include README.md inside module - // and dokka will create this README as main page - alias(libs.plugins.klibs.gradle.dokka.module) apply false + alias(libs.plugins.klibs.gradle.java.utf8) } ``` -### Java info +- Sets `options.encoding = "UTF-8"` for all `JavaCompile` tasks + +--- + +### Module Info + +**ID:** `ru.astrainteractive.gradleplugin.rootinfo` + +Applies project group, version, and description from properties. ```kotlin plugins { - // This will setup project java version - // And kotlin compile java - alias(libs.plugins.klibs.gradle.java.version) apply false - // This will enable options.encoding = "UTF-8" - alias(libs.plugins.klibs.gradle.java.utf8) apply false + alias(libs.plugins.klibs.gradle.rootinfo) } ``` -### Publication plugin +- Sets `project.group` from `klibs.project.group` +- Sets `project.version` from `klibs.project.version.string` +- Sets `project.description` from `klibs.project.description` +- Warns if applied to a non-root project + +--- + +### Publication + +**ID:** `ru.astrainteractive.gradleplugin.publication` + +Configures Maven Central publication via [Vanniktech Maven Publish](https://github.com/vanniktech/gradle-maven-publish-plugin). ```kotlin plugins { - // This plugin will create publication to sonatype repository - id("ru.astrainteractive.gradleplugin.publication") + alias(libs.plugins.klibs.gradle.publication) } ``` -In your local.properties +- Applies `com.vanniktech.maven.publish` plugin +- Configures `publishToMavenCentral(automaticRelease = false)` +- Sets coordinates from `klibs.publish.groupId`, `project.name`, `klibs.project.version.string` +- Signs all publications +- Generates full POM (name, description, URL, license, developers, SCM) from project and publish properties + +Required secret properties in `local.properties`: ```properties -OSSRH_USERNAME=OSSRH_USERNAME -OSSRH_PASSWORD=OSSRH_PASSWORD -SIGNING_KEY=SIGNING_KEY -SIGNING_KEY_ID=SIGNING_KEY_ID -SIGNING_PASSWORD=SIGNING_PASSWORD +OSSRH_USERNAME=your_username +OSSRH_PASSWORD=your_password +SIGNING_KEY=your_signing_key +SIGNING_KEY_ID=your_key_id +SIGNING_PASSWORD=your_signing_password +``` + +--- + +### Kobweb Resources + +**ID:** `ru.astrainteractive.gradleplugin.js.kobweb.resources` + +Manages JavaScript resources copying for [Kobweb](https://kobweb.varabyte.com/) applications. + +```kotlin +plugins { + alias(libs.plugins.klibs.gradle.js.kobweb.resources) +} + +jsResources { + projectsPaths = listOf(":shared", ":frontend") +} +``` + +- Creates `jsResources` extension with `projectsPaths` configuration +- Registers `copyJsResources` task copying from `src/jsMain/resources/public` of referenced projects +- Wires Kobweb tasks (`KobwebStartTask`, `KobwebGenerateSiteIndexTask`, etc.) to depend on `copyJsResources` + +--- + +### Webpack No Source Maps + +**ID:** `ru.astrainteractive.gradleplugin.js.webpack.nosourcemaps` + +Disables source maps in Kotlin/JS Webpack builds. + +```kotlin +plugins { + alias(libs.plugins.klibs.gradle.js.webpack.nosourcemaps) +} ``` -### Base64 Secret plugin +- Sets `sourceMaps = false` for all `KotlinWebpack` tasks + +--- + +## Tasks + +### SecretFileTask -This task will generate secret file from secret base64. Useful for `android.keystore` or `google-services.json` +A custom task that decodes a Base64 string into a file. Useful for secrets like `keystore.jks` or `google-services.json` in CI/CD. ```kotlin -tasks.register("YOUR_TASK_NAME") { - targetFile = file("YOUR_TARGET_FILE.txt") - base64 = secretProperty("YOUR_KEY").requireString +tasks.register("generateKeystore") { + targetFile.set(file("keystore.jks")) + base64.set(secretProperty("KEYSTORE_BASE64").requireString) } -``` \ No newline at end of file +``` + + + +For custom property access, `PropertyValue` extensions, and caching details, see [Property Module](property.md). diff --git a/docs/index.md b/docs/index.md index d2ae182..f4a0670 100644 --- a/docs/index.md +++ b/docs/index.md @@ -1,6 +1,6 @@ # Gradle Plugin Suite -This repository contains a collection of useful Gradle plugins +A modular collection of Gradle plugins for Kotlin projects. --- @@ -9,12 +9,10 @@ This repository contains a collection of useful Gradle plugins This **Gradle Plugin suite** is a modular build-logic plugins library for Kotlin projects. Instead of having one monolithic plugin, it's split into sub-plugins to provide focused functionality: -- `convention` - basic utilities for any gradle-related project -- `android` - plugins and tasks for Android projects -- `minecraft` - plugins and tasks related for Minecraft development - -This modular structure allows you to pick and use only the parts of the plugin you need, keeping your builds clean and -focused. +- `property` - property management system for `gradle.properties`, `local.properties`, and environment variables +- `convention` - core plugins for Java, Kotlin, Detekt, Dokka, publication, and more +- `android` - plugins for Android SDK, Compose, APK signing, namespacing +- `minecraft` - resource processor for Bukkit, Fabric, Forge, and Velocity --- @@ -22,31 +20,50 @@ focused. ### Define required plugins -In your `libs.version.toml` +In your `libs.versions.toml` ```toml [versions] -# klibs klibs-gradleplugin = "" [plugins] # Core klibs-gradle-detekt = { id = "ru.astrainteractive.gradleplugin.detekt", version.ref = "klibs-gradleplugin" } -klibs-gradle-detekt-compose = { id = "ru.astrainteractive.gradleplugin.detekt.compose", version.ref = "klibs-gradleplugin" } klibs-gradle-dokka-module = { id = "ru.astrainteractive.gradleplugin.dokka.module", version.ref = "klibs-gradleplugin" } klibs-gradle-dokka-root = { id = "ru.astrainteractive.gradleplugin.dokka.root", version.ref = "klibs-gradleplugin" } klibs-gradle-java-version = { id = "ru.astrainteractive.gradleplugin.java.version", version.ref = "klibs-gradleplugin" } klibs-gradle-java-utf8 = { id = "ru.astrainteractive.gradleplugin.java.utf8", version.ref = "klibs-gradleplugin" } -klibs-gradle-rootinfo = { id = "ru.astrainteractive.gradleplugin.root.info", version.ref = "klibs-gradleplugin" } +klibs-gradle-rootinfo = { id = "ru.astrainteractive.gradleplugin.rootinfo", version.ref = "klibs-gradleplugin" } klibs-gradle-publication = { id = "ru.astrainteractive.gradleplugin.publication", version.ref = "klibs-gradleplugin" } +# JavaScript +klibs-gradle-js-kobweb-resources = { id = "ru.astrainteractive.gradleplugin.js.kobweb.resources", version.ref = "klibs-gradleplugin" } +klibs-gradle-js-webpack-nosourcemaps = { id = "ru.astrainteractive.gradleplugin.js.webpack.nosourcemaps", version.ref = "klibs-gradleplugin" } +# Minecraft +klibs-gradle-minecraft-resource-processor = { id = "ru.astrainteractive.gradleplugin.minecraft.resource.processor", version.ref = "klibs-gradleplugin" } # Android +klibs-gradle-android-java = { id = "ru.astrainteractive.gradleplugin.android.java", version.ref = "klibs-gradleplugin" } klibs-gradle-android-sdk = { id = "ru.astrainteractive.gradleplugin.android.sdk", version.ref = "klibs-gradleplugin" } klibs-gradle-android-namespace = { id = "ru.astrainteractive.gradleplugin.android.namespace", version.ref = "klibs-gradleplugin" } klibs-gradle-android-compose = { id = "ru.astrainteractive.gradleplugin.android.compose", version.ref = "klibs-gradleplugin" } klibs-gradle-android-apk-sign = { id = "ru.astrainteractive.gradleplugin.android.apk.sign", version.ref = "klibs-gradleplugin" } klibs-gradle-android-apk-name = { id = "ru.astrainteractive.gradleplugin.android.apk.name", version.ref = "klibs-gradleplugin" } -# Minecrat -klibs-gradle-minecraft-resource-processor = { id = "ru.astrainteractive.gradleplugin.minecraft.resource-processor", version.ref = "klibs-gradleplugin" } +``` + +### Configure your `gradle.properties` + +```properties +# Java +klibs.java.source=11 +klibs.java.target=11 +klibs.java.ktarget=11 + +# Project +klibs.project.name=MyProject +klibs.project.group=com.example.project +klibs.project.version.string=1.0.0 +klibs.project.description=My project description +klibs.project.url=https://github.com/username/project +klibs.project.developers=username|Full Name|email@example.com ``` ### Setup your gradle plugins @@ -57,21 +74,32 @@ Your root `build.gradle.kts` plugins { // klibs - core alias(libs.plugins.klibs.gradle.detekt) apply false - alias(libs.plugins.klibs.gradle.detekt.compose) apply false alias(libs.plugins.klibs.gradle.dokka.module) apply false alias(libs.plugins.klibs.gradle.dokka.root) apply false alias(libs.plugins.klibs.gradle.java.version) apply false alias(libs.plugins.klibs.gradle.java.utf8) apply false alias(libs.plugins.klibs.gradle.rootinfo) apply false alias(libs.plugins.klibs.gradle.publication) apply false + // klibs - javascript + alias(libs.plugins.klibs.gradle.js.kobweb.resources) apply false + alias(libs.plugins.klibs.gradle.js.webpack.nosourcemaps) apply false + // klibs - minecraft + alias(libs.plugins.klibs.gradle.minecraft.resource.processor) apply false // klibs - android + alias(libs.plugins.klibs.gradle.android.java) apply false alias(libs.plugins.klibs.gradle.android.sdk) apply false alias(libs.plugins.klibs.gradle.android.namespace) apply false alias(libs.plugins.klibs.gradle.android.compose) apply false alias(libs.plugins.klibs.gradle.android.apk.sign) apply false alias(libs.plugins.klibs.gradle.android.apk.name) apply false - // klibs - minecraft - alias(libs.plugins.klibs.gradle.minecraft.resource.processor) apply false } ``` +--- + +## Documentation + +- [Convention Module](convention.md) - Core plugins, properties reference, tasks, and custom property access +- [Android Plugins](android.md) - Android SDK, Compose, signing, namespace, and APK naming plugins +- [Minecraft Plugins](minecraft.md) - Resource processor for Bukkit, Fabric, Forge, and Velocity +- [Property Module](property.md) - Property management system (`PropertyValue`, lookup order, caching) diff --git a/docs/minecraft.md b/docs/minecraft.md index a151ae3..545f670 100644 --- a/docs/minecraft.md +++ b/docs/minecraft.md @@ -1,17 +1,40 @@ -### Minecraft plugins +## Minecraft Plugins -*Some functionality may be dependent on [convention.md](convention.md)* +*Depends on properties defined in [convention.md](convention.md)* -### Setup resource processor +--- -In your `build.gradle.kts` +### Minecraft Resource Processor + +**ID:** `ru.astrainteractive.gradleplugin.minecraft.resource.processor` + +Provides a `minecraftProcessResource` DSL extension for processing Minecraft mod resource files. Automatically expands template variables (name, version, description, etc.) from `ProjectInfo` into resource files during build. ```kotlin plugins { alias(libs.plugins.klibs.gradle.minecraft.resource.processor) } -// Let's imagine, you need to provide custom libraries in your properties +minecraftProcessResource { + // Bukkit/Spigot/Paper - processes plugin.yml + bukkit() + + // Fabric - processes fabric.mod.json + fabric() + + // Forge - processes META-INF/mods.toml + forge() + + // Velocity - processes velocity-plugin.json + velocity() +} +``` + +### Custom properties + +Each platform function accepts a `customProperties` map that merges with the defaults: + +```kotlin minecraftProcessResource { bukkit( customProperties = mapOf( @@ -22,11 +45,17 @@ minecraftProcessResource { ).joinToString("\",\"", "[\"", "\"]") ) ) - // The same can be done for Fabric - fabric() - // Forge - forge() - // And Velocity - velocity() -} -``` \ No newline at end of file +} +``` + +### Default template variables + +**Bukkit** (`plugin.yml`): `main`, `name`, `prefix`, `version`, `description`, `url`, `author`, `authors`, `libraries` + +**Velocity** (`velocity-plugin.json`): `id`, `name`, `version`, `url`, `authors`, `main` + +**Fabric** (`fabric.mod.json`): `version` + +**Forge** (`META-INF/mods.toml`): `modId`, `version`, `description`, `displayName`, `authors` + +All values are derived from `ProjectInfo` properties (`klibs.project.*`). diff --git a/docs/property.md b/docs/property.md new file mode 100644 index 0000000..05a4f13 --- /dev/null +++ b/docs/property.md @@ -0,0 +1,115 @@ +## Property Module + +The `property` module provides a flexible property management system for accessing configuration values from `gradle.properties`, `local.properties`, and environment variables. + +--- + +## PropertyValue Interface + +All property access methods return a `PropertyValue`: + +```kotlin +interface PropertyValue { + val key: String + fun getValue(): Result +} +``` + +--- + +## Accessing Properties + +### Gradle Property (with `klibs.` prefix) + +Prepends `klibs.` to the path. Lookup order: `local.properties` -> `gradle.properties` -> Gradle providers. + +```kotlin +val property: PropertyValue = project.klibsGradleProperty("project.name") +// Resolves key: klibs.project.name +``` + +### Gradle Property (raw key) + +Uses the key as-is. Same lookup order. + +```kotlin +val property: PropertyValue = project.gradleProperty("some.custom.key") +// Resolves key: some.custom.key +``` + +### Secret Property (with `klibs.` prefix) + +Prepends `klibs.` to the path. Lookup order: environment variable -> `local.properties`. + +```kotlin +val secret: PropertyValue = project.klibsSecretProperty("KEY_PASSWORD") +// Resolves key: klibs.KEY_PASSWORD +// Environment variable: klibs_KEY_PASSWORD (dots replaced with underscores) +``` + +### Secret Property (raw key) + +Uses the key as-is. Same lookup order. + +```kotlin +val secret: PropertyValue = project.secretProperty("CUSTOM_SECRET") +// Resolves key: CUSTOM_SECRET +``` + +> **Environment variables:** Since `System.getenv` doesn't support dots, all `.` in the key are replaced with `_` when looking up environment variables. + +--- + +## PropertyValue Extensions + +### String + +```kotlin +property.stringOrNull // String? - null if not found +property.stringOrEmpty // String - empty string if not found +property.requireString // String - throws if not found +``` + +### Integer + +```kotlin +property.intOrNull // Int? - null if not found or not parseable +property.requireInt // Int - throws if not found +``` + +### JavaVersion / JvmTarget + +```kotlin +property.requireJavaVersion // JavaVersion - throws if not found +property.requireJvmTarget // JvmTarget - throws if not found +``` + +--- + +## Caching + +Properties can be cached per-project using `asCached`: + +```kotlin +val cached: PropertyValue = property.asCached(project.extensions) +``` + +This stores the resolved value in the project's `ExtensionContainer` to avoid repeated file lookups. Values are cached per key - including "not found" results. + +--- + +## Property File Lookup + +Both `local.properties` and `gradle.properties` are resolved by walking up the project hierarchy: + +1. Check current project directory +2. Check parent project directory +3. Check root project directory + +This means a single `gradle.properties` at the root is sufficient for all subprojects. Symbolic links are supported. + +--- + +## Integration with Convention Module + +The `property` module is used by the `convention` module to provide typed property models. See [Convention Module](convention.md) for the full list of `klibs.*` property keys and pre-defined models like `JInfo`, `ProjectInfo`, `PublishInfo`, and `AndroidSdkInfo`. diff --git a/gradle.properties b/gradle.properties index ec5bf56..77ff114 100644 --- a/gradle.properties +++ b/gradle.properties @@ -8,4 +8,4 @@ project.name=GradlePlugin project.description=GradlePlugin for my kotlin projects project.group=ru.astrainteractive.gradleplugin project.web=https://github.com/makeevrserg/gradle-plugin -project.version.string=1.15.0 +project.version.string=2.0.0 diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 4e733d8..8062bbc 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -1,7 +1,8 @@ [versions] -agp = "9.0.0" +agp = "9.1.0" detekt = "2.0.0-alpha.2" # https://detekt.dev/docs/gettingstarted/gradle/ -dokka = "2.1.0" +dokka = "2.2.0" +kobweb = "0.24.0" # https://github.com/varabyte/kobweb kotlin = "2.3.20" vaniktech = "0.35.0" @@ -11,6 +12,7 @@ detekt-gradle = { module = "dev.detekt:detekt-gradle-plugin", version.ref = "det dokka-base = { module = "org.jetbrains.dokka:dokka-base", version.ref = "dokka" } dokka-core = { module = "org.jetbrains.dokka:dokka-core", version.ref = "dokka" } dokka-gradle = { module = "org.jetbrains.dokka:dokka-gradle-plugin", version.ref = "dokka" } +kobweb-gradle = { module = "com.varabyte.kobweb.gradle:application", version.ref = "kobweb" } kotlin-gradle = { module = "org.jetbrains.kotlin:kotlin-gradle-plugin", version.ref = "kotlin" } vaniktech = { module = "com.vanniktech:gradle-maven-publish-plugin", version.ref = "vaniktech" }