├── .editorconfig ├── .gitignore ├── .idea ├── codeStyles │ └── codeStyleConfig.xml ├── icon.png ├── inspectionProfiles │ └── Project_Default.xml ├── kotlinc.xml ├── ktlint-plugin.xml ├── ktlint.xml ├── markdown.xml └── vcs.xml ├── LICENSE ├── README-zh-CN.md ├── README.md ├── build.gradle.kts ├── docs ├── changelog-zh-CN.md ├── changelog.md ├── guide-zh-CN.md └── guide.md ├── gradle.properties ├── gradle ├── sweet-dependency │ └── sweet-dependency-config.yaml └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── img-src └── icon.png ├── samples ├── sample-android │ ├── .gitignore │ ├── build.gradle.kts │ ├── demo-app │ │ ├── .gitignore │ │ ├── build.gradle.kts │ │ ├── proguard-rules.pro │ │ └── src │ │ │ ├── androidTest │ │ │ └── java │ │ │ │ └── com │ │ │ │ └── highcapable │ │ │ │ └── sweetdependency │ │ │ │ └── demo_app │ │ │ │ └── ExampleInstrumentedTest.kt │ │ │ ├── main │ │ │ ├── AndroidManifest.xml │ │ │ ├── java │ │ │ │ └── com │ │ │ │ │ └── highcapable │ │ │ │ │ └── sweetdependency │ │ │ │ │ └── demo_app │ │ │ │ │ └── MainActivity.kt │ │ │ └── res │ │ │ │ ├── drawable-v24 │ │ │ │ └── ic_launcher_foreground.xml │ │ │ │ ├── drawable │ │ │ │ └── ic_launcher_background.xml │ │ │ │ ├── layout │ │ │ │ └── activity_main.xml │ │ │ │ ├── mipmap-anydpi-v26 │ │ │ │ ├── ic_launcher.xml │ │ │ │ └── ic_launcher_round.xml │ │ │ │ ├── mipmap-anydpi-v33 │ │ │ │ └── ic_launcher.xml │ │ │ │ ├── mipmap-hdpi │ │ │ │ ├── ic_launcher.webp │ │ │ │ └── ic_launcher_round.webp │ │ │ │ ├── mipmap-mdpi │ │ │ │ ├── ic_launcher.webp │ │ │ │ └── ic_launcher_round.webp │ │ │ │ ├── mipmap-xhdpi │ │ │ │ ├── ic_launcher.webp │ │ │ │ └── ic_launcher_round.webp │ │ │ │ ├── mipmap-xxhdpi │ │ │ │ ├── ic_launcher.webp │ │ │ │ └── ic_launcher_round.webp │ │ │ │ ├── mipmap-xxxhdpi │ │ │ │ ├── ic_launcher.webp │ │ │ │ └── ic_launcher_round.webp │ │ │ │ ├── values-night │ │ │ │ └── themes.xml │ │ │ │ ├── values │ │ │ │ ├── colors.xml │ │ │ │ ├── strings.xml │ │ │ │ └── themes.xml │ │ │ │ └── xml │ │ │ │ ├── backup_rules.xml │ │ │ │ └── data_extraction_rules.xml │ │ │ └── test │ │ │ └── java │ │ │ └── com │ │ │ └── highcapable │ │ │ └── sweetdependency │ │ │ └── demo_app │ │ │ └── ExampleUnitTest.kt │ ├── demo-library │ │ ├── .gitignore │ │ ├── build.gradle.kts │ │ ├── consumer-rules.pro │ │ ├── proguard-rules.pro │ │ └── src │ │ │ ├── androidTest │ │ │ └── java │ │ │ │ └── com │ │ │ │ └── highcapable │ │ │ │ └── sweetdependency │ │ │ │ └── demo_library │ │ │ │ └── ExampleInstrumentedTest.kt │ │ │ ├── main │ │ │ ├── AndroidManifest.xml │ │ │ └── java │ │ │ │ └── com │ │ │ │ └── highcapable │ │ │ │ └── sweetdependency │ │ │ │ └── demo_library │ │ │ │ └── DemoLibrary.kt │ │ │ └── test │ │ │ └── java │ │ │ └── com │ │ │ └── highcapable │ │ │ └── sweetdependency │ │ │ └── demo_library │ │ │ └── ExampleUnitTest.kt │ ├── gradle.properties │ ├── gradle │ │ ├── sweet-dependency │ │ │ └── sweet-dependency-config.yaml │ │ └── wrapper │ │ │ ├── gradle-wrapper.jar │ │ │ └── gradle-wrapper.properties │ ├── gradlew │ ├── gradlew.bat │ └── settings.gradle.kts └── sample-jvm │ ├── .gitignore │ ├── build.gradle.kts │ ├── gradle.properties │ ├── gradle │ ├── sweet-dependency │ │ └── sweet-dependency-config.yaml │ └── wrapper │ │ ├── gradle-wrapper.jar │ │ └── gradle-wrapper.properties │ ├── gradlew │ ├── gradlew.bat │ ├── sample-jvm │ ├── build.gradle.kts │ └── src │ │ └── main │ │ └── kotlin │ │ └── com │ │ └── highcapable │ │ └── sweetdependency │ │ └── demo_jvm │ │ └── Main.kt │ └── settings.gradle.kts ├── settings.gradle.kts └── sweetdependency-gradle-plugin ├── build.gradle.kts └── src └── main └── java ├── com └── highcapable │ └── sweetdependency │ ├── SweetDependency.kt │ ├── document │ ├── DependencyDocument.kt │ ├── PreferencesDocument.kt │ ├── RepositoryDocument.kt │ ├── RootConfigDocument.kt │ ├── VersionFilterDocument.kt │ ├── factory │ │ └── DocumentFactory.kt │ └── mapping │ │ ├── RootConfigDocumentMapping.kt │ │ └── entity │ │ └── DependencyMapping.kt │ ├── environment │ └── Environment.kt │ ├── exception │ └── SweetDependencyUnresolvedException.kt │ ├── gradle │ ├── delegate │ │ ├── GradleDelegate.kt │ │ ├── ProjectTransaction.kt │ │ └── entity │ │ │ └── ExternalDependencyDelegate.kt │ ├── entity │ │ ├── DependencyName.kt │ │ ├── DependencyUpdateMode.kt │ │ ├── DependencyVersion.kt │ │ └── ExternalDependency.kt │ ├── factory │ │ ├── ExtensionAwareFactory.kt │ │ └── GradleProjectFactory.kt │ ├── helper │ │ └── GradleHelper.kt │ ├── proxy │ │ └── IGradleLifecycle.kt │ └── wrapper │ │ ├── LibraryDependencyWrapper.kt │ │ ├── PluginDependencyWrapper.kt │ │ └── type │ │ └── LibraryDependencyType.kt │ ├── manager │ ├── DependencyManager.kt │ ├── GradleTaskManager.kt │ ├── RepositoryManager.kt │ ├── const │ │ ├── AdditionalRepositories.kt │ │ └── InternalRepositories.kt │ ├── content │ │ ├── Dependencies.kt │ │ └── Repositories.kt │ ├── helper │ │ ├── DependencyAutowireLogHelper.kt │ │ └── DependencyDeployHelper.kt │ ├── maven │ │ ├── MavenParser.kt │ │ └── entity │ │ │ └── MavenMetadata.kt │ └── transaction │ │ ├── DependencyMigrationTemplateTransaction.kt │ │ └── RuntimeDebugTransaction.kt │ ├── plugin │ ├── SweetDependencyExtension.kt │ ├── SweetDependencyPlugin.kt │ ├── config │ │ ├── content │ │ │ └── SweetDependencyConfigs.kt │ │ ├── factory │ │ │ └── SweetDependencyConfigsFactory.kt │ │ └── proxy │ │ │ └── ISweetDependencyConfigs.kt │ ├── extension │ │ ├── accessors │ │ │ └── proxy │ │ │ │ └── IExtensionAccessors.kt │ │ └── dsl │ │ │ ├── configure │ │ │ └── SweetDependencyConfigureExtension.kt │ │ │ └── manager │ │ │ └── SweetDependencyAutowireExtension.kt │ ├── generator │ │ └── LibrariesAccessorsGenerator.kt │ ├── helper │ │ └── PluginUpdateHelper.kt │ ├── impl │ │ ├── SweetDependencyExtensionImpl.kt │ │ └── base │ │ │ └── BaseExtensionImpl.kt │ └── task │ │ ├── AutowireDependenciesTask.kt │ │ ├── AutowireLibrariesTask.kt │ │ ├── AutowirePluginsTask.kt │ │ ├── CreateDependenciesMigrationTemplateTask.kt │ │ ├── SweetDependencyDebugTask.kt │ │ ├── UpdateAllDependenciesTask.kt │ │ ├── UpdateAllLibrariesTask.kt │ │ ├── UpdateAllPluginsTask.kt │ │ ├── UpdateOptionalDependenciesTask.kt │ │ ├── UpdateOptionalLibrariesTask.kt │ │ ├── UpdateOptionalPluginsTask.kt │ │ └── base │ │ └── BaseTask.kt │ └── utils │ ├── FileFactory.kt │ ├── HttpFactory.kt │ ├── ThreadPoolFactory.kt │ ├── ThrowableFactory.kt │ ├── VariableFactory.kt │ ├── code │ ├── CodeCompiler.kt │ ├── entity │ │ └── MavenPomData.kt │ └── factory │ │ └── CodeCompilerFactory.kt │ ├── debug │ ├── SError.kt │ └── SLog.kt │ └── yaml │ ├── Yaml.kt │ ├── factory │ └── YamlFactory.kt │ └── proxy │ └── IYamlDocument.kt └── org └── gradle └── kotlin └── dsl ├── SweetDependencyProjectExtensionFactory.kt └── SweetDependencySettingsExtensionFactory.kt /.editorconfig: -------------------------------------------------------------------------------- 1 | # noinspection EditorConfigKeyCorrectness 2 | [{*.kt,*.kts}] 3 | ktlint_standard_annotation = disabled 4 | ktlint_standard_filename = disabled 5 | ktlint_standard_wrapping = disabled 6 | ktlint_standard_import-ordering = enabled 7 | ktlint_standard_max-line-length = disabled 8 | ktlint_standard_multiline-if-else = disabled 9 | ktlint_standard_argument-list-wrapping = disabled 10 | ktlint_standard_parameter-list-wrapping = disabled 11 | ktlint_standard_trailing-comma-on-declaration-site = disabled 12 | ktlint_function_signature_body_expression_wrapping = multiline 13 | ktlint_standard_string-template-indent = disabled 14 | ktlint_standard_function-signature = disabled 15 | ktlint_standard_trailing-comma-on-call-site = disabled 16 | ktlint_standard_multiline-expression-wrapping = disabled 17 | ktlint_standard_no-empty-first-line-in-class-body = disabled 18 | ktlint_standard_if-else-wrapping = disabled 19 | ktlint_standard_if-else-bracing = disabled 20 | ktlint_standard_statement-wrapping = disabled 21 | ktlint_standard_blank-line-before-declaration = disabled 22 | ktlint_standard_no-empty-file = disabled 23 | ktlint_standard_property-naming = disabled 24 | ktlint_standard_function-naming = disabled 25 | ktlint_standard_chain-method-continuation = disabled 26 | ktlint_standard_class-signature = disabled 27 | ktlint_standard_condition-wrapping = disabled 28 | ktlint_standard_class-signature = disabled 29 | ktlint_standard_no-trailing-spaces = disabled 30 | ktlint_standard_multiline-loop = disabled 31 | ij_continuation_indent_size = 2 32 | indent_size = 4 33 | indent_style = space 34 | insert_final_newline = false 35 | max_line_length = 150 -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ## Fully .gtignore for IntelliJ, Android Studio and Gradle based Java projects 2 | ## References: 3 | ## - https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore 4 | ## - https://github.com/android/platform-samples/blob/main/.gitignore 5 | 6 | # User-specific stuff 7 | .idea/**/workspace.xml 8 | .idea/**/tasks.xml 9 | .idea/**/usage.statistics.xml 10 | .idea/**/dictionaries 11 | .idea/**/shelf 12 | 13 | # AWS User-specific 14 | .idea/**/aws.xml 15 | 16 | # Generated files 17 | .idea/**/contentModel.xml 18 | 19 | # Sensitive or high-churn files 20 | .idea/**/dataSources/ 21 | .idea/**/dataSources.ids 22 | .idea/**/dataSources.local.xml 23 | .idea/**/sqlDataSources.xml 24 | .idea/**/dynamic.xml 25 | .idea/**/uiDesigner.xml 26 | .idea/**/dbnavigator.xml 27 | 28 | # Gradle 29 | .idea/**/gradle.xml 30 | .idea/**/libraries 31 | 32 | # Gradle and Maven with auto-import 33 | .idea/.name 34 | .idea/artifacts 35 | .idea/compiler.xml 36 | .idea/jarRepositories.xml 37 | .idea/modules.xml 38 | .idea/*.iml 39 | .idea/modules 40 | .idea/caches 41 | .idea/material_theme** 42 | .idea/other.xml 43 | *.iml 44 | *.ipr 45 | 46 | # Kotlin 47 | .kotlin 48 | 49 | # Misc 50 | .idea/misc.xml 51 | 52 | # CMake 53 | cmake-build-*/ 54 | 55 | # Mongo Explorer plugin 56 | .idea/**/mongoSettings.xml 57 | 58 | # File-based project format 59 | *.iws 60 | 61 | # IntelliJ 62 | out/ 63 | 64 | # mpeltonen/sbt-idea plugin 65 | .idea_modules/ 66 | 67 | # JIRA plugin 68 | atlassian-ide-plugin.xml 69 | 70 | # Cursive Clojure plugin 71 | .idea/replstate.xml 72 | 73 | # SonarLint plugin 74 | .idea/sonarlint/ 75 | 76 | # Crashlytics plugin (for Android Studio and IntelliJ) 77 | com_crashlytics_export_strings.xml 78 | crashlytics.properties 79 | crashlytics-build.properties 80 | fabric.properties 81 | 82 | # Editor-based Rest Client 83 | .idea/httpRequests 84 | 85 | # Android studio 3.1+ serialized cache file 86 | .idea/caches/build_file_checksums.ser 87 | 88 | # Android studio 3.1+ additional 89 | .idea/deployment*.xml 90 | .idea/assetWizardSettings.xml 91 | .idea/androidTestResultsUserPreferences.xml 92 | 93 | # Android projects 94 | **/local.properties 95 | /captures 96 | .externalNativeBuild 97 | .cxx 98 | 99 | # Gradle projects 100 | .gradle 101 | build/ 102 | 103 | # Mkdocs temporary serving folder 104 | docs-gen 105 | site 106 | *.bak 107 | .idea/appInsightsSettings.xml 108 | 109 | # Mac OS 110 | .DS_Store -------------------------------------------------------------------------------- /.idea/codeStyles/codeStyleConfig.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | -------------------------------------------------------------------------------- /.idea/icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HighCapable/SweetDependency/bfb97905cc3bcd0e72bed2f75f48eab4a413327d/.idea/icon.png -------------------------------------------------------------------------------- /.idea/inspectionProfiles/Project_Default.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 15 | -------------------------------------------------------------------------------- /.idea/kotlinc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 6 | -------------------------------------------------------------------------------- /.idea/ktlint-plugin.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | MANUAL 5 | false 6 | 7 | -------------------------------------------------------------------------------- /.idea/ktlint.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | false 5 | 6 | -------------------------------------------------------------------------------- /.idea/markdown.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 6 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /README-zh-CN.md: -------------------------------------------------------------------------------- 1 | # Sweet Dependency 2 | 3 | [![GitHub license](https://img.shields.io/github/license/HighCapable/SweetDependency?color=blue)](https://github.com/HighCapable/SweetDependency/blob/master/LICENSE) 4 | [![GitHub release](https://img.shields.io/github/v/release/HighCapable/SweetDependency?display_name=release&logo=github&color=green)](https://github.com/HighCapable/SweetDependency/releases) 5 | [![Telegram](https://img.shields.io/badge/discussion-Telegram-blue.svg?logo=telegram)](https://t.me/HighCapable_Dev) 6 | [![QQ](https://img.shields.io/badge/discussion-QQ-blue.svg?logo=tencent-qq&logoColor=red)](https://qm.qq.com/cgi-bin/qm/qr?k=Pnsc5RY6N2mBKFjOLPiYldbAbprAU3V7&jump_from=webapi&authKey=X5EsOVzLXt1dRunge8ryTxDRrh9/IiW1Pua75eDLh9RE3KXE+bwXIYF5cWri/9lf) 7 | 8 | LOGO 9 | 10 | 一个轻松自动装配和管理依赖的 Gradle 插件。 11 | 12 | [English](README.md) | 简体中文 13 | 14 | | LOGO | [HighCapable](https://github.com/HighCapable) | 15 | |-------------------------------------------------------------------------------------------------------------------------------|-----------------------------------------------| 16 | 17 | 这个项目属于上述组织,**点击上方链接关注这个组织**,发现更多好项目。 18 | 19 | ## 这是什么 20 | 21 | 这是一个用来管理 Gradle 依赖的 Gradle 插件,所有依赖集中管理并自动更新,解决了每个子项目都需要手动更新到相同版本依赖的问题。 22 | 23 | 虽然 Gradle 后期推出了 Version Catalogs 来管理依赖,但是它的方式依然不够自由和人性化,且存在限制。 24 | 25 | 不同于传统的依赖管理方式,`SweetDependency` 采用 YAML 进行动态配置,可读性相对较高,配置过程简单且易用。 26 | 27 | ## 兼容性 28 | 29 | 不仅仅是 Android 项目,任何使用 Gradle 作为构建工具的项目都可以使用。 30 | 31 | 目前暂时只有 Gradle 插件,IDEA 的相关插件还在计划开发中,预计将会支持配置文件的语法检查和将配置文件显示在 Android 项目的 Gradle 文件列表中。 32 | 33 | 支持 Gradle `7.x.x` 和 `8.x.x`,其它版本未做测试并不推荐使用。 34 | 35 | > 构建脚本语言 36 | 37 | - Kotlin DSL 38 | 39 | 推荐优先使用此语言作为构建脚本语言,这也是目前 Gradle 推荐的语言。 40 | 41 | - Groovy DSL 42 | 43 | 部分功能可能无法兼容,在后期会逐渐放弃支持,且部分功能会无法使用。 44 | 45 | > 相关功能列表 46 | 47 | 部分功能将跟随后期用户需求逐渐完善。 48 | 49 | - [x] 支持 Kotlin Multiplatform 50 | 51 | - [x] 管理 Gradle 插件依赖 52 | 53 | - [x] 管理 Gradle 库依赖 54 | 55 | - [x] 自动装配 Maven 依赖 (POM、BOM) 56 | 57 | - [ ] 自动装配 Ivy 依赖 58 | 59 | ## 开始使用 60 | 61 | - [点击这里](docs/guide-zh-CN.md) 查看使用文档 62 | 63 | ## 更新日志 64 | 65 | - [点击这里](docs/changelog-zh-CN.md) 查看历史更新日志 66 | 67 | ## 项目推广 68 | 69 | 如果你正在寻找一个可以自动生成属性键值的 Gradle 插件,你可以了解一下 [SweetProperty](https://github.com/HighCapable/SweetProperty) 项目。 70 | 71 | 本项目同样使用了 **SweetProperty**。 72 | 73 | 74 |
75 |

嘿,还请君留步!👋

76 |

这里有 Android 开发工具、UI 设计、Gradle 插件、Xposed 模块和实用软件等相关项目。

77 |

如果下方的项目能为你提供帮助,不妨为我点个 star 吧!

78 |

所有项目免费、开源,遵循对应开源许可协议。

79 |

→ 查看更多关于我的项目,请点击这里 ←

80 |
81 | 82 | ## Star History 83 | 84 | ![Star History Chart](https://api.star-history.com/svg?repos=HighCapable/SweetDependency&type=Date) 85 | 86 | ## 许可证 87 | 88 | - [Apache-2.0](https://www.apache.org/licenses/LICENSE-2.0) 89 | 90 | ``` 91 | Apache License Version 2.0 92 | 93 | Copyright (C) 2019 HighCapable 94 | 95 | Licensed under the Apache License, Version 2.0 (the "License"); 96 | you may not use this file except in compliance with the License. 97 | You may obtain a copy of the License at 98 | 99 | https://www.apache.org/licenses/LICENSE-2.0 100 | 101 | Unless required by applicable law or agreed to in writing, software 102 | distributed under the License is distributed on an "AS IS" BASIS, 103 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 104 | See the License for the specific language governing permissions and 105 | limitations under the License. 106 | ``` 107 | 108 | 版权所有 © 2019 HighCapable -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Sweet Dependency 2 | 3 | [![GitHub license](https://img.shields.io/github/license/HighCapable/SweetDependency?color=blue)](https://github.com/HighCapable/SweetDependency/blob/master/LICENSE) 4 | [![GitHub release](https://img.shields.io/github/v/release/HighCapable/SweetDependency?display_name=release&logo=github&color=green)](https://github.com/HighCapable/SweetDependency/releases) 5 | [![Telegram](https://img.shields.io/badge/discussion-Telegram-blue.svg?logo=telegram)](https://t.me/HighCapable_Dev) 6 | [![QQ](https://img.shields.io/badge/discussion-QQ-blue.svg?logo=tencent-qq&logoColor=red)](https://qm.qq.com/cgi-bin/qm/qr?k=Pnsc5RY6N2mBKFjOLPiYldbAbprAU3V7&jump_from=webapi&authKey=X5EsOVzLXt1dRunge8ryTxDRrh9/IiW1Pua75eDLh9RE3KXE+bwXIYF5cWri/9lf) 7 | 8 | LOGO 9 | 10 | An easy autowire and manage dependencies Gradle plugin. 11 | 12 | English | [简体中文](README-zh-CN.md) 13 | 14 | | LOGO | [HighCapable](https://github.com/HighCapable) | 15 | |-------------------------------------------------------------------------------------------------------------------------------|-----------------------------------------------| 16 | 17 | This project belongs to the above-mentioned organization, **click the link above to follow this organization** and discover more good projects. 18 | 19 | ## What's this 20 | 21 | This is a Gradle plugin for managing Gradle dependencies. 22 | 23 | Although Gradle later launched the Version Catalogs to manage dependencies, its method is still not free and user-friendly, and has limitations. 24 | 25 | Different from traditional dependency management methods, `SweetDependency` uses YAML for dynamic configuration, 26 | which is relatively readable, and the configuration process is simple and easy to use. 27 | 28 | ## Compatibility 29 | 30 | Not just Android projects, any project that uses Gradle as a build tool will work. 31 | 32 | Currently there is only Gradle plugin, IDEA related plugins are still under development, 33 | support for syntax checking of configuration file and displaying configuration file in the Android project's Gradle files list is expected. 34 | 35 | Gradle `7.x.x` and `8.x.x` are supported, other versions have not been tested and are not recommended. 36 | 37 | > Build Script Language 38 | 39 | - Kotlin DSL 40 | 41 | It is recommended to use this language as the build script language first, which is also the language currently recommended by Gradle. 42 | 43 | - Groovy DSL 44 | 45 | Some functions may be incompatible, support will be gradually dropped in the future, and some functions may become unavailable. 46 | 47 | > Related Feature List 48 | 49 | Some functions will be gradually improved following the needs of users. 50 | 51 | - [x] Support Kotlin Multiplatform 52 | 53 | - [x] Manage Gradle dependencies (plugins) 54 | 55 | - [x] Manage Gradle dependencies (libraries) 56 | 57 | - [x] Autowire Maven dependencies (POM, BOM) 58 | 59 | - [ ] Autowire Ivy dependencies 60 | 61 | ## Get Started 62 | 63 | - [Click here](docs/guide.md) to view the documentation 64 | 65 | ## Changelog 66 | 67 | - [Click here](docs/changelog.md) to view the historical changelog 68 | 69 | ## Promotion 70 | 71 | If you are looking for a Gradle plugin that can automatically generate properties key-values, 72 | you can check out the [SweetProperty](https://github.com/HighCapable/SweetProperty) project. 73 | 74 | This project also uses **SweetProperty**. 75 | 76 | 77 |
78 |

Hey, please stay! 👋

79 |

Here are related projects such as Android development tools, UI design, Gradle plugins, Xposed Modules and practical software.

80 |

If the project below can help you, please give me a star!

81 |

All projects are free, open source, and follow the corresponding open source license agreement.

82 |

→ To see more about my projects, please click here ←

83 |
84 | 85 | ## Star History 86 | 87 | ![Star History Chart](https://api.star-history.com/svg?repos=HighCapable/SweetDependency&type=Date) 88 | 89 | ## License 90 | 91 | - [Apache-2.0](https://www.apache.org/licenses/LICENSE-2.0) 92 | 93 | ``` 94 | Apache License Version 2.0 95 | 96 | Copyright (C) 2019 HighCapable 97 | 98 | Licensed under the Apache License, Version 2.0 (the "License"); 99 | you may not use this file except in compliance with the License. 100 | You may obtain a copy of the License at 101 | 102 | https://www.apache.org/licenses/LICENSE-2.0 103 | 104 | Unless required by applicable law or agreed to in writing, software 105 | distributed under the License is distributed on an "AS IS" BASIS, 106 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 107 | See the License for the specific language governing permissions and 108 | limitations under the License. 109 | ``` 110 | 111 | Copyright © 2019 HighCapable -------------------------------------------------------------------------------- /build.gradle.kts: -------------------------------------------------------------------------------- 1 | plugins { 2 | autowire(libs.plugins.kotlin.jvm) apply false 3 | autowire(libs.plugins.maven.publish) apply false 4 | } -------------------------------------------------------------------------------- /docs/changelog-zh-CN.md: -------------------------------------------------------------------------------- 1 | # 更新日志 2 | 3 | ## 1.0.0 | 2023.09.03 4 | 5 | - 首个版本提交至 Maven 6 | 7 | ## 1.0.1 | 2023.09.07 8 | 9 | - 使用 `net.lingala.zip4j` 取代 JDK 默认创建压缩文档功能修复在 Windows 平台中 Gradle 8.0.2+ 版本创建的 JAR 损坏导致找不到生成的 Class 问题 10 | - 重构自动生成代码部分的装载功能,增加可能找不到 Class 的错误提示 11 | - 新增在设置了未定义版本的插件依赖条件下直接运行自动装配相关 Gradle Task 将抛出异常 12 | - 修复可能的旧版本 Gradle 在使用 `repositories` 的 `content` 功能会抛出异常 13 | 14 | ## 1.0.2 | 2023.09.26 15 | 16 | - 自动生成代码功能将始终输出源码文件,以方便在生成失败的时候进行调试 17 | - 修复部分连续名称的依赖可能导致生成失败的问题 18 | - 修复插件自身检查更新功能失效 19 | - 修复 Gradle 生命周期问题,可能导致 `autowire` 方法的项目作用域不正确 20 | - 改进并采用 Gradle 项目命名规范 21 | - 新增依赖命名空间可启用或禁用生成功能,更新后需要参考文档自行迁移部分配置文件的节点名称否则会发生错误 22 | - 新增使用 `::` 或 `::` 可以访问其它节点的依赖名称、别名并设置到 `version-ref` 功能 23 | 24 | ## 1.0.3 | 2023.11.04 25 | 26 | - 修复从 `1.0.0` 版本开始的一个本插件与 `Kotlin` 插件的 `Class` 冲突问题 27 | - 更换 Kotlin Multiplatform 中的配置依赖 `autowire(...)` 写法为 `sweet.autowire(...)` 28 | - 生成的代码使用 `@Nonnull` 标记以使其能够在 Kotlin DSL 脚本中识别为非空返回值类型 29 | - 一些其它功能性的改进 30 | 31 | ## 1.0.4 | 2023.11.14 32 | 33 | - 新增 `isUseDependencyResolutionManagement` 选项,默认启用,现在你可以选择是否允许插件使用 `dependencyResolutionManagement` 配置库依赖 34 | - 新增 `isDebug` 选项,默认不启用,你可以启用此选项来在自动装配时输出详细的依赖搜索信息 35 | - 一些其它功能性的改进 -------------------------------------------------------------------------------- /docs/changelog.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | 3 | ## 1.0.0 | 2023.09.03 4 | 5 | - The first version is submitted to Maven 6 | 7 | ## 1.0.1 | 2023.09.07 8 | 9 | - Use `net.lingala.zip4j` to replace JDK's default function of creating compressed files and fix the problem that the JAR created by Gradle 8.0.2+ 10 | version on Windows platform is broken and the generated classes cannot be found 11 | - Refactor the loading function of the automatically generated code part, and add an error message that classes may not be found 12 | - Added an exception will be thrown when running the autowire related Gradle task directly 13 | under the condition of setting an undefined version of plugins 14 | - Fix possible old version of Gradle throwing exception when using `content` function of `repositories` 15 | 16 | ## 1.0.2 | 2023.09.26 17 | 18 | - The automatic code generation function will always output source code files to facilitate debugging when the generation fails 19 | - Fix dependencies with some consecutive names may cause generation failure 20 | - Fix plugin own update function 21 | - Fix Gradle lifecycle problem that may cause the project scope of the `autowire` method to be incorrect 22 | - Improve and adopt Gradle project naming convention 23 | - Added dependencies namespace to enable or disable the generation function, after the update, you need to refer to the documentation to migrate the 24 | node names of some configuration files yourself, otherwise errors will occur 25 | - Added the function of using `::` or `::` to access the dependencies name and alias of other nodes and set them to `version-ref` 26 | 27 | ## 1.0.3 | 2023.11.04 28 | 29 | - Fix a `Class` conflict between this plugin and the `Kotlin` plugin starting from `1.0.0` version 30 | - Change the configuration dependency `autowire(...)` in Kotlin Multiplatform to `sweet.autowire(...)` 31 | - Generated code is marked with `@Nonnull` to make it recognized as a non-null return type in Kotlin DSL scripts 32 | - Some other functional improvements 33 | 34 | ## 1.0.4 | 2023.11.14 35 | 36 | - Added `isUseDependencyResolutionManagement` option, enabled by default, now you can choose whether to allow plugins to 37 | use `dependencyResolutionManagement` to configure library dependencies 38 | - Added `isDebug` option, not enabled by default, you can enable this option to output detailed dependency search information during autowiring 39 | - Some other functional improvements -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | # Project Configuration 2 | project.name=SweetDependency 3 | project.url=https://github.com/HighCapable/SweetDependency 4 | project.groupName=com.highcapable.sweetdependency 5 | project.moduleName=sweet-dependency 6 | project.version=1.0.4 7 | # Gradle Plugin Configuration 8 | gradle.plugin.moduleName=${project.groupName}.gradle.plugin 9 | gradle.plugin.implementationClass=${project.groupName}.plugin.SweetDependencyPlugin 10 | # Maven Publish Configuration 11 | SONATYPE_HOST=S01 12 | RELEASE_SIGNING_ENABLED=true 13 | # Maven POM Configuration 14 | POM_NAME=SweetDependency 15 | POM_ARTIFACT_ID=sweet-dependency 16 | POM_DESCRIPTION=An easy autowire and manage dependencies Gradle plugin. 17 | POM_URL=https://github.com/HighCapable/SweetDependency 18 | POM_LICENSE_NAME=Apache License 2.0 19 | POM_LICENSE_URL=https://github.com/HighCapable/SweetDependency/blob/master/LICENSE 20 | POM_LICENSE_DIST=repo 21 | POM_SCM_URL=https://github.com/HighCapable/SweetDependency 22 | POM_SCM_CONNECTION=scm:git:git://github.com/HighCapable/SweetDependency.git 23 | POM_SCM_DEV_CONNECTION=scm:git:ssh://github.com/HighCapable/SweetDependency.git 24 | POM_DEVELOPER_ID=0 25 | POM_DEVELOPER_NAME=fankes 26 | POM_DEVELOPER_EMAIL=qzmmcn@163.com 27 | POM_DEVELOPER_URL=https://github.com/fankes -------------------------------------------------------------------------------- /gradle/sweet-dependency/sweet-dependency-config.yaml: -------------------------------------------------------------------------------- 1 | preferences: 2 | autowire-on-sync-mode: UPDATE_OPTIONAL_DEPENDENCIES 3 | repositories-mode: FAIL_ON_PROJECT_REPOS 4 | 5 | repositories: 6 | gradle-plugin-portal: 7 | scope: PLUGINS 8 | google: 9 | maven-central: 10 | maven-local: 11 | 12 | plugins: 13 | org.jetbrains.kotlin.jvm: 14 | alias: kotlin-jvm 15 | version: 2.1.10 16 | org.jetbrains.kotlin.plugin.serialization: 17 | alias: kotlin-serialization 18 | version-ref: kotlin-jvm 19 | com.vanniktech.maven.publish: 20 | alias: maven-publish 21 | version: 0.31.0 22 | 23 | libraries: 24 | org.snakeyaml: 25 | snakeyaml-engine: 26 | version: 2.9 27 | com.charleskorn.kaml: 28 | kaml: 29 | version: 0.72.0 30 | com.squareup.okhttp3: 31 | okhttp: 32 | version: 4.12.0 33 | com.squareup: 34 | javapoet: 35 | version: 1.13.0 36 | net.lingala.zip4j: 37 | zip4j: 38 | version: 2.11.5 -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HighCapable/SweetDependency/bfb97905cc3bcd0e72bed2f75f48eab4a413327d/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionUrl=https\://services.gradle.org/distributions/gradle-8.13-bin.zip 3 | distributionPath=wrapper/dists 4 | zipStorePath=wrapper/dists 5 | zipStoreBase=GRADLE_USER_HOME -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @rem 2 | @rem Copyright 2015 the original author or authors. 3 | @rem 4 | @rem Licensed under the Apache License, Version 2.0 (the "License"); 5 | @rem you may not use this file except in compliance with the License. 6 | @rem You may obtain a copy of the License at 7 | @rem 8 | @rem https://www.apache.org/licenses/LICENSE-2.0 9 | @rem 10 | @rem Unless required by applicable law or agreed to in writing, software 11 | @rem distributed under the License is distributed on an "AS IS" BASIS, 12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | @rem See the License for the specific language governing permissions and 14 | @rem limitations under the License. 15 | @rem 16 | 17 | @if "%DEBUG%" == "" @echo off 18 | @rem ########################################################################## 19 | @rem 20 | @rem Gradle startup script for Windows 21 | @rem 22 | @rem ########################################################################## 23 | 24 | @rem Set local scope for the variables with windows NT shell 25 | if "%OS%"=="Windows_NT" setlocal 26 | 27 | set DIRNAME=%~dp0 28 | if "%DIRNAME%" == "" set DIRNAME=. 29 | set APP_BASE_NAME=%~n0 30 | set APP_HOME=%DIRNAME% 31 | 32 | @rem Resolve any "." and ".." in APP_HOME to make it shorter. 33 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi 34 | 35 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 36 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" 37 | 38 | @rem Find java.exe 39 | if defined JAVA_HOME goto findJavaFromJavaHome 40 | 41 | set JAVA_EXE=java.exe 42 | %JAVA_EXE% -version >NUL 2>&1 43 | if "%ERRORLEVEL%" == "0" goto execute 44 | 45 | echo. 46 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 47 | echo. 48 | echo Please set the JAVA_HOME variable in your environment to match the 49 | echo location of your Java installation. 50 | 51 | goto fail 52 | 53 | :findJavaFromJavaHome 54 | set JAVA_HOME=%JAVA_HOME:"=% 55 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 56 | 57 | if exist "%JAVA_EXE%" goto execute 58 | 59 | echo. 60 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 61 | echo. 62 | echo Please set the JAVA_HOME variable in your environment to match the 63 | echo location of your Java installation. 64 | 65 | goto fail 66 | 67 | :execute 68 | @rem Setup the command line 69 | 70 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 71 | 72 | 73 | @rem Execute Gradle 74 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* 75 | 76 | :end 77 | @rem End local scope for the variables with windows NT shell 78 | if "%ERRORLEVEL%"=="0" goto mainEnd 79 | 80 | :fail 81 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 82 | rem the _cmd.exe /c_ return code! 83 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 84 | exit /b 1 85 | 86 | :mainEnd 87 | if "%OS%"=="Windows_NT" endlocal 88 | 89 | :omega 90 | -------------------------------------------------------------------------------- /img-src/icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HighCapable/SweetDependency/bfb97905cc3bcd0e72bed2f75f48eab4a413327d/img-src/icon.png -------------------------------------------------------------------------------- /samples/sample-android/.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | /.idea/caches 5 | /.idea/libraries 6 | /.idea/modules.xml 7 | /.idea/workspace.xml 8 | /.idea/navEditor.xml 9 | /.idea/assetWizardSettings.xml 10 | .DS_Store 11 | /build 12 | /captures 13 | .externalNativeBuild 14 | .cxx 15 | local.properties 16 | -------------------------------------------------------------------------------- /samples/sample-android/build.gradle.kts: -------------------------------------------------------------------------------- 1 | plugins { 2 | autowire(libs.plugins.com.android.application) apply false 3 | autowire(libs.plugins.com.android.library) apply false 4 | autowire(libs.plugins.org.jetbrains.kotlin.android) apply false 5 | } -------------------------------------------------------------------------------- /samples/sample-android/demo-app/.gitignore: -------------------------------------------------------------------------------- 1 | /build -------------------------------------------------------------------------------- /samples/sample-android/demo-app/build.gradle.kts: -------------------------------------------------------------------------------- 1 | plugins { 2 | autowire(libs.plugins.com.android.application) 3 | autowire(libs.plugins.org.jetbrains.kotlin.android) 4 | } 5 | 6 | android { 7 | namespace = "com.highcapable.sweetdependency.demo_app" 8 | compileSdk = 34 9 | 10 | defaultConfig { 11 | applicationId = "com.highcapable.sweetdependency.demo_app" 12 | minSdk = 24 13 | targetSdk = 34 14 | versionCode = 1 15 | versionName = "1.0" 16 | testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" 17 | } 18 | 19 | buildTypes { 20 | release { 21 | isMinifyEnabled = false 22 | proguardFiles(getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro") 23 | } 24 | } 25 | compileOptions { 26 | sourceCompatibility = JavaVersion.VERSION_17 27 | targetCompatibility = JavaVersion.VERSION_17 28 | } 29 | kotlinOptions { 30 | jvmTarget = "17" 31 | } 32 | } 33 | 34 | dependencies { 35 | implementation(androidx.core.core.ktx) 36 | implementation(androidx.appcompat.appcompat) 37 | implementation(com.google.android.material.material) 38 | implementation(androidx.constraintlayout.constraintlayout) 39 | testImplementation(junit.junit) 40 | androidTestImplementation(androidx.test.ext.junit) 41 | androidTestImplementation(androidx.test.espresso.espresso.core) 42 | } -------------------------------------------------------------------------------- /samples/sample-android/demo-app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # You can control the set of applied configuration files using the 3 | # proguardFiles setting in build.gradle. 4 | # 5 | # For more details, see 6 | # http://developer.android.com/guide/developing/tools/proguard.html 7 | 8 | # If your project uses WebView with JS, uncomment the following 9 | # and specify the fully qualified class name to the JavaScript interface 10 | # class: 11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 12 | # public *; 13 | #} 14 | 15 | # Uncomment this to preserve the line number information for 16 | # debugging stack traces. 17 | #-keepattributes SourceFile,LineNumberTable 18 | 19 | # If you keep the line number information, uncomment this to 20 | # hide the original source file name. 21 | #-renamesourcefileattribute SourceFile -------------------------------------------------------------------------------- /samples/sample-android/demo-app/src/androidTest/java/com/highcapable/sweetdependency/demo_app/ExampleInstrumentedTest.kt: -------------------------------------------------------------------------------- 1 | package com.highcapable.sweetdependency.demo_app 2 | 3 | import androidx.test.platform.app.InstrumentationRegistry 4 | import androidx.test.ext.junit.runners.AndroidJUnit4 5 | 6 | import org.junit.Test 7 | import org.junit.runner.RunWith 8 | 9 | import org.junit.Assert.* 10 | 11 | /** 12 | * Instrumented test, which will execute on an Android device. 13 | * 14 | * See [testing documentation](http://d.android.com/tools/testing). 15 | */ 16 | @RunWith(AndroidJUnit4::class) 17 | class ExampleInstrumentedTest { 18 | @Test 19 | fun useAppContext() { 20 | // Context of the app under test. 21 | val appContext = InstrumentationRegistry.getInstrumentation().targetContext 22 | assertEquals("com.highcapable.sweetdependency.demo_app", appContext.packageName) 23 | } 24 | } -------------------------------------------------------------------------------- /samples/sample-android/demo-app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 14 | 15 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /samples/sample-android/demo-app/src/main/java/com/highcapable/sweetdependency/demo_app/MainActivity.kt: -------------------------------------------------------------------------------- 1 | package com.highcapable.sweetdependency.demo_app 2 | 3 | import android.os.Bundle 4 | import androidx.appcompat.app.AppCompatActivity 5 | 6 | class MainActivity : AppCompatActivity() { 7 | 8 | override fun onCreate(savedInstanceState: Bundle?) { 9 | super.onCreate(savedInstanceState) 10 | setContentView(R.layout.activity_main) 11 | } 12 | } -------------------------------------------------------------------------------- /samples/sample-android/demo-app/src/main/res/drawable-v24/ic_launcher_foreground.xml: -------------------------------------------------------------------------------- 1 | 7 | 8 | 9 | 15 | 18 | 21 | 22 | 23 | 24 | 30 | -------------------------------------------------------------------------------- /samples/sample-android/demo-app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 17 | -------------------------------------------------------------------------------- /samples/sample-android/demo-app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /samples/sample-android/demo-app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /samples/sample-android/demo-app/src/main/res/mipmap-anydpi-v33/ic_launcher.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /samples/sample-android/demo-app/src/main/res/mipmap-hdpi/ic_launcher.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HighCapable/SweetDependency/bfb97905cc3bcd0e72bed2f75f48eab4a413327d/samples/sample-android/demo-app/src/main/res/mipmap-hdpi/ic_launcher.webp -------------------------------------------------------------------------------- /samples/sample-android/demo-app/src/main/res/mipmap-hdpi/ic_launcher_round.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HighCapable/SweetDependency/bfb97905cc3bcd0e72bed2f75f48eab4a413327d/samples/sample-android/demo-app/src/main/res/mipmap-hdpi/ic_launcher_round.webp -------------------------------------------------------------------------------- /samples/sample-android/demo-app/src/main/res/mipmap-mdpi/ic_launcher.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HighCapable/SweetDependency/bfb97905cc3bcd0e72bed2f75f48eab4a413327d/samples/sample-android/demo-app/src/main/res/mipmap-mdpi/ic_launcher.webp -------------------------------------------------------------------------------- /samples/sample-android/demo-app/src/main/res/mipmap-mdpi/ic_launcher_round.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HighCapable/SweetDependency/bfb97905cc3bcd0e72bed2f75f48eab4a413327d/samples/sample-android/demo-app/src/main/res/mipmap-mdpi/ic_launcher_round.webp -------------------------------------------------------------------------------- /samples/sample-android/demo-app/src/main/res/mipmap-xhdpi/ic_launcher.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HighCapable/SweetDependency/bfb97905cc3bcd0e72bed2f75f48eab4a413327d/samples/sample-android/demo-app/src/main/res/mipmap-xhdpi/ic_launcher.webp -------------------------------------------------------------------------------- /samples/sample-android/demo-app/src/main/res/mipmap-xhdpi/ic_launcher_round.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HighCapable/SweetDependency/bfb97905cc3bcd0e72bed2f75f48eab4a413327d/samples/sample-android/demo-app/src/main/res/mipmap-xhdpi/ic_launcher_round.webp -------------------------------------------------------------------------------- /samples/sample-android/demo-app/src/main/res/mipmap-xxhdpi/ic_launcher.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HighCapable/SweetDependency/bfb97905cc3bcd0e72bed2f75f48eab4a413327d/samples/sample-android/demo-app/src/main/res/mipmap-xxhdpi/ic_launcher.webp -------------------------------------------------------------------------------- /samples/sample-android/demo-app/src/main/res/mipmap-xxhdpi/ic_launcher_round.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HighCapable/SweetDependency/bfb97905cc3bcd0e72bed2f75f48eab4a413327d/samples/sample-android/demo-app/src/main/res/mipmap-xxhdpi/ic_launcher_round.webp -------------------------------------------------------------------------------- /samples/sample-android/demo-app/src/main/res/mipmap-xxxhdpi/ic_launcher.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HighCapable/SweetDependency/bfb97905cc3bcd0e72bed2f75f48eab4a413327d/samples/sample-android/demo-app/src/main/res/mipmap-xxxhdpi/ic_launcher.webp -------------------------------------------------------------------------------- /samples/sample-android/demo-app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HighCapable/SweetDependency/bfb97905cc3bcd0e72bed2f75f48eab4a413327d/samples/sample-android/demo-app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.webp -------------------------------------------------------------------------------- /samples/sample-android/demo-app/src/main/res/values-night/themes.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 16 | -------------------------------------------------------------------------------- /samples/sample-android/demo-app/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #FFBB86FC 4 | #FF6200EE 5 | #FF3700B3 6 | #FF03DAC5 7 | #FF018786 8 | #FF000000 9 | #FFFFFFFF 10 | -------------------------------------------------------------------------------- /samples/sample-android/demo-app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | SweetDependency 3 | -------------------------------------------------------------------------------- /samples/sample-android/demo-app/src/main/res/values/themes.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 16 | -------------------------------------------------------------------------------- /samples/sample-android/demo-app/src/main/res/xml/backup_rules.xml: -------------------------------------------------------------------------------- 1 | 8 | 9 | 13 | -------------------------------------------------------------------------------- /samples/sample-android/demo-app/src/main/res/xml/data_extraction_rules.xml: -------------------------------------------------------------------------------- 1 | 6 | 7 | 8 | 12 | 13 | 19 | -------------------------------------------------------------------------------- /samples/sample-android/demo-app/src/test/java/com/highcapable/sweetdependency/demo_app/ExampleUnitTest.kt: -------------------------------------------------------------------------------- 1 | package com.highcapable.sweetdependency.demo_app 2 | 3 | import org.junit.Test 4 | 5 | import org.junit.Assert.* 6 | 7 | /** 8 | * Example local unit test, which will execute on the development machine (host). 9 | * 10 | * See [testing documentation](http://d.android.com/tools/testing). 11 | */ 12 | class ExampleUnitTest { 13 | @Test 14 | fun addition_isCorrect() { 15 | assertEquals(4, 2 + 2) 16 | } 17 | } -------------------------------------------------------------------------------- /samples/sample-android/demo-library/.gitignore: -------------------------------------------------------------------------------- 1 | /build -------------------------------------------------------------------------------- /samples/sample-android/demo-library/build.gradle.kts: -------------------------------------------------------------------------------- 1 | plugins { 2 | autowire(libs.plugins.com.android.library) 3 | autowire(libs.plugins.org.jetbrains.kotlin.android) 4 | } 5 | 6 | android { 7 | namespace = "com.highcapable.sweetdependency.demo_library" 8 | compileSdk = 34 9 | 10 | defaultConfig { 11 | minSdk = 24 12 | testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" 13 | consumerProguardFiles("consumer-rules.pro") 14 | } 15 | 16 | buildTypes { 17 | release { 18 | isMinifyEnabled = false 19 | proguardFiles(getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro") 20 | } 21 | } 22 | compileOptions { 23 | sourceCompatibility = JavaVersion.VERSION_17 24 | targetCompatibility = JavaVersion.VERSION_17 25 | } 26 | kotlinOptions { 27 | jvmTarget = "17" 28 | } 29 | } 30 | 31 | dependencies { 32 | implementation(androidx.core.core.ktx) 33 | implementation(androidx.appcompat.appcompat) 34 | implementation(com.google.android.material.material) 35 | implementation(androidx.constraintlayout.constraintlayout) 36 | testImplementation(junit.junit) 37 | androidTestImplementation(androidx.test.ext.junit) 38 | androidTestImplementation(androidx.test.espresso.espresso.core) 39 | } -------------------------------------------------------------------------------- /samples/sample-android/demo-library/consumer-rules.pro: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HighCapable/SweetDependency/bfb97905cc3bcd0e72bed2f75f48eab4a413327d/samples/sample-android/demo-library/consumer-rules.pro -------------------------------------------------------------------------------- /samples/sample-android/demo-library/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # You can control the set of applied configuration files using the 3 | # proguardFiles setting in build.gradle. 4 | # 5 | # For more details, see 6 | # http://developer.android.com/guide/developing/tools/proguard.html 7 | 8 | # If your project uses WebView with JS, uncomment the following 9 | # and specify the fully qualified class name to the JavaScript interface 10 | # class: 11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 12 | # public *; 13 | #} 14 | 15 | # Uncomment this to preserve the line number information for 16 | # debugging stack traces. 17 | #-keepattributes SourceFile,LineNumberTable 18 | 19 | # If you keep the line number information, uncomment this to 20 | # hide the original source file name. 21 | #-renamesourcefileattribute SourceFile -------------------------------------------------------------------------------- /samples/sample-android/demo-library/src/androidTest/java/com/highcapable/sweetdependency/demo_library/ExampleInstrumentedTest.kt: -------------------------------------------------------------------------------- 1 | package com.highcapable.sweetdependency.demo_library 2 | 3 | import androidx.test.platform.app.InstrumentationRegistry 4 | import androidx.test.ext.junit.runners.AndroidJUnit4 5 | 6 | import org.junit.Test 7 | import org.junit.runner.RunWith 8 | 9 | import org.junit.Assert.* 10 | 11 | /** 12 | * Instrumented test, which will execute on an Android device. 13 | * 14 | * See [testing documentation](http://d.android.com/tools/testing). 15 | */ 16 | @RunWith(AndroidJUnit4::class) 17 | class ExampleInstrumentedTest { 18 | @Test 19 | fun useAppContext() { 20 | // Context of the app under test. 21 | val appContext = InstrumentationRegistry.getInstrumentation().targetContext 22 | assertEquals("com.highcapable.sweetdependency.demo_library.test", appContext.packageName) 23 | } 24 | } -------------------------------------------------------------------------------- /samples/sample-android/demo-library/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /samples/sample-android/demo-library/src/main/java/com/highcapable/sweetdependency/demo_library/DemoLibrary.kt: -------------------------------------------------------------------------------- 1 | package com.highcapable.sweetdependency.demo_library 2 | 3 | class DemoLibrary -------------------------------------------------------------------------------- /samples/sample-android/demo-library/src/test/java/com/highcapable/sweetdependency/demo_library/ExampleUnitTest.kt: -------------------------------------------------------------------------------- 1 | package com.highcapable.sweetdependency.demo_library 2 | 3 | import org.junit.Test 4 | 5 | import org.junit.Assert.* 6 | 7 | /** 8 | * Example local unit test, which will execute on the development machine (host). 9 | * 10 | * See [testing documentation](http://d.android.com/tools/testing). 11 | */ 12 | class ExampleUnitTest { 13 | @Test 14 | fun addition_isCorrect() { 15 | assertEquals(4, 2 + 2) 16 | } 17 | } -------------------------------------------------------------------------------- /samples/sample-android/gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | # IDE (e.g. Android Studio) users: 3 | # Gradle settings configured through the IDE *will override* 4 | # any settings specified in this file. 5 | # For more details on how to configure your build environment visit 6 | # http://www.gradle.org/docs/current/userguide/build_environment.html 7 | # Specifies the JVM arguments used for the daemon process. 8 | # The setting is particularly useful for tweaking memory settings. 9 | org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8 10 | # When configured, Gradle will run in incubating parallel mode. 11 | # This option should only be used with decoupled projects. More details, visit 12 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 13 | # org.gradle.parallel=true 14 | # AndroidX package structure to make it clearer which packages are bundled with the 15 | # Android operating system, and which are packaged with your app's APK 16 | # https://developer.android.com/topic/libraries/support-library/androidx-rn 17 | android.useAndroidX=true 18 | # Kotlin code style for this project: "official" or "obsolete": 19 | kotlin.code.style=official 20 | # Enables namespacing of each library's R class so that its R class includes only the 21 | # resources declared in the library itself and none from the library's dependencies, 22 | # thereby reducing the size of the R class for that library 23 | android.nonTransitiveRClass=true -------------------------------------------------------------------------------- /samples/sample-android/gradle/sweet-dependency/sweet-dependency-config.yaml: -------------------------------------------------------------------------------- 1 | preferences: 2 | autowire-on-sync-mode: UPDATE_OPTIONAL_DEPENDENCIES 3 | repositories-mode: FAIL_ON_PROJECT_REPOS 4 | 5 | repositories: 6 | gradle-plugin-portal: 7 | scope: PLUGINS 8 | google: 9 | maven-central: 10 | 11 | plugins: 12 | com.android.application: 13 | version: + 14 | com.android.library: 15 | version-ref: com.android.application 16 | org.jetbrains.kotlin.android: 17 | version: + 18 | 19 | libraries: 20 | com.google.android.material: 21 | material: 22 | version: + 23 | androidx.constraintlayout: 24 | constraintlayout: 25 | version: + 26 | junit: 27 | junit: 28 | version: + 29 | androidx.appcompat: 30 | appcompat: 31 | version: + 32 | androidx.core: 33 | core: 34 | version: + 35 | core-ktx: 36 | version-ref: ::core 37 | androidx.test.ext: 38 | junit: 39 | version: + 40 | androidx.test.espresso: 41 | espresso-core: 42 | version: + -------------------------------------------------------------------------------- /samples/sample-android/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HighCapable/SweetDependency/bfb97905cc3bcd0e72bed2f75f48eab4a413327d/samples/sample-android/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /samples/sample-android/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionUrl=https\://services.gradle.org/distributions/gradle-8.3-bin.zip 3 | distributionPath=wrapper/dists 4 | zipStorePath=wrapper/dists 5 | zipStoreBase=GRADLE_USER_HOME -------------------------------------------------------------------------------- /samples/sample-android/gradlew.bat: -------------------------------------------------------------------------------- 1 | @rem 2 | @rem Copyright 2015 the original author or authors. 3 | @rem 4 | @rem Licensed under the Apache License, Version 2.0 (the "License"); 5 | @rem you may not use this file except in compliance with the License. 6 | @rem You may obtain a copy of the License at 7 | @rem 8 | @rem https://www.apache.org/licenses/LICENSE-2.0 9 | @rem 10 | @rem Unless required by applicable law or agreed to in writing, software 11 | @rem distributed under the License is distributed on an "AS IS" BASIS, 12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | @rem See the License for the specific language governing permissions and 14 | @rem limitations under the License. 15 | @rem 16 | 17 | @if "%DEBUG%" == "" @echo off 18 | @rem ########################################################################## 19 | @rem 20 | @rem Gradle startup script for Windows 21 | @rem 22 | @rem ########################################################################## 23 | 24 | @rem Set local scope for the variables with windows NT shell 25 | if "%OS%"=="Windows_NT" setlocal 26 | 27 | set DIRNAME=%~dp0 28 | if "%DIRNAME%" == "" set DIRNAME=. 29 | set APP_BASE_NAME=%~n0 30 | set APP_HOME=%DIRNAME% 31 | 32 | @rem Resolve any "." and ".." in APP_HOME to make it shorter. 33 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi 34 | 35 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 36 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" 37 | 38 | @rem Find java.exe 39 | if defined JAVA_HOME goto findJavaFromJavaHome 40 | 41 | set JAVA_EXE=java.exe 42 | %JAVA_EXE% -version >NUL 2>&1 43 | if "%ERRORLEVEL%" == "0" goto execute 44 | 45 | echo. 46 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 47 | echo. 48 | echo Please set the JAVA_HOME variable in your environment to match the 49 | echo location of your Java installation. 50 | 51 | goto fail 52 | 53 | :findJavaFromJavaHome 54 | set JAVA_HOME=%JAVA_HOME:"=% 55 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 56 | 57 | if exist "%JAVA_EXE%" goto execute 58 | 59 | echo. 60 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 61 | echo. 62 | echo Please set the JAVA_HOME variable in your environment to match the 63 | echo location of your Java installation. 64 | 65 | goto fail 66 | 67 | :execute 68 | @rem Setup the command line 69 | 70 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 71 | 72 | 73 | @rem Execute Gradle 74 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* 75 | 76 | :end 77 | @rem End local scope for the variables with windows NT shell 78 | if "%ERRORLEVEL%"=="0" goto mainEnd 79 | 80 | :fail 81 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 82 | rem the _cmd.exe /c_ return code! 83 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 84 | exit /b 1 85 | 86 | :mainEnd 87 | if "%OS%"=="Windows_NT" endlocal 88 | 89 | :omega 90 | -------------------------------------------------------------------------------- /samples/sample-android/settings.gradle.kts: -------------------------------------------------------------------------------- 1 | pluginManagement { 2 | repositories { 3 | gradlePluginPortal() 4 | google() 5 | mavenCentral() 6 | } 7 | } 8 | plugins { 9 | // Import the SweetDependency plugin here 10 | // 在这里引入 SweetDependency 插件 11 | id("com.highcapable.sweetdependency") version "1.0.4" 12 | } 13 | sweetDependency { 14 | configFileName = "sweet-dependency-config.yaml" 15 | isEnableDependenciesAutowireLog = true 16 | isEnableVerboseMode = true 17 | } 18 | rootProject.name = "SweetDependency-Sample-Android" 19 | include(":demo-app") 20 | include(":demo-library") -------------------------------------------------------------------------------- /samples/sample-jvm/.gitignore: -------------------------------------------------------------------------------- 1 | .gradle 2 | build/ 3 | !gradle/wrapper/gradle-wrapper.jar 4 | !**/src/main/**/build/ 5 | !**/src/test/**/build/ 6 | 7 | ### IntelliJ IDEA ### 8 | .idea/modules.xml 9 | .idea/jarRepositories.xml 10 | .idea/compiler.xml 11 | .idea/libraries/ 12 | *.iws 13 | *.iml 14 | *.ipr 15 | out/ 16 | !**/src/main/**/out/ 17 | !**/src/test/**/out/ 18 | 19 | ### Eclipse ### 20 | .apt_generated 21 | .classpath 22 | .factorypath 23 | .project 24 | .settings 25 | .springBeans 26 | .sts4-cache 27 | bin/ 28 | !**/src/main/**/bin/ 29 | !**/src/test/**/bin/ 30 | 31 | ### NetBeans ### 32 | /nbproject/private/ 33 | /nbbuild/ 34 | /dist/ 35 | /nbdist/ 36 | /.nb-gradle/ 37 | 38 | ### VS Code ### 39 | .vscode/ 40 | 41 | ### Mac OS ### 42 | .DS_Store -------------------------------------------------------------------------------- /samples/sample-jvm/build.gradle.kts: -------------------------------------------------------------------------------- 1 | plugins { 2 | autowire(libs.plugins.org.jetbrains.kotlin.jvm) apply false 3 | } -------------------------------------------------------------------------------- /samples/sample-jvm/gradle.properties: -------------------------------------------------------------------------------- 1 | kotlin.code.style=official -------------------------------------------------------------------------------- /samples/sample-jvm/gradle/sweet-dependency/sweet-dependency-config.yaml: -------------------------------------------------------------------------------- 1 | preferences: 2 | autowire-on-sync-mode: UPDATE_OPTIONAL_DEPENDENCIES 3 | repositories-mode: FAIL_ON_PROJECT_REPOS 4 | 5 | repositories: 6 | gradle-plugin-portal: 7 | scope: PLUGINS 8 | google: 9 | maven-central: 10 | 11 | plugins: 12 | org.jetbrains.kotlin.jvm: 13 | version: + 14 | 15 | libraries: 16 | org.jetbrains.kotlin: 17 | kotlin-test: 18 | version: + -------------------------------------------------------------------------------- /samples/sample-jvm/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HighCapable/SweetDependency/bfb97905cc3bcd0e72bed2f75f48eab4a413327d/samples/sample-jvm/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /samples/sample-jvm/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-8.3-bin.zip 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists -------------------------------------------------------------------------------- /samples/sample-jvm/gradlew.bat: -------------------------------------------------------------------------------- 1 | @rem 2 | @rem Copyright 2015 the original author or authors. 3 | @rem 4 | @rem Licensed under the Apache License, Version 2.0 (the "License"); 5 | @rem you may not use this file except in compliance with the License. 6 | @rem You may obtain a copy of the License at 7 | @rem 8 | @rem https://www.apache.org/licenses/LICENSE-2.0 9 | @rem 10 | @rem Unless required by applicable law or agreed to in writing, software 11 | @rem distributed under the License is distributed on an "AS IS" BASIS, 12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | @rem See the License for the specific language governing permissions and 14 | @rem limitations under the License. 15 | @rem 16 | 17 | @if "%DEBUG%" == "" @echo off 18 | @rem ########################################################################## 19 | @rem 20 | @rem Gradle startup script for Windows 21 | @rem 22 | @rem ########################################################################## 23 | 24 | @rem Set local scope for the variables with windows NT shell 25 | if "%OS%"=="Windows_NT" setlocal 26 | 27 | set DIRNAME=%~dp0 28 | if "%DIRNAME%" == "" set DIRNAME=. 29 | set APP_BASE_NAME=%~n0 30 | set APP_HOME=%DIRNAME% 31 | 32 | @rem Resolve any "." and ".." in APP_HOME to make it shorter. 33 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi 34 | 35 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 36 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" 37 | 38 | @rem Find java.exe 39 | if defined JAVA_HOME goto findJavaFromJavaHome 40 | 41 | set JAVA_EXE=java.exe 42 | %JAVA_EXE% -version >NUL 2>&1 43 | if "%ERRORLEVEL%" == "0" goto execute 44 | 45 | echo. 46 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 47 | echo. 48 | echo Please set the JAVA_HOME variable in your environment to match the 49 | echo location of your Java installation. 50 | 51 | goto fail 52 | 53 | :findJavaFromJavaHome 54 | set JAVA_HOME=%JAVA_HOME:"=% 55 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 56 | 57 | if exist "%JAVA_EXE%" goto execute 58 | 59 | echo. 60 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 61 | echo. 62 | echo Please set the JAVA_HOME variable in your environment to match the 63 | echo location of your Java installation. 64 | 65 | goto fail 66 | 67 | :execute 68 | @rem Setup the command line 69 | 70 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 71 | 72 | 73 | @rem Execute Gradle 74 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* 75 | 76 | :end 77 | @rem End local scope for the variables with windows NT shell 78 | if "%ERRORLEVEL%"=="0" goto mainEnd 79 | 80 | :fail 81 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 82 | rem the _cmd.exe /c_ return code! 83 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 84 | exit /b 1 85 | 86 | :mainEnd 87 | if "%OS%"=="Windows_NT" endlocal 88 | 89 | :omega 90 | -------------------------------------------------------------------------------- /samples/sample-jvm/sample-jvm/build.gradle.kts: -------------------------------------------------------------------------------- 1 | plugins { 2 | autowire(libs.plugins.org.jetbrains.kotlin.jvm) 3 | application 4 | } 5 | 6 | group = "com.highcapable.sweetdependency.demo_jvm" 7 | version = "1.0-SNAPSHOT" 8 | 9 | tasks.test { 10 | useJUnitPlatform() 11 | } 12 | 13 | kotlin { 14 | jvmToolchain(17) 15 | } 16 | 17 | application { 18 | mainClass.set("com.highcapable.sweetdependency.demo_jvm.MainKt") 19 | } 20 | 21 | dependencies { 22 | testImplementation(org.jetbrains.kotlin.kotlin.test) 23 | } -------------------------------------------------------------------------------- /samples/sample-jvm/sample-jvm/src/main/kotlin/com/highcapable/sweetdependency/demo_jvm/Main.kt: -------------------------------------------------------------------------------- 1 | package com.highcapable.sweetdependency.demo_jvm 2 | 3 | fun main(args: Array) { 4 | println("Hello World!") 5 | 6 | // Try adding program arguments via Run/Debug configuration. 7 | // Learn more about running applications: https://www.jetbrains.com/help/idea/running-applications.html. 8 | println("Program arguments: ${args.joinToString()}") 9 | } -------------------------------------------------------------------------------- /samples/sample-jvm/settings.gradle.kts: -------------------------------------------------------------------------------- 1 | pluginManagement { 2 | repositories { 3 | gradlePluginPortal() 4 | google() 5 | mavenCentral() 6 | } 7 | } 8 | plugins { 9 | // Import the SweetDependency plugin here 10 | // 在这里引入 SweetDependency 插件 11 | id("com.highcapable.sweetdependency") version "1.0.4" 12 | } 13 | sweetDependency { 14 | configFileName = "sweet-dependency-config.yaml" 15 | isEnableDependenciesAutowireLog = true 16 | isEnableVerboseMode = true 17 | } 18 | rootProject.name = "SweetDependency-Sample-Jvm" 19 | include(":sample-jvm") -------------------------------------------------------------------------------- /settings.gradle.kts: -------------------------------------------------------------------------------- 1 | pluginManagement { 2 | repositories { 3 | gradlePluginPortal() 4 | google() 5 | mavenCentral() 6 | mavenLocal() 7 | } 8 | } 9 | plugins { 10 | id("com.highcapable.sweetdependency") version "1.0.4" 11 | id("com.highcapable.sweetproperty") version "1.0.5" 12 | } 13 | sweetDependency { 14 | isEnableVerboseMode = false 15 | } 16 | sweetProperty { 17 | global { 18 | sourcesCode { 19 | className = rootProject.name 20 | includeKeys( 21 | "^project\\..*\$".toRegex(), 22 | "^gradle\\..*\$".toRegex() 23 | ) 24 | isEnableRestrictedAccess = true 25 | } 26 | } 27 | rootProject { all { isEnable = false } } 28 | } 29 | rootProject.name = "SweetDependency" 30 | include(":sweetdependency-gradle-plugin") -------------------------------------------------------------------------------- /sweetdependency-gradle-plugin/build.gradle.kts: -------------------------------------------------------------------------------- 1 | plugins { 2 | `kotlin-dsl` 3 | autowire(libs.plugins.kotlin.jvm) 4 | autowire(libs.plugins.kotlin.serialization) 5 | autowire(libs.plugins.maven.publish) 6 | } 7 | 8 | group = property.project.groupName 9 | version = property.project.version 10 | 11 | java { 12 | sourceCompatibility = JavaVersion.VERSION_21 13 | targetCompatibility = JavaVersion.VERSION_21 14 | withSourcesJar() 15 | } 16 | 17 | kotlin { 18 | jvmToolchain(21) 19 | sourceSets.all { languageSettings { languageVersion = "2.0" } } 20 | compilerOptions { 21 | freeCompilerArgs = listOf( 22 | "-Xno-param-assertions", 23 | "-Xno-call-assertions", 24 | "-Xno-receiver-assertions" 25 | ) 26 | } 27 | } 28 | 29 | dependencies { 30 | implementation(org.snakeyaml.snakeyaml.engine) 31 | implementation(com.charleskorn.kaml.kaml) 32 | implementation(com.squareup.okhttp3.okhttp) 33 | implementation(com.squareup.javapoet) 34 | implementation(net.lingala.zip4j.zip4j) 35 | } 36 | 37 | gradlePlugin { 38 | plugins { 39 | create(property.project.moduleName) { 40 | id = property.project.groupName 41 | implementationClass = property.gradle.plugin.implementationClass 42 | } 43 | } 44 | } -------------------------------------------------------------------------------- /sweetdependency-gradle-plugin/src/main/java/com/highcapable/sweetdependency/SweetDependency.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * SweetDependency - An easy autowire and manage dependencies Gradle plugin. 3 | * Copyright (C) 2019 HighCapable 4 | * https://github.com/HighCapable/SweetDependency 5 | * 6 | * Apache License Version 2.0 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * https://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | * 20 | * This file is created by fankes on 2023/5/17. 21 | */ 22 | package com.highcapable.sweetdependency 23 | 24 | import com.highcapable.sweetdependency.generated.SweetDependencyProperties 25 | 26 | /** 27 | * [SweetDependency] 的装载调用类 28 | */ 29 | object SweetDependency { 30 | 31 | /** Banner 内容 */ 32 | private const val BANNER_CONTENT = """ 33 | _____ _ _____ _ 34 | / ____| | | | __ \ | | 35 | | (_____ _____ ___| |_ | | | | ___ _ __ ___ _ __ __| | ___ _ __ ___ _ _ 36 | \___ \ \ /\ / / _ \/ _ \ __| | | | |/ _ \ '_ \ / _ \ '_ \ / _` |/ _ \ '_ \ / __| | | | 37 | ____) \ V V / __/ __/ |_ | |__| | __/ |_) | __/ | | | (_| | __/ | | | (__| |_| | 38 | |_____/ \_/\_/ \___|\___|\__| |_____/ \___| .__/ \___|_| |_|\__,_|\___|_| |_|\___|\__, | 39 | | | __/ | 40 | |_| |___/ 41 | """ 42 | 43 | /** Banner 内容 */ 44 | val bannerContent = BANNER_CONTENT.trimIndent() 45 | 46 | /** 标签名称 */ 47 | const val TAG = SweetDependencyProperties.PROJECT_NAME 48 | 49 | /** 版本 */ 50 | const val VERSION = SweetDependencyProperties.PROJECT_VERSION 51 | 52 | /** 项目地址 */ 53 | const val PROJECT_URL = SweetDependencyProperties.PROJECT_URL 54 | } -------------------------------------------------------------------------------- /sweetdependency-gradle-plugin/src/main/java/com/highcapable/sweetdependency/document/DependencyDocument.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * SweetDependency - An easy autowire and manage dependencies Gradle plugin. 3 | * Copyright (C) 2019 HighCapable 4 | * https://github.com/HighCapable/SweetDependency 5 | * 6 | * Apache License Version 2.0 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * https://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | * 20 | * This file is created by fankes on 2023/5/18. 21 | */ 22 | @file:Suppress("unused") 23 | 24 | package com.highcapable.sweetdependency.document 25 | 26 | import com.highcapable.sweetdependency.gradle.entity.DependencyVersion 27 | import com.highcapable.sweetdependency.manager.content.Repositories 28 | import com.highcapable.sweetdependency.utils.debug.SError 29 | import com.highcapable.sweetdependency.utils.toSpaceList 30 | import com.highcapable.sweetdependency.utils.yaml.proxy.IYamlDocument 31 | import kotlinx.serialization.SerialName 32 | import kotlinx.serialization.Serializable 33 | 34 | /** 35 | * 依赖每项文档实体 36 | * @param alias 别名 37 | * @param version 版本 38 | * @param versionRef 版本引用 39 | * @param versions 版本别名数组 40 | * @param isAutoUpdate 是否自动更新 41 | * @param versionFilter 版本过滤器文档实体 42 | * @param repositories 指定使用的存储库名称 43 | */ 44 | @Serializable 45 | internal data class DependencyDocument( 46 | @SerialName("alias") 47 | internal var alias: String = "", 48 | @SerialName("version") 49 | internal var version: String = "", 50 | @SerialName("version-ref") 51 | internal var versionRef: String = "", 52 | @SerialName("versions") 53 | internal var versions: MutableMap = mutableMapOf(), 54 | @SerialName("auto-update") 55 | internal var isAutoUpdate: Boolean = true, 56 | @SerialName("version-filter") 57 | internal var versionFilter: VersionFilterDocument? = null, 58 | @SerialName("repositories") 59 | internal var repositories: String = "" 60 | ) : IYamlDocument { 61 | 62 | /** 63 | * 获取版本 64 | * @return [DependencyVersion] 65 | */ 66 | internal fun version() = DependencyVersion(version) 67 | 68 | /** 69 | * 获取版本别名数组 70 | * @return <[MutableMap]><[String], [DependencyVersion]> 71 | */ 72 | internal fun versions() = mutableMapOf().also { 73 | versions.forEach { (key, value) -> it[key] = DependencyVersion(value.replace(DependencyVersion.LATEST_VERSION_NAME, version)) } 74 | } 75 | 76 | /** 77 | * 更新版本 78 | * @param newVersion 新版本 79 | */ 80 | internal fun updateVersion(newVersion: DependencyVersion) { 81 | version = newVersion.current 82 | } 83 | 84 | /** 85 | * 更新版本 86 | * @param document 当前文档实例 87 | */ 88 | internal fun updateVersion(document: DependencyDocument) { 89 | version = document.version 90 | } 91 | 92 | /** 93 | * 获取指定使用的存储库数组 94 | * @return [MutableList]<[RepositoryDocument]> 95 | */ 96 | internal fun repositories() = mutableListOf().apply { 97 | repositories.toSpaceList().forEach { 98 | add(Repositories.all().firstOrNull { e -> e.nodeName == it } ?: SError.make("Could not found repository with name \"$it\"")) 99 | } 100 | }.distinctBy { it.url.ifBlank { it.path } }.toMutableList() 101 | } -------------------------------------------------------------------------------- /sweetdependency-gradle-plugin/src/main/java/com/highcapable/sweetdependency/document/PreferencesDocument.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * SweetDependency - An easy autowire and manage dependencies Gradle plugin. 3 | * Copyright (C) 2019 HighCapable 4 | * https://github.com/HighCapable/SweetDependency 5 | * 6 | * Apache License Version 2.0 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * https://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | * 20 | * This file is created by fankes on 2023/5/17. 21 | */ 22 | package com.highcapable.sweetdependency.document 23 | 24 | import com.highcapable.sweetdependency.document.factory.checkingName 25 | import com.highcapable.sweetdependency.utils.camelcase 26 | import com.highcapable.sweetdependency.utils.debug.SError 27 | import com.highcapable.sweetdependency.utils.yaml.proxy.IYamlDocument 28 | import kotlinx.serialization.SerialName 29 | import kotlinx.serialization.Serializable 30 | import org.gradle.api.initialization.resolve.RepositoriesMode as GradleRepositoriesMode 31 | 32 | /** 33 | * 偏好配置项文档实体 34 | * @param autowireOnSyncMode Gradle Sync 自动装配、更新依赖模式 35 | * @param repositoriesMode 存储库装载模式 36 | * @param dependenciesNamespace 依赖命名空间 37 | * @param versionFilter 版本过滤器文档实体 38 | */ 39 | @Serializable 40 | internal data class PreferencesDocument( 41 | @SerialName("autowire-on-sync-mode") 42 | internal var autowireOnSyncMode: AutowireOnSyncMode = AutowireOnSyncMode.UPDATE_OPTIONAL_DEPENDENCIES, 43 | @SerialName("repositories-mode") 44 | internal var repositoriesMode: RepositoriesMode = RepositoriesMode.FAIL_ON_PROJECT_REPOS, 45 | @SerialName("dependencies-namespace") 46 | internal var dependenciesNamespace: DependenciesNamespaceDocument = DependenciesNamespaceDocument(), 47 | @SerialName("version-filter") 48 | internal var versionFilter: VersionFilterDocument = VersionFilterDocument() 49 | ) : IYamlDocument { 50 | 51 | /** 52 | * 依赖命名空间文档实体 53 | * @param plugins 插件依赖 54 | * @param libraries 库依赖 55 | */ 56 | @Serializable 57 | internal data class DependenciesNamespaceDocument( 58 | @SerialName("plugins") 59 | var plugins: NamespaceOptionDocument = NamespaceOptionDocument(name = "libs"), 60 | @SerialName("libraries") 61 | var libraries: NamespaceOptionDocument = NamespaceOptionDocument() 62 | ) : IYamlDocument { 63 | 64 | init { 65 | if (plugins.name.isNotBlank() && libraries.name.isNotBlank() && plugins.name == libraries.name) 66 | SError.make("Duplicated dependencies namespace \"$plugins\"") 67 | } 68 | } 69 | 70 | /** 71 | * 命名空间选项文档实体 72 | * @param isEnable 是否启用 73 | * @param name 名称 74 | */ 75 | @Serializable 76 | internal data class NamespaceOptionDocument( 77 | @SerialName("enable") 78 | var isEnable: Boolean = true, 79 | @SerialName("name") 80 | var name: String = "" 81 | ) : IYamlDocument { 82 | 83 | /** 84 | * 获取名称 85 | * @return [String] 86 | */ 87 | internal fun name() = name.apply { checkingName("dependencies namespace", isCheckExtName = true) }.camelcase() 88 | } 89 | 90 | /** 91 | * Gradle Sync 自动装配、更新依赖模式定义类 92 | */ 93 | internal enum class AutowireOnSyncMode { 94 | /** 自动装配和更新可选依赖 (插件依赖 + 库依赖) */ 95 | UPDATE_OPTIONAL_DEPENDENCIES, 96 | 97 | /** 自动装配和更新所有依赖 (插件依赖 + 库依赖) */ 98 | UPDATE_ALL_DEPENDENCIES, 99 | 100 | /** 仅自动装配使用“+”填充版本的依赖 (插件依赖 + 库依赖) */ 101 | ONLY_AUTOWIRE_DEPENDENCIES, 102 | 103 | /** 自动装配和更新可选依赖 (插件依赖) */ 104 | UPDATE_OPTIONAL_PLUGINS, 105 | 106 | /** 自动装配和更新所有依赖 (插件依赖) */ 107 | UPDATE_ALL_PLUGINS, 108 | 109 | /** 仅自动装配使用“+”填充版本的依赖 (插件依赖) */ 110 | ONLY_AUTOWIRE_PLUGINS, 111 | 112 | /** 自动装配和更新可选依赖 (库依赖) */ 113 | UPDATE_OPTIONAL_LIBRARIES, 114 | 115 | /** 自动装配和更新所有依赖 (库依赖) */ 116 | UPDATE_ALL_LIBRARIES, 117 | 118 | /** 仅自动装配使用“+”填充版本的依赖 (库依赖) */ 119 | ONLY_AUTOWIRE_LIBRARIES, 120 | 121 | /** 什么也不做 - 关闭所有功能 */ 122 | OFF 123 | } 124 | 125 | /** 126 | * 存储库装载模式定义类 (跟随 Gradle 进行配置调整) 127 | */ 128 | internal enum class RepositoriesMode { 129 | /** 参考 [GradleRepositoriesMode.PREFER_PROJECT] */ 130 | PREFER_PROJECT, 131 | 132 | /** 参考 [GradleRepositoriesMode.PREFER_SETTINGS] */ 133 | PREFER_SETTINGS, 134 | 135 | /** 参考 [GradleRepositoriesMode.FAIL_ON_PROJECT_REPOS] */ 136 | FAIL_ON_PROJECT_REPOS 137 | } 138 | } -------------------------------------------------------------------------------- /sweetdependency-gradle-plugin/src/main/java/com/highcapable/sweetdependency/document/VersionFilterDocument.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * SweetDependency - An easy autowire and manage dependencies Gradle plugin. 3 | * Copyright (C) 2019 HighCapable 4 | * https://github.com/HighCapable/SweetDependency 5 | * 6 | * Apache License Version 2.0 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * https://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | * 20 | * This file is created by fankes on 2023/6/9. 21 | */ 22 | package com.highcapable.sweetdependency.document 23 | 24 | import com.highcapable.sweetdependency.gradle.entity.DependencyVersion 25 | import com.highcapable.sweetdependency.manager.content.Repositories 26 | import com.highcapable.sweetdependency.utils.filter 27 | import com.highcapable.sweetdependency.utils.toSpaceList 28 | import com.highcapable.sweetdependency.utils.yaml.proxy.IYamlDocument 29 | import kotlinx.serialization.SerialName 30 | import kotlinx.serialization.Serializable 31 | 32 | /** 33 | * 版本过滤器文档实体 34 | * @param isUseInternal 使用内置过滤器 35 | * @param exclusionList 排除列表 36 | */ 37 | @Serializable 38 | internal data class VersionFilterDocument( 39 | @SerialName("use-internal") 40 | internal var isUseInternal: Boolean = true, 41 | @SerialName("exclusion-list") 42 | internal var exclusionList: String = "" 43 | ) : IYamlDocument { 44 | 45 | /** 46 | * 版本排除列表实体 47 | * @param list 当前排除列表数组 48 | */ 49 | internal class ExclusionList internal constructor(private val list: MutableList) { 50 | 51 | /** 52 | * 获取当前排除列表数组 53 | * @return [MutableList]<[String]> 54 | */ 55 | internal fun all() = list 56 | 57 | /** 58 | * 当前是否存在排除列表 59 | * @return [Boolean] 60 | */ 61 | internal fun isEmpty() = all().isEmpty() 62 | 63 | /** 64 | * 当前是否不存在排除列表 65 | * @return [Boolean] 66 | */ 67 | internal fun isNotEmpty() = !isEmpty() 68 | 69 | /** 70 | * 依赖于当前 [version] 提供的版本并在 [all] 中排除 (不区分大小写) 71 | * 72 | * 此操作会调用 [clone] 创建一个新实例并返回 73 | * @param version 当前版本 74 | * @return [ExclusionList] 75 | */ 76 | internal fun depends(version: DependencyVersion) = clone().apply { 77 | if (!version.isAutowire && !version.isBlank) all().removeAll { version.deployed.lowercase().contains(it.lowercase()) } 78 | } 79 | 80 | /** 81 | * 使用 [all] 过滤当前版本字符串 (不区分大小写) 82 | * @param versions 当前版本字符串数组 83 | * @return [MutableList]<[DependencyVersion]> 84 | */ 85 | internal fun filter(versions: MutableList) = 86 | if (all().isEmpty()) versions else versions.filter { version -> all().none { version.current.lowercase().contains(it.lowercase()) } } 87 | 88 | /** 89 | * 克隆并创建一个新实例 90 | * @return [ExclusionList] 91 | */ 92 | private fun clone() = ExclusionList(mutableListOf().apply { addAll(all()) }) 93 | 94 | override fun toString() = all().toString() 95 | } 96 | 97 | /** 98 | * 获取排除列表 99 | * @return [ExclusionList] 100 | */ 101 | internal fun exclusionList() = ExclusionList(mutableListOf().apply { 102 | if (isUseInternal) addAll(Repositories.defaultVersionFilterExclusionList) 103 | addAll(exclusionList.toSpaceList()) 104 | }) 105 | } -------------------------------------------------------------------------------- /sweetdependency-gradle-plugin/src/main/java/com/highcapable/sweetdependency/document/mapping/entity/DependencyMapping.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * SweetDependency - An easy autowire and manage dependencies Gradle plugin. 3 | * Copyright (C) 2019 HighCapable 4 | * https://github.com/HighCapable/SweetDependency 5 | * 6 | * Apache License Version 2.0 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * https://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | * 20 | * This file is created by fankes on 2023/6/1. 21 | */ 22 | package com.highcapable.sweetdependency.document.mapping.entity 23 | 24 | /** 25 | * 每项依赖测绘实体 26 | * @param notation 依赖名称或 ID 27 | * @param versionLine 版本所处行号 28 | */ 29 | internal data class DependencyMapping(internal var notation: String = "", internal var versionLine: Int = -1) -------------------------------------------------------------------------------- /sweetdependency-gradle-plugin/src/main/java/com/highcapable/sweetdependency/environment/Environment.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * SweetDependency - An easy autowire and manage dependencies Gradle plugin. 3 | * Copyright (C) 2019 HighCapable 4 | * https://github.com/HighCapable/SweetDependency 5 | * 6 | * Apache License Version 2.0 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * https://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | * 20 | * This file is created by fankes on 2023/6/28. 21 | */ 22 | package com.highcapable.sweetdependency.environment 23 | 24 | import com.highcapable.sweetdependency.SweetDependency 25 | import com.highcapable.sweetdependency.generated.SweetDependencyProperties 26 | import com.highcapable.sweetdependency.gradle.helper.GradleHelper 27 | import com.highcapable.sweetdependency.utils.toFile 28 | import java.io.File 29 | 30 | /** 31 | * [SweetDependency] 环境工具类 32 | */ 33 | internal object Environment { 34 | 35 | /** [SweetDependency] 缓存存放目录 */ 36 | private const val MEMORY_DIR_PATH = ".gradle/${SweetDependencyProperties.PROJECT_MODULE_NAME}" 37 | 38 | /** [SweetDependency] 功能存放目录 */ 39 | private const val RESOURCES_DIR_PATH = "gradle/${SweetDependencyProperties.PROJECT_MODULE_NAME}" 40 | 41 | /** 42 | * 获取 [SweetDependency] 缓存存放目录 43 | * @return [File] 44 | */ 45 | private val memoryDir get() = "${GradleHelper.rootDir.absolutePath}/$MEMORY_DIR_PATH".toFile().also { if (!it.exists()) it.mkdirs() } 46 | 47 | /** 48 | * 获取 [SweetDependency] 功能存放目录 49 | * @return [File] 50 | */ 51 | private val resourcesDir get() = "${GradleHelper.rootDir.absolutePath}/$RESOURCES_DIR_PATH".toFile().also { if (!it.exists()) it.mkdirs() } 52 | 53 | /** 54 | * 获取系统信息 55 | * @return [String] 56 | */ 57 | internal val systemInfo get() = "${System.getProperty("os.name")} ${System.getProperty("os.version")}" 58 | 59 | /** 60 | * 获取字符集名称 61 | * @return [String] 62 | */ 63 | internal val characterEncoding get() = System.getProperty("file.encoding") 64 | 65 | /** 66 | * 获取 Java 版本 67 | * @return [String] 68 | */ 69 | internal val javaVersion get() = System.getProperty("java.version") 70 | 71 | /** 72 | * 获取 [SweetDependency] 缓存存放目录 73 | * @param dirOrFileName 子路径目录、文件名称数组 74 | * @return [File] 75 | */ 76 | internal fun memoryDir(vararg dirOrFileName: String) = memoryDir.parseDir(*dirOrFileName) 77 | 78 | /** 79 | * 获取 [SweetDependency] 功能存放目录 80 | * @param dirOrFileName 子路径目录、文件名称数组 81 | * @return [File] 82 | */ 83 | internal fun resourcesDir(vararg dirOrFileName: String) = resourcesDir.parseDir(*dirOrFileName) 84 | 85 | /** 86 | * 解析 [SweetDependency] 存放目录 87 | * @param dirOrFileName 子路径目录、文件名称数组 88 | * @return [File] 89 | */ 90 | private fun File.parseDir(vararg dirOrFileName: String): File { 91 | var splitPath = "" 92 | dirOrFileName.forEach { splitPath += "$it/" } 93 | return "$absolutePath/${splitPath.ifBlank { "/" }.dropLast(1)}".toFile() 94 | } 95 | } -------------------------------------------------------------------------------- /sweetdependency-gradle-plugin/src/main/java/com/highcapable/sweetdependency/exception/SweetDependencyUnresolvedException.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * SweetDependency - An easy autowire and manage dependencies Gradle plugin. 3 | * Copyright (C) 2019 HighCapable 4 | * https://github.com/HighCapable/SweetDependency 5 | * 6 | * Apache License Version 2.0 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * https://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | * 20 | * This file is created by fankes on 2023/5/31. 21 | */ 22 | package com.highcapable.sweetdependency.exception 23 | 24 | import com.highcapable.sweetdependency.SweetDependency 25 | import com.highcapable.sweetdependency.utils.dumpToString 26 | 27 | /** 28 | * [SweetDependency] 异常定义类 29 | * @param msg 异常内容 30 | * @param parent 父级异常 - 默认空 31 | */ 32 | internal class SweetDependencyUnresolvedException internal constructor(private val msg: String, parent: Throwable? = null) : Exception( 33 | ("[${SweetDependency.TAG}] The project initialization could not be completed, please check the following for errors\n" + 34 | "If you need help, visit ${SweetDependency.PROJECT_URL}\n" + 35 | "* What went wrong:\n" + 36 | "$msg\n${if (parent != null) (when (parent) { 37 | is SweetDependencyUnresolvedException -> "* Caused by:" 38 | else -> "* Exception is:" 39 | } + "\n${parent.dumpToString()}") else ""}").trim() 40 | ) { 41 | override fun toString() = "${javaClass.simpleName}: $msg" 42 | } -------------------------------------------------------------------------------- /sweetdependency-gradle-plugin/src/main/java/com/highcapable/sweetdependency/gradle/delegate/GradleDelegate.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * SweetDependency - An easy autowire and manage dependencies Gradle plugin. 3 | * Copyright (C) 2019 HighCapable 4 | * https://github.com/HighCapable/SweetDependency 5 | * 6 | * Apache License Version 2.0 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * https://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | * 20 | * This file is created by fankes on 2023/5/26. 21 | */ 22 | package com.highcapable.sweetdependency.gradle.delegate 23 | 24 | import com.highcapable.sweetdependency.gradle.helper.GradleHelper 25 | import com.highcapable.sweetdependency.gradle.proxy.IGradleLifecycle 26 | import com.highcapable.sweetdependency.utils.debug.SError 27 | import org.gradle.api.Project 28 | import org.gradle.api.initialization.Settings 29 | 30 | /** 31 | * Gradle 代理工具类 32 | */ 33 | internal object GradleDelegate { 34 | 35 | /** 当前 Gradle 生命周期接口实例 */ 36 | private var lifecycle: IGradleLifecycle? = null 37 | 38 | /** 39 | * 创建 Gradle 生命周期 (插件) [T] 40 | * @param settings 当前设置 41 | */ 42 | internal inline fun create(settings: Settings) { 43 | runCatching { 44 | lifecycle = T::class.java.getConstructor().newInstance() 45 | }.onFailure { SError.make("Failed to create Gradle lifecycle of \"${T::class.java}\"") } 46 | GradleHelper.attach(settings) 47 | callOnSettingsLoaded(settings) 48 | settings.gradle.settingsEvaluated { callOnSettingsEvaluate(settings = this) } 49 | settings.gradle.projectsLoaded { 50 | rootProject.beforeEvaluate { callOnProjectLoaded(project = this, isRoot = true) } 51 | rootProject.afterEvaluate { callOnProjectEvaluate(project = this, isRoot = true) } 52 | rootProject.subprojects.forEach { 53 | it.beforeEvaluate { callOnProjectLoaded(project = this, isRoot = false) } 54 | it.afterEvaluate { callOnProjectEvaluate(project = this, isRoot = false) } 55 | } 56 | } 57 | } 58 | 59 | /** 60 | * 调用 Gradle 开始装载事件 61 | * @param settings 当前实例 62 | */ 63 | private fun callOnSettingsLoaded(settings: Settings) { 64 | lifecycle?.onSettingsLoaded(settings) 65 | } 66 | 67 | /** 68 | * 调用 Gradle 装载完成事件 69 | * @param settings 当前实例 70 | */ 71 | private fun callOnSettingsEvaluate(settings: Settings) { 72 | lifecycle?.onSettingsEvaluate(settings) 73 | } 74 | 75 | /** 76 | * 调用 Gradle 开始装载项目事件 77 | * @param project 当前项目 78 | * @param isRoot 是否为根项目 79 | */ 80 | private fun callOnProjectLoaded(project: Project, isRoot: Boolean) { 81 | if (isRoot) GradleHelper.cachingProjectList(project) 82 | lifecycle?.onProjectLoaded(project, isRoot) 83 | } 84 | 85 | /** 86 | * 调用 Gradle 项目装载完成事件 87 | * @param project 当前项目 88 | * @param isRoot 是否为根项目 89 | */ 90 | private fun callOnProjectEvaluate(project: Project, isRoot: Boolean) { 91 | GradleHelper.cachingDependencyList(project, isRoot) 92 | lifecycle?.onProjectEvaluate(project, isRoot) 93 | } 94 | } -------------------------------------------------------------------------------- /sweetdependency-gradle-plugin/src/main/java/com/highcapable/sweetdependency/gradle/delegate/ProjectTransaction.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * SweetDependency - An easy autowire and manage dependencies Gradle plugin. 3 | * Copyright (C) 2019 HighCapable 4 | * https://github.com/HighCapable/SweetDependency 5 | * 6 | * Apache License Version 2.0 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * https://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | * 20 | * This file is created by fankes on 2023/5/29. 21 | */ 22 | package com.highcapable.sweetdependency.gradle.delegate 23 | 24 | import org.gradle.api.Project 25 | import kotlin.properties.Delegates 26 | 27 | /** 28 | * 项目事务实例实现类 29 | */ 30 | internal class ProjectTransaction { 31 | 32 | internal companion object { 33 | 34 | /** 当前项目 (当前生命周期静态) */ 35 | internal var current by Delegates.notNull() 36 | 37 | /** 是否为根项目 (当前生命周期静态) */ 38 | internal var isRoot by Delegates.notNull() 39 | } 40 | 41 | /** 当前装载实例方法体数组 */ 42 | internal val evaluateCallbacks = mutableSetOf<((Project, Boolean) -> Unit)>() 43 | 44 | /** 45 | * 获取当前项目 46 | * @return [Project] 47 | */ 48 | internal val current get() = Companion.current 49 | 50 | /** 51 | * 获取是否为根项目 52 | * @return [Boolean] 53 | */ 54 | internal val isRoot get() = Companion.isRoot 55 | 56 | /** 57 | * 创建装载实例监听 58 | * @param evaluate 回调装载监听 - ([Project] 当前项目,[Boolean] 师傅为根项目) 59 | */ 60 | internal fun evaluation(evaluate: (project: Project, isRoot: Boolean) -> Unit) { 61 | evaluateCallbacks.add(evaluate) 62 | } 63 | } -------------------------------------------------------------------------------- /sweetdependency-gradle-plugin/src/main/java/com/highcapable/sweetdependency/gradle/delegate/entity/ExternalDependencyDelegate.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * SweetDependency - An easy autowire and manage dependencies Gradle plugin. 3 | * Copyright (C) 2019 HighCapable 4 | * https://github.com/HighCapable/SweetDependency 5 | * 6 | * Apache License Version 2.0 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * https://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | * 20 | * This file is created by fankes on 2023/6/25. 21 | */ 22 | @file:Suppress("USELESS_ELVIS", "KotlinRedundantDiagnosticSuppress") 23 | 24 | package com.highcapable.sweetdependency.gradle.delegate.entity 25 | 26 | import com.highcapable.sweetdependency.document.factory.spliceToDependencyNotation 27 | import com.highcapable.sweetdependency.gradle.entity.DependencyVersion 28 | import com.highcapable.sweetdependency.manager.GradleTaskManager 29 | import com.highcapable.sweetdependency.utils.debug.SError 30 | import org.gradle.api.internal.artifacts.dependencies.DefaultExternalModuleDependency 31 | 32 | /** 33 | * 外部存储库依赖实体代理类 34 | * 35 | * 代理 [DefaultExternalModuleDependency] 36 | * @param groupId Group ID 37 | * @param artifactId Artifact ID 38 | * @param version 版本 39 | */ 40 | internal open class ExternalDependencyDelegate internal constructor( 41 | @get:JvmName("getDelegateGroupId") 42 | @set:JvmName("setDelegateGroupId") 43 | var groupId: String, 44 | @get:JvmName("getDelegateArtifactId") 45 | @set:JvmName("setDelegateArtifactId") 46 | var artifactId: String, 47 | @get:JvmName("getDelegateVersion") 48 | @set:JvmName("setDelegateVersion") 49 | var version: String 50 | ) : DefaultExternalModuleDependency(groupId, artifactId, version) { 51 | 52 | override fun getVersion(): String { 53 | val notation = spliceToDependencyNotation(groupId, artifactId) 54 | if (version == DependencyVersion.AUTOWIRE_VERSION_NAME && !GradleTaskManager.isInternalRunningTask) SError.make( 55 | """ 56 | This library "$notation" is not autowired and cannot be deployed 57 | You can try the following solutions to resolve this problem: 58 | 1. Manually re-run Gradle Sync (make sure "autowire-on-sync-mode" not be "OFF") 59 | 2. Manually run "${GradleTaskManager.AUTOWIRE_LIBRARIES_TASK_NAME}" task and re-run Gradle Sync 60 | 3. Fill an existing version for dependency "$notation" and re-run Gradle Sync 61 | If you get this error again after doing the above, maybe the currently set repositories cannot find this library 62 | """.trimIndent() 63 | ); return super.getVersion() ?: version 64 | } 65 | 66 | override fun toString() = "ExternalDependencyDelegate(groupId = $groupId, artifactId = $artifactId, version = $version)" 67 | } -------------------------------------------------------------------------------- /sweetdependency-gradle-plugin/src/main/java/com/highcapable/sweetdependency/gradle/entity/DependencyName.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * SweetDependency - An easy autowire and manage dependencies Gradle plugin. 3 | * Copyright (C) 2019 HighCapable 4 | * https://github.com/HighCapable/SweetDependency 5 | * 6 | * Apache License Version 2.0 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * https://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | * 20 | * This file is created by fankes on 2023/8/16. 21 | */ 22 | @file:Suppress("unused", "MemberVisibilityCanBePrivate") 23 | 24 | package com.highcapable.sweetdependency.gradle.entity 25 | 26 | import com.highcapable.sweetdependency.document.factory.convertToDependencyAmbiguousName 27 | import com.highcapable.sweetdependency.document.factory.convertToDependencyUrlName 28 | import com.highcapable.sweetdependency.document.factory.spliceToDependencyNotation 29 | import com.highcapable.sweetdependency.document.factory.splitToDependencyNames 30 | import com.highcapable.sweetdependency.utils.firstNumberToLetter 31 | 32 | /** 33 | * 依赖名称实体类 34 | * @param type 名称类型 35 | * @param groupId Group ID 36 | * @param artifactId Artifact ID 37 | */ 38 | internal class DependencyName private constructor(internal val type: Type, internal val groupId: String, internal val artifactId: String) { 39 | 40 | internal companion object { 41 | 42 | /** 标识 Gradle 插件后缀名称 */ 43 | private const val GRADLE_PLUGIN_SUFFIX = "gradle.plugin" 44 | 45 | /** 46 | * 创建为插件依赖名称 47 | * @param notation 完整名称 48 | */ 49 | internal fun plugin(notation: String) = DependencyName(Type.PLUGIN, notation, "$notation.$GRADLE_PLUGIN_SUFFIX") 50 | 51 | /** 52 | * 创建为库依赖名称 53 | * @param notation 完整名称 54 | */ 55 | internal fun library(notation: String) = notation.splitToDependencyNames().let { names -> DependencyName(Type.LIBRARY, names[0], names[1]) } 56 | 57 | /** 58 | * 创建为库依赖名称 59 | * @param groupId Group ID 60 | * @param artifactId Artifact ID 61 | */ 62 | internal fun library(groupId: String, artifactId: String) = DependencyName(Type.LIBRARY, groupId, artifactId) 63 | } 64 | 65 | /** 66 | * 获取当前模糊分离名称 (使用 [symbol] 进行分离) 67 | * @param symbol 分隔符 - 默认 "." 68 | * @param isReplaceFirstChar 是否使用 [firstNumberToLetter] 替换每一段第一个字符 - 默认否 69 | * @param isLowerCase 是否全部转换为小写 - 默认是 70 | * @return [String] 71 | */ 72 | internal fun ambiguousName(symbol: String = ".", isReplaceFirstChar: Boolean = false, isLowerCase: Boolean = true) = 73 | current.convertToDependencyAmbiguousName(symbol, isReplaceFirstChar, isLowerCase) 74 | 75 | /** 76 | * 获取当前 URL 名称 77 | * @return [String] 78 | */ 79 | internal val urlName get() = notation.convertToDependencyUrlName() 80 | 81 | /** 82 | * 获取当前描述内容 83 | * @return [String] 84 | */ 85 | internal val description get() = "$typeName \"$current\"" 86 | 87 | /** 88 | * 获取当前类型名称 89 | * @return [String] 90 | */ 91 | internal val typeName get() = when (type) { 92 | Type.PLUGIN -> "Plugin" 93 | Type.LIBRARY -> "Library" 94 | } 95 | 96 | /** 97 | * 获取当前名称 98 | * @return [String] 99 | */ 100 | internal val current get() = when (type) { 101 | Type.PLUGIN -> groupId 102 | Type.LIBRARY -> notation 103 | } 104 | 105 | /** 106 | * 获取当前完整名称 107 | * @return [String] 108 | */ 109 | internal val notation get() = spliceToDependencyNotation(groupId, artifactId) 110 | 111 | override fun equals(other: Any?) = other.toString() == toString() 112 | 113 | override fun hashCode() = toString().hashCode() 114 | 115 | override fun toString() = current 116 | 117 | /** 118 | * 名称类型定义类 119 | */ 120 | internal enum class Type { 121 | /** 插件依赖 */ 122 | PLUGIN, 123 | 124 | /** 库依赖 */ 125 | LIBRARY 126 | } 127 | } -------------------------------------------------------------------------------- /sweetdependency-gradle-plugin/src/main/java/com/highcapable/sweetdependency/gradle/entity/DependencyUpdateMode.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * SweetDependency - An easy autowire and manage dependencies Gradle plugin. 3 | * Copyright (C) 2019 HighCapable 4 | * https://github.com/HighCapable/SweetDependency 5 | * 6 | * Apache License Version 2.0 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * https://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | * 20 | * This file is created by fankes on 2023/8/18. 21 | */ 22 | package com.highcapable.sweetdependency.gradle.entity 23 | 24 | /** 25 | * 依赖更新模式实体类 26 | * @param dependencyType 依赖类型 27 | * @param updateType 依赖更新模式 28 | */ 29 | internal data class DependencyUpdateMode(internal var dependencyType: DependencyType, internal var updateType: UpdateType) { 30 | 31 | /** 32 | * 依赖类型定义类 33 | */ 34 | internal enum class DependencyType { 35 | /** 全部类型 */ 36 | ALL, 37 | 38 | /** 插件依赖 */ 39 | PLUGINS, 40 | 41 | /** 库依赖 */ 42 | LIBRARIES, 43 | } 44 | 45 | /** 46 | * 依赖更新模式类型定义类 47 | */ 48 | internal enum class UpdateType { 49 | /** 可选更新 */ 50 | UPDATE_OPTIONAL, 51 | 52 | /** 全部更新 */ 53 | UPDATE_ALL, 54 | 55 | /** 仅自动装配 */ 56 | ONLY_AUTOWIRE, 57 | } 58 | } -------------------------------------------------------------------------------- /sweetdependency-gradle-plugin/src/main/java/com/highcapable/sweetdependency/gradle/entity/ExternalDependency.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * SweetDependency - An easy autowire and manage dependencies Gradle plugin. 3 | * Copyright (C) 2019 HighCapable 4 | * https://github.com/HighCapable/SweetDependency 5 | * 6 | * Apache License Version 2.0 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * https://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | * 20 | * This file is created by fankes on 2023/6/23. 21 | */ 22 | package com.highcapable.sweetdependency.gradle.entity 23 | 24 | /** 25 | * 外部存储库依赖实体类 26 | * @param dependencyName 依赖名称 27 | * @param version 版本 28 | */ 29 | internal data class ExternalDependency(private val dependencyName: DependencyName, internal val version: DependencyVersion) { 30 | 31 | /** 32 | * 获取 Group ID 33 | * @return [String] 34 | */ 35 | internal val groupId get() = dependencyName.groupId 36 | 37 | /** 38 | * 获取 Artifact ID 39 | * @return [String] 40 | */ 41 | internal val artifactId get() = dependencyName.artifactId 42 | 43 | override fun toString() = dependencyName.current 44 | } -------------------------------------------------------------------------------- /sweetdependency-gradle-plugin/src/main/java/com/highcapable/sweetdependency/gradle/factory/ExtensionAwareFactory.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * SweetDependency - An easy autowire and manage dependencies Gradle plugin. 3 | * Copyright (C) 2019 HighCapable 4 | * https://github.com/HighCapable/SweetDependency 5 | * 6 | * Apache License Version 2.0 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * https://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | * 20 | * This file is created by fankes on 2023/5/27. 21 | */ 22 | @file:Suppress("unused", "USELESS_CAST", "KotlinRedundantDiagnosticSuppress") 23 | 24 | package com.highcapable.sweetdependency.gradle.factory 25 | 26 | import com.highcapable.sweetdependency.exception.SweetDependencyUnresolvedException 27 | import com.highcapable.sweetdependency.utils.camelcase 28 | import com.highcapable.sweetdependency.utils.debug.SError 29 | import org.gradle.api.Action 30 | import org.gradle.api.plugins.ExtensionAware 31 | 32 | /** 33 | * 创建、获取扩展方法 34 | * @param name 方法名称 - 自动调用 [toSafeExtName] 35 | * @param clazz 目标对象 [Class] 36 | * @param args 方法参数 37 | * @return [ExtensionAware] 38 | */ 39 | internal fun ExtensionAware.getOrCreate(name: String, clazz: Class<*>, vararg args: Any?) = name.toSafeExtName().let { sName -> 40 | runCatching { extensions.create(sName, clazz, *args).asExtension() }.getOrElse { 41 | if (!(it is IllegalArgumentException && it.message?.startsWith("Cannot add extension with name") == true)) throw it 42 | runCatching { extensions.getByName(sName).asExtension() }.getOrNull() ?: SError.make("Create or get extension failed with name \"$sName\"") 43 | } 44 | } 45 | 46 | /** 47 | * 创建、获取扩展方法 - 目标对象 [T] 48 | * @param name 方法名称 - 自动调用 [toSafeExtName] 49 | * @param args 方法参数 50 | * @return [T] 51 | */ 52 | internal inline fun ExtensionAware.getOrCreate(name: String, vararg args: Any?) = name.toSafeExtName().let { sName -> 53 | runCatching { extensions.create(sName, T::class.java, *args) as T }.getOrElse { 54 | if (!(it is IllegalArgumentException && it.message?.startsWith("Cannot add extension with name") == true)) throw it 55 | runCatching { extensions.getByName(sName) as? T? }.getOrNull() ?: SError.make("Create or get extension failed with name \"$sName\"") 56 | } 57 | } 58 | 59 | /** 60 | * 获取扩展方法 61 | * @param name 方法名称 62 | * @return [ExtensionAware] 63 | */ 64 | internal fun ExtensionAware.get(name: String) = 65 | runCatching { extensions.getByName(name).asExtension() }.getOrNull() ?: SError.make("Could not get extension with name \"$name\"") 66 | 67 | /** 68 | * 获取扩展方法 - 目标对象 [T] 69 | * @param name 方法名称 70 | * @return [T] 71 | */ 72 | internal inline fun ExtensionAware.get(name: String) = 73 | runCatching { extensions.getByName(name) as T }.getOrNull() ?: SError.make("Could not get extension with name \"$name\"") 74 | 75 | /** 76 | * 获取扩展方法 - 目标对象 [T] 77 | * @return [T] 78 | */ 79 | internal inline fun ExtensionAware.get() = 80 | runCatching { extensions.getByType(T::class.java) as T }.getOrNull() ?: SError.make("Could not get extension with type ${T::class.java}") 81 | 82 | /** 83 | * 配置扩展方法 - 目标对象 [T] 84 | * @param name 方法名称 85 | * @param configure 配置方法体 86 | */ 87 | internal inline fun ExtensionAware.configure(name: String, configure: Action) = extensions.configure(name, configure) 88 | 89 | /** 90 | * 是否存在扩展方法 91 | * @param name 方法名称 92 | * @return [Boolean] 93 | */ 94 | internal fun ExtensionAware.hasExtension(name: String) = runCatching { extensions.getByName(name); true }.getOrNull() ?: false 95 | 96 | /** 97 | * 转换到扩展方法类型 [ExtensionAware] 98 | * @return [ExtensionAware] 99 | * @throws SweetDependencyUnresolvedException 如果类型不是 [ExtensionAware] 100 | */ 101 | internal fun Any.asExtension() = this as? ExtensionAware? ?: SError.make("This instance \"$this\" is not a valid Extension") 102 | 103 | /** 104 | * 由于 Gradle 存在一个 [ExtensionAware] 的扩展 105 | * 106 | * 此功能用于检测当前字符串是否为 Gradle 使用的关键字名称 107 | * @return [Boolean] 108 | */ 109 | internal fun String.isUnSafeExtName() = camelcase().let { it == "ext" || it == "extra" || it == "extraProperties" || it == "extensions" } 110 | 111 | /** 112 | * 由于 Gradle 存在一个 [ExtensionAware] 的扩展 113 | * 114 | * 此功能用于转换不符合规定的字符串到 "{字符串}s" 115 | * @return [String] 116 | */ 117 | internal fun String.toSafeExtName() = if (isUnSafeExtName()) "${this}s" else this -------------------------------------------------------------------------------- /sweetdependency-gradle-plugin/src/main/java/com/highcapable/sweetdependency/gradle/proxy/IGradleLifecycle.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * SweetDependency - An easy autowire and manage dependencies Gradle plugin. 3 | * Copyright (C) 2019 HighCapable 4 | * https://github.com/HighCapable/SweetDependency 5 | * 6 | * Apache License Version 2.0 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * https://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | * 20 | * This file is created by fankes on 2023/5/26. 21 | */ 22 | package com.highcapable.sweetdependency.gradle.proxy 23 | 24 | import org.gradle.api.Project 25 | import org.gradle.api.initialization.Settings 26 | 27 | /** 28 | * Gradle 生命周期接口 29 | */ 30 | internal interface IGradleLifecycle { 31 | 32 | /** 33 | * 当 Gradle 开始装载时回调 34 | * @param settings 当前设置 35 | */ 36 | fun onSettingsLoaded(settings: Settings) 37 | 38 | /** 39 | * 当 Gradle 装载完成时回调 40 | * @param settings 当前设置 41 | */ 42 | fun onSettingsEvaluate(settings: Settings) 43 | 44 | /** 45 | * 当 Gradle 开始装载项目时回调 46 | * @param project 当前项目 47 | * @param isRoot 是否为根项目 48 | */ 49 | fun onProjectLoaded(project: Project, isRoot: Boolean) 50 | 51 | /** 52 | * 当 Gradle 项目装载完成时回调 53 | * @param project 当前项目 54 | * @param isRoot 是否为根项目 55 | */ 56 | fun onProjectEvaluate(project: Project, isRoot: Boolean) 57 | } -------------------------------------------------------------------------------- /sweetdependency-gradle-plugin/src/main/java/com/highcapable/sweetdependency/gradle/wrapper/LibraryDependencyWrapper.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * SweetDependency - An easy autowire and manage dependencies Gradle plugin. 3 | * Copyright (C) 2019 HighCapable 4 | * https://github.com/HighCapable/SweetDependency 5 | * 6 | * Apache License Version 2.0 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * https://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | * 20 | * This file is created by fankes on 2023/5/28. 21 | */ 22 | @file:Suppress("USELESS_ELVIS", "KotlinRedundantDiagnosticSuppress") 23 | 24 | package com.highcapable.sweetdependency.gradle.wrapper 25 | 26 | import com.highcapable.sweetdependency.document.factory.spliceToDependencyNotation 27 | import com.highcapable.sweetdependency.gradle.delegate.entity.ExternalDependencyDelegate 28 | import com.highcapable.sweetdependency.gradle.entity.DependencyVersion 29 | import com.highcapable.sweetdependency.gradle.wrapper.type.LibraryDependencyType 30 | import org.gradle.api.Project 31 | import org.gradle.api.artifacts.Dependency 32 | import org.gradle.api.artifacts.ExternalDependency 33 | import org.gradle.api.artifacts.FileCollectionDependency 34 | import org.gradle.api.artifacts.ProjectDependency 35 | import java.io.File 36 | 37 | /** 38 | * 库依赖包装实例实现类 39 | * @param instance 当前实例 40 | * @param configurationName 配置名称 41 | */ 42 | internal data class LibraryDependencyWrapper internal constructor(private val instance: Dependency, internal val configurationName: String) { 43 | 44 | /** 45 | * 获取当前依赖类型 46 | * @return [LibraryDependencyType] 47 | */ 48 | val type 49 | get() = when (instance) { 50 | is ExternalDependencyDelegate -> LibraryDependencyType.EXTERNAL_DELEGATE 51 | is ExternalDependency -> LibraryDependencyType.EXTERNAL 52 | is ProjectDependency -> LibraryDependencyType.PROJECT 53 | is FileCollectionDependency -> LibraryDependencyType.FILES 54 | else -> LibraryDependencyType.OTHERS 55 | } 56 | 57 | /** 58 | * 依赖的文件数组 59 | * 60 | * - [type] 需要为 [LibraryDependencyType.FILES] 否则始终为 null 61 | * @return [MutableSet]<[File]> or null 62 | */ 63 | val files get() = runCatching { (instance as? FileCollectionDependency?)?.files?.files?.toMutableSet() }.getOrNull() 64 | 65 | /** 66 | * 依赖的项目 67 | * 68 | * - [type] 需要为 [LibraryDependencyType.PROJECT] 否则始终为 null 69 | * @return [Project] or null 70 | */ 71 | val project get() = runCatching { (instance as? ProjectDependency?)?.dependencyProject }.getOrNull() 72 | 73 | /** 74 | * Group ID 75 | * @return [String] 76 | */ 77 | val groupId get() = instance.group ?: "" 78 | 79 | /** 80 | * Artifact ID 81 | * @return [String] 82 | */ 83 | val artifactId get() = instance.name ?: "" 84 | 85 | /** 86 | * 版本 87 | * @return [DependencyVersion] 88 | */ 89 | val version get() = DependencyVersion(instance.version ?: "") 90 | 91 | override fun toString() = spliceToDependencyNotation(groupId, artifactId) 92 | } -------------------------------------------------------------------------------- /sweetdependency-gradle-plugin/src/main/java/com/highcapable/sweetdependency/gradle/wrapper/PluginDependencyWrapper.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * SweetDependency - An easy autowire and manage dependencies Gradle plugin. 3 | * Copyright (C) 2019 HighCapable 4 | * https://github.com/HighCapable/SweetDependency 5 | * 6 | * Apache License Version 2.0 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * https://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | * 20 | * This file is created by fankes on 2023/8/17. 21 | */ 22 | package com.highcapable.sweetdependency.gradle.wrapper 23 | 24 | import org.gradle.api.Plugin 25 | 26 | /** 27 | * 插件依赖包装实例实现类 28 | * @param instance 当前实例 29 | * @param id 插件 ID 30 | */ 31 | internal data class PluginDependencyWrapper internal constructor(private val instance: Plugin<*>, internal val id: String) { 32 | 33 | override fun toString() = id 34 | } -------------------------------------------------------------------------------- /sweetdependency-gradle-plugin/src/main/java/com/highcapable/sweetdependency/gradle/wrapper/type/LibraryDependencyType.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * SweetDependency - An easy autowire and manage dependencies Gradle plugin. 3 | * Copyright (C) 2019 HighCapable 4 | * https://github.com/HighCapable/SweetDependency 5 | * 6 | * Apache License Version 2.0 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * https://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | * 20 | * This file is created by fankes on 2023/6/10. 21 | */ 22 | package com.highcapable.sweetdependency.gradle.wrapper.type 23 | 24 | /** 25 | * 库依赖类型定义类 26 | */ 27 | internal enum class LibraryDependencyType { 28 | /** 其它类型 */ 29 | OTHERS, 30 | 31 | /** 外部存储库 */ 32 | EXTERNAL, 33 | 34 | /** 外部存储库 (代理) */ 35 | EXTERNAL_DELEGATE, 36 | 37 | /** 项目 */ 38 | PROJECT, 39 | 40 | /** 文件 */ 41 | FILES 42 | } -------------------------------------------------------------------------------- /sweetdependency-gradle-plugin/src/main/java/com/highcapable/sweetdependency/manager/const/AdditionalRepositories.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * SweetDependency - An easy autowire and manage dependencies Gradle plugin. 3 | * Copyright (C) 2019 HighCapable 4 | * https://github.com/HighCapable/SweetDependency 5 | * 6 | * Apache License Version 2.0 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * https://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | * 20 | * This file is created by fankes on 2023/5/16. 21 | */ 22 | package com.highcapable.sweetdependency.manager.const 23 | 24 | /** 25 | * 附加常用第三方存储库 26 | */ 27 | internal object AdditionalRepositories { 28 | 29 | /** 中央存储库 (分流) */ 30 | const val MAVEN_CENTRAL_BRANCH = "https://repo1.maven.org/maven2" 31 | 32 | /** JitPack */ 33 | const val JITPACK = "https://www.jitpack.io" 34 | 35 | /** OSS Release */ 36 | const val SONATYPE_OSS_RELEASES = "https://s01.oss.sonatype.org/content/repositories/releases" 37 | 38 | /** OSS Snapshots */ 39 | const val SONATYPE_OSS_SNAPSHOTS = "https://s01.oss.sonatype.org/content/repositories/snapshots" 40 | 41 | /** 阿里云 Google 存储库镜像 */ 42 | const val ALIYUN_GOOGLE_MIRROR = "https://maven.aliyun.com/repository/google" 43 | 44 | /** 阿里云中央存储库镜像 */ 45 | const val ALIYUN_MAVEN_CENTRAL_MIRROR = "https://maven.aliyun.com/repository/central" 46 | 47 | /** 阿里云公共存储库镜像 */ 48 | const val ALIYUN_MAVEN_PUBLIC_MIRROR = "https://maven.aliyun.com/repository/public" 49 | 50 | /** 阿里云 JCenter 镜像 */ 51 | const val ALIYUN_JCENTER_MIRROR = "https://maven.aliyun.com/nexus/content/repositories/jcenter" 52 | 53 | /** 54 | * 存储库简洁名称定义类 55 | */ 56 | internal object Name { 57 | 58 | /** 中央存储库 (分流) */ 59 | const val MAVEN_CENTRAL_BRANCH = "maven-central-branch" 60 | 61 | /** JitPack */ 62 | const val JITPACK = "jit-pack" 63 | 64 | /** OSS Release */ 65 | const val SONATYPE_OSS_RELEASES = "sonatype-oss-releases" 66 | 67 | /** OSS Snapshots */ 68 | const val SONATYPE_OSS_SNAPSHOTS = "sonatype-oss-snapshots" 69 | 70 | /** 阿里云 Google 存储库镜像 */ 71 | const val ALIYUN_GOOGLE_MIRROR = "aliyun-google-mirror" 72 | 73 | /** 阿里云中央存储库镜像 */ 74 | const val ALIYUN_MAVEN_CENTRAL_MIRROR = "aliyun-maven-central-mirror" 75 | 76 | /** 阿里云公共存储库镜像 */ 77 | const val ALIYUN_MAVEN_PUBLIC_MIRROR = "aliyun-maven-public-mirror" 78 | 79 | /** 阿里云 JCenter 镜像 */ 80 | const val ALIYUN_JCENTER_MIRROR = "aliyun-jcenter-mirror" 81 | } 82 | } -------------------------------------------------------------------------------- /sweetdependency-gradle-plugin/src/main/java/com/highcapable/sweetdependency/manager/const/InternalRepositories.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * SweetDependency - An easy autowire and manage dependencies Gradle plugin. 3 | * Copyright (C) 2019 HighCapable 4 | * https://github.com/HighCapable/SweetDependency 5 | * 6 | * Apache License Version 2.0 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * https://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | * 20 | * This file is created by fankes on 2023/5/18. 21 | */ 22 | package com.highcapable.sweetdependency.manager.const 23 | 24 | /** 25 | * 内置存储库 26 | */ 27 | internal object InternalRepositories { 28 | 29 | /** 本地 Maven 存储库相对路径 */ 30 | const val MAVEN_LOCAL_RELATIVE_PATH = ".m2/repository" 31 | 32 | /** Google Maven */ 33 | const val GOOGLE = "https://dl.google.com/dl/android/maven2" 34 | 35 | /** 中央存储库 */ 36 | const val MAVEN_CENTRAL = "https://repo.maven.apache.org/maven2" 37 | 38 | /** Gradle Plugin 存储库 */ 39 | const val GRADLE_PLUGIN_PORTAL = "https://plugins.gradle.org/m2" 40 | 41 | /** 42 | * 存储库简洁名称定义类 43 | */ 44 | internal object Name { 45 | 46 | /** Google Maven */ 47 | const val GOOGLE = "google" 48 | 49 | /** 中央存储库 */ 50 | const val MAVEN_CENTRAL = "maven-central" 51 | 52 | /** 本地 Maven 存储库 */ 53 | const val MAVEN_LOCAL = "maven-local" 54 | 55 | /** Maven 存储库 */ 56 | const val MAVEN = "maven" 57 | 58 | /** Ivy 存储库 */ 59 | const val IVY = "ivy" 60 | 61 | /** Gradle Plugin 存储库 */ 62 | const val GRADLE_PLUGIN_PORTAL = "gradle-plugin-portal" 63 | } 64 | } -------------------------------------------------------------------------------- /sweetdependency-gradle-plugin/src/main/java/com/highcapable/sweetdependency/manager/content/Dependencies.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * SweetDependency - An easy autowire and manage dependencies Gradle plugin. 3 | * Copyright (C) 2019 HighCapable 4 | * https://github.com/HighCapable/SweetDependency 5 | * 6 | * Apache License Version 2.0 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * https://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | * 20 | * This file is created by fankes on 2023/6/25. 21 | */ 22 | @file:Suppress("unused", "MemberVisibilityCanBePrivate") 23 | 24 | package com.highcapable.sweetdependency.manager.content 25 | 26 | import com.highcapable.sweetdependency.document.DependencyDocument 27 | import com.highcapable.sweetdependency.document.factory.DependenciesCondition 28 | import com.highcapable.sweetdependency.document.factory.DependencyMap 29 | import com.highcapable.sweetdependency.gradle.entity.DependencyName 30 | import com.highcapable.sweetdependency.utils.filter 31 | 32 | /** 33 | * 已添加的依赖管理类 34 | */ 35 | internal object Dependencies { 36 | 37 | /** 当前已添加的全部插件依赖数组 */ 38 | private val pluginEntries = mutableMapOf() 39 | 40 | /** 当前已添加的全部库依赖数组 */ 41 | private val libraryEntries = mutableMapOf() 42 | 43 | /** 标识当前是否为已过期状态 */ 44 | private var isMarkedOutdate = true 45 | 46 | /** 47 | * 获取当前过期状态 48 | * @return [Boolean] 49 | */ 50 | internal val isOutdate get() = isMarkedOutdate 51 | 52 | /** 53 | * 刷新当前缓存数据状态 54 | * @param isOutdate 是否标识为已过期 55 | */ 56 | internal fun refreshState(isOutdate: Boolean) { 57 | isMarkedOutdate = isOutdate 58 | } 59 | 60 | /** 61 | * 获取当前全部数组 62 | * @return [DependencyMap] 63 | */ 64 | internal fun all() = (pluginEntries + libraryEntries).toMutableMap() 65 | 66 | /** 67 | * 获取当前插件依赖数组 68 | * @return [DependencyMap] 69 | */ 70 | internal fun plugins() = pluginEntries 71 | 72 | /** 73 | * 获取当前库依赖数组 74 | * @return [DependencyMap] 75 | */ 76 | internal fun libraries() = libraryEntries 77 | 78 | /** 79 | * 当前是否存在依赖 80 | * @return [Boolean] 81 | */ 82 | internal fun isEmpty() = all().isEmpty() 83 | 84 | /** 85 | * 当前是否不存在依赖 86 | * @return [Boolean] 87 | */ 88 | internal fun isNotEmpty() = !isEmpty() 89 | 90 | /** 91 | * 查找是否存在指定的依赖 92 | * @param condition 条件方法体 93 | * @return [Boolean] 94 | */ 95 | internal inline fun hasAll(condition: DependenciesCondition) = findAll { key, value -> condition(key, value) }.isNotEmpty() 96 | 97 | /** 98 | * 查找是否存在指定的插件依赖 99 | * @param condition 条件方法体 100 | * @return [Boolean] 101 | */ 102 | internal inline fun hasPlugin(condition: DependenciesCondition) = findPlugins { key, value -> condition(key, value) }.isNotEmpty() 103 | 104 | /** 105 | * 查找是否存在指定的库依赖 106 | * @param condition 条件方法体 107 | * @return [Boolean] 108 | */ 109 | internal inline fun hasLibrary(condition: DependenciesCondition) = findLibraries { key, value -> condition(key, value) }.isNotEmpty() 110 | 111 | /** 112 | * 查找指定条件的依赖数组 113 | * @param condition 条件方法体 114 | * @return [DependencyMap] 115 | */ 116 | internal inline fun findAll(condition: DependenciesCondition) = all().filter { condition(it.key, it.value) } 117 | 118 | /** 119 | * 查找指定条件的插件依赖数组 120 | * @param condition 条件方法体 121 | * @return [DependencyMap] 122 | */ 123 | internal inline fun findPlugins(condition: DependenciesCondition) = plugins().filter { condition(it.key, it.value) } 124 | 125 | /** 126 | * 查找指定条件的库依赖数组 127 | * @param condition 条件方法体 128 | * @return [DependencyMap] 129 | */ 130 | internal inline fun findLibraries(condition: DependenciesCondition) = libraries().filter { condition(it.key, it.value) } 131 | 132 | /** 133 | * 生成依赖数组 134 | * @param plugins 插件依赖数组 135 | * @param libraries 依赖数组 136 | */ 137 | internal fun generate(plugins: DependencyMap, libraries: DependencyMap) { 138 | if (plugins == plugins() && libraries == libraries()) return refreshState(isOutdate = false) 139 | resetData() 140 | plugins().putAll(plugins) 141 | libraries().putAll(libraries) 142 | } 143 | 144 | /** 重置 (清空) 当前依赖数组 */ 145 | private fun resetData() { 146 | pluginEntries.clear() 147 | libraryEntries.clear() 148 | refreshState(isOutdate = true) 149 | } 150 | } -------------------------------------------------------------------------------- /sweetdependency-gradle-plugin/src/main/java/com/highcapable/sweetdependency/manager/content/Repositories.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * SweetDependency - An easy autowire and manage dependencies Gradle plugin. 3 | * Copyright (C) 2019 HighCapable 4 | * https://github.com/HighCapable/SweetDependency 5 | * 6 | * Apache License Version 2.0 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * https://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | * 20 | * This file is created by fankes on 2023/5/16. 21 | */ 22 | package com.highcapable.sweetdependency.manager.content 23 | 24 | import com.highcapable.sweetdependency.document.RepositoryDocument 25 | import com.highcapable.sweetdependency.document.factory.RepositoryList 26 | import com.highcapable.sweetdependency.manager.const.AdditionalRepositories 27 | import com.highcapable.sweetdependency.manager.const.InternalRepositories 28 | import com.highcapable.sweetdependency.utils.parseFileSeparator 29 | 30 | /** 31 | * 已添加的存储库管理类 32 | */ 33 | internal object Repositories { 34 | 35 | /** 默认本地 Maven 存储库路径 */ 36 | internal val defaultMavenLocalPath by lazy { 37 | "${System.getProperty("user.home")}/${InternalRepositories.MAVEN_LOCAL_RELATIVE_PATH}".parseFileSeparator() 38 | } 39 | 40 | /** 默认版本过滤器排除列表数组 */ 41 | internal val defaultVersionFilterExclusionList = arrayOf("-beta", "-alpha", "-dev", "-canary", "-pre", "-rc", "-ga", "-snapshot") 42 | 43 | /** 当前已添加的全部存储库数组 */ 44 | private val entries = mutableListOf() 45 | 46 | /** 47 | * 获取当前存储库数组 48 | * @return [MutableList]<[RepositoryDocument]> 49 | */ 50 | internal fun all() = entries 51 | 52 | /** 53 | * 当前是否存在存储库 54 | * @return [Boolean] 55 | */ 56 | internal fun isEmpty() = all().isEmpty() 57 | 58 | /** 59 | * 当前是否不存在存储库 60 | * @return [Boolean] 61 | */ 62 | internal fun isNotEmpty() = !isEmpty() 63 | 64 | /** 65 | * 生成存储库数组 66 | * @param repositories 存储库数组 67 | */ 68 | internal fun generate(repositories: RepositoryList) { 69 | if (repositories == all()) return 70 | resetData() 71 | all().addAll(repositories) 72 | } 73 | 74 | /** 75 | * 查找可用的存储库名 URL 地址 76 | * @param name 存储库名 77 | * @return [String] 78 | */ 79 | internal fun findAdditional(name: String) = when (name) { 80 | AdditionalRepositories.Name.MAVEN_CENTRAL_BRANCH -> AdditionalRepositories.MAVEN_CENTRAL_BRANCH 81 | AdditionalRepositories.Name.JITPACK -> AdditionalRepositories.JITPACK 82 | AdditionalRepositories.Name.SONATYPE_OSS_RELEASES -> AdditionalRepositories.SONATYPE_OSS_RELEASES 83 | AdditionalRepositories.Name.SONATYPE_OSS_SNAPSHOTS -> AdditionalRepositories.SONATYPE_OSS_SNAPSHOTS 84 | AdditionalRepositories.Name.ALIYUN_GOOGLE_MIRROR -> AdditionalRepositories.ALIYUN_GOOGLE_MIRROR 85 | AdditionalRepositories.Name.ALIYUN_MAVEN_CENTRAL_MIRROR -> AdditionalRepositories.ALIYUN_MAVEN_CENTRAL_MIRROR 86 | AdditionalRepositories.Name.ALIYUN_MAVEN_PUBLIC_MIRROR -> AdditionalRepositories.ALIYUN_MAVEN_PUBLIC_MIRROR 87 | AdditionalRepositories.Name.ALIYUN_JCENTER_MIRROR -> AdditionalRepositories.ALIYUN_JCENTER_MIRROR 88 | else -> "" 89 | } 90 | 91 | /** 重置 (清空) 当前存储库数组 */ 92 | private fun resetData() = entries.clear() 93 | } -------------------------------------------------------------------------------- /sweetdependency-gradle-plugin/src/main/java/com/highcapable/sweetdependency/manager/helper/DependencyAutowireLogHelper.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * SweetDependency - An easy autowire and manage dependencies Gradle plugin. 3 | * Copyright (C) 2019 HighCapable 4 | * https://github.com/HighCapable/SweetDependency 5 | * 6 | * Apache License Version 2.0 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * https://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | * 20 | * This file is created by fankes on 2023/5/21. 21 | */ 22 | package com.highcapable.sweetdependency.manager.helper 23 | 24 | import com.highcapable.sweetdependency.environment.Environment 25 | import com.highcapable.sweetdependency.gradle.entity.DependencyName 26 | import com.highcapable.sweetdependency.gradle.entity.DependencyVersion 27 | import com.highcapable.sweetdependency.plugin.config.content.SweetDependencyConfigs 28 | import com.highcapable.sweetdependency.utils.debug.SLog 29 | import java.text.SimpleDateFormat 30 | import java.util.* 31 | 32 | /** 33 | * 依赖自动装配日志工具类 34 | */ 35 | internal object DependencyAutowireLogHelper { 36 | 37 | /** 当前日志文件名 */ 38 | private const val LOG_FILE_NAME = "dependencies-autowire.log" 39 | 40 | /** 41 | * 当前日志文件 42 | * @return [String] 43 | */ 44 | internal val logFile get() = Environment.memoryDir(LOG_FILE_NAME) 45 | 46 | /** 47 | * 记录当前依赖改变 48 | * @param dependencyName 依赖名称 49 | * @param fromVersion 起始版本 50 | * @param toVersion 最终版本 51 | */ 52 | internal fun record(dependencyName: DependencyName, fromVersion: DependencyVersion, toVersion: DependencyVersion) { 53 | if (!SweetDependencyConfigs.configs.isEnableDependenciesAutowireLog) return 54 | val versionInfo = if (fromVersion.isAutowire) 55 | "autowire version \"$toVersion\"" 56 | else "update version \"$fromVersion\" -> \"$toVersion\"" 57 | logFile.runCatching { 58 | appendText("[${SimpleDateFormat.getDateTimeInstance().format(Date())}] ${dependencyName.description} $versionInfo\n") 59 | }.onFailure { SLog.error("Failed to written log file \"$logFile\"\n$it") } 60 | } 61 | } -------------------------------------------------------------------------------- /sweetdependency-gradle-plugin/src/main/java/com/highcapable/sweetdependency/manager/maven/MavenParser.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * SweetDependency - An easy autowire and manage dependencies Gradle plugin. 3 | * Copyright (C) 2019 HighCapable 4 | * https://github.com/HighCapable/SweetDependency 5 | * 6 | * Apache License Version 2.0 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * https://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | * 20 | * This file is created by fankes on 2023/6/6. 21 | */ 22 | package com.highcapable.sweetdependency.manager.maven 23 | 24 | import com.highcapable.sweetdependency.document.RepositoryDocument 25 | import com.highcapable.sweetdependency.gradle.entity.DependencyName 26 | import com.highcapable.sweetdependency.gradle.entity.DependencyVersion 27 | import com.highcapable.sweetdependency.gradle.helper.GradleHelper 28 | import com.highcapable.sweetdependency.manager.maven.entity.MavenMetadata 29 | import com.highcapable.sweetdependency.utils.debug.SError 30 | import com.highcapable.sweetdependency.utils.executeFileBody 31 | import com.highcapable.sweetdependency.utils.executeUrlBody 32 | import com.highcapable.sweetdependency.utils.noEmpty 33 | import org.xml.sax.InputSource 34 | import java.io.StringReader 35 | import javax.xml.parsers.DocumentBuilderFactory 36 | 37 | /** 38 | * Maven 解析器工具类 39 | */ 40 | internal object MavenParser { 41 | 42 | /** 依赖配置文件名 */ 43 | private const val METADATA_FILE_NAME = "maven-metadata.xml" 44 | 45 | /** 依赖配置文件名 (本地) */ 46 | private const val METADATA_LOCAL_FILE_NAME = "maven-metadata-local.xml" 47 | 48 | /** 49 | * 通过依赖全称使用指定存储库得到 [MavenMetadata] 实体 50 | * @param dependencyName 依赖名称 51 | * @param repo 当前存储库实体 52 | * @param currentVersion 当前依赖版本 53 | * @return [MavenMetadata] 54 | */ 55 | internal fun acquire(dependencyName: DependencyName, repo: RepositoryDocument, currentVersion: DependencyVersion): MavenMetadata { 56 | val headerUrlOrPath = "${repo.url.ifBlank { repo.path }}/${dependencyName.urlName}/" 57 | val isIncludeScope = repo.isIncludeScope(dependencyName.type == DependencyName.Type.PLUGIN) 58 | /** 离线模式下不会自动装配、更新在线依赖 */ 59 | if (isIncludeScope && GradleHelper.isOfflineMode) return MavenMetadata() 60 | var currentUrl: String 61 | return when { 62 | repo.url.isNotBlank() -> "$headerUrlOrPath$METADATA_FILE_NAME" 63 | .apply { currentUrl = this } 64 | .executeUrlBody(repo.credentials.username, repo.credentials.password) 65 | repo.path.isNotBlank() -> "$headerUrlOrPath$METADATA_LOCAL_FILE_NAME" 66 | .apply { currentUrl = this } 67 | .executeFileBody() 68 | else -> SError.make("Could not resolve this repository \"${repo.nodeName}\"") 69 | }.trim().toMetadata(currentUrl, currentVersion) 70 | } 71 | 72 | /** 73 | * 解析 [METADATA_FILE_NAME]、[METADATA_LOCAL_FILE_NAME] 内容到 [MavenMetadata] 实体 74 | * @param url 当前依赖获取 URL 75 | * @param currentVersion 当前依赖版本 76 | * @return [MavenMetadata] 77 | */ 78 | private fun String.toMetadata(url: String, currentVersion: DependencyVersion) = runCatching { 79 | if (!(contains("")) || !endsWith("")) return@runCatching MavenMetadata(url) 80 | DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(InputSource(StringReader(this))).let { document -> 81 | val lastUpdated = document.getElementsByTagName("lastUpdated").item(0)?.textContent?.toLongOrNull() ?: 0L 82 | val versionNodeList = document.getElementsByTagName("version") 83 | val versions = mutableListOf() 84 | for (i in 0..versionNodeList.length) versionNodeList.item(i)?.textContent?.also { versions.add(currentVersion.clone(it)) } 85 | MavenMetadata(url, versions.noEmpty()?.reversed()?.toMutableList() ?: mutableListOf(), lastUpdated) 86 | } 87 | }.getOrNull() ?: MavenMetadata(url) 88 | } -------------------------------------------------------------------------------- /sweetdependency-gradle-plugin/src/main/java/com/highcapable/sweetdependency/manager/maven/entity/MavenMetadata.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * SweetDependency - An easy autowire and manage dependencies Gradle plugin. 3 | * Copyright (C) 2019 HighCapable 4 | * https://github.com/HighCapable/SweetDependency 5 | * 6 | * Apache License Version 2.0 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * https://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | * 20 | * This file is created by fankes on 2023/6/6. 21 | */ 22 | package com.highcapable.sweetdependency.manager.maven.entity 23 | 24 | import com.highcapable.sweetdependency.gradle.entity.DependencyVersion 25 | 26 | /** 27 | * Maven Metadata 实体 28 | * @param url 依赖获取 URL 29 | * @param versions 版本数组 30 | * @param lastUpdated 最后更新时间戳 31 | */ 32 | internal data class MavenMetadata( 33 | internal var url: String = "", 34 | internal var versions: MutableList = mutableListOf(), 35 | internal var lastUpdated: Long = 0L 36 | ) -------------------------------------------------------------------------------- /sweetdependency-gradle-plugin/src/main/java/com/highcapable/sweetdependency/plugin/SweetDependencyExtension.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * SweetDependency - An easy autowire and manage dependencies Gradle plugin. 3 | * Copyright (C) 2019 HighCapable 4 | * https://github.com/HighCapable/SweetDependency 5 | * 6 | * Apache License Version 2.0 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * https://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | * 20 | * This file is created by fankes on 2023/5/19. 21 | */ 22 | package com.highcapable.sweetdependency.plugin 23 | 24 | import com.highcapable.sweetdependency.SweetDependency 25 | import com.highcapable.sweetdependency.gradle.delegate.ProjectTransaction 26 | import com.highcapable.sweetdependency.gradle.factory.getOrCreate 27 | import com.highcapable.sweetdependency.gradle.proxy.IGradleLifecycle 28 | import com.highcapable.sweetdependency.manager.GradleTaskManager 29 | import com.highcapable.sweetdependency.plugin.extension.dsl.configure.SweetDependencyConfigureExtension 30 | import com.highcapable.sweetdependency.plugin.impl.SweetDependencyExtensionImpl 31 | import com.highcapable.sweetdependency.utils.debug.SError 32 | import org.gradle.api.Project 33 | import org.gradle.api.initialization.Settings 34 | 35 | /** 36 | * [SweetDependency] 插件扩展类 37 | */ 38 | internal class SweetDependencyExtension internal constructor() : IGradleLifecycle { 39 | 40 | /** 当前配置方法体实例 */ 41 | private var configure: SweetDependencyConfigureExtension? = null 42 | 43 | /** 当前扩展实现实例 */ 44 | private var impl: SweetDependencyExtensionImpl? = null 45 | 46 | /** 当前项目事务实例 */ 47 | private var transaction: ProjectTransaction? = null 48 | 49 | override fun onSettingsLoaded(settings: Settings) { 50 | configure = settings.getOrCreate(SweetDependencyConfigureExtension.NAME) 51 | } 52 | 53 | override fun onSettingsEvaluate(settings: Settings) { 54 | impl = SweetDependencyExtensionImpl() 55 | impl?.onInitialization(settings, configure?.build() ?: SError.make("Settings lifecycle is broken")) 56 | } 57 | 58 | override fun onProjectLoaded(project: Project, isRoot: Boolean) { 59 | ProjectTransaction.current = project 60 | ProjectTransaction.isRoot = isRoot 61 | if (transaction == null) transaction = ProjectTransaction() 62 | if (isRoot) GradleTaskManager.register(project) 63 | transaction?.also { impl?.onTransaction(it) } 64 | } 65 | 66 | override fun onProjectEvaluate(project: Project, isRoot: Boolean) { 67 | transaction?.evaluateCallbacks?.forEach { it(project, isRoot) } 68 | } 69 | } -------------------------------------------------------------------------------- /sweetdependency-gradle-plugin/src/main/java/com/highcapable/sweetdependency/plugin/SweetDependencyPlugin.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * SweetDependency - An easy autowire and manage dependencies Gradle plugin. 3 | * Copyright (C) 2019 HighCapable 4 | * https://github.com/HighCapable/SweetDependency 5 | * 6 | * Apache License Version 2.0 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * https://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | * 20 | * This file is created by fankes on 2023/5/16. 21 | */ 22 | @file:Suppress("unused") 23 | 24 | package com.highcapable.sweetdependency.plugin 25 | 26 | import com.highcapable.sweetdependency.SweetDependency 27 | import com.highcapable.sweetdependency.gradle.delegate.GradleDelegate 28 | import com.highcapable.sweetdependency.utils.debug.SError 29 | import org.gradle.api.Plugin 30 | import org.gradle.api.initialization.Settings 31 | import org.gradle.api.plugins.ExtensionAware 32 | 33 | /** 34 | * [SweetDependency] 插件定义类 35 | */ 36 | class SweetDependencyPlugin internal constructor() : Plugin { 37 | 38 | override fun apply(target: T) = when (target) { 39 | is Settings -> GradleDelegate.create(target) 40 | else -> SError.make("${SweetDependency.TAG} can only applied in settings.gradle or settings.gradle.kts, but current is $target") 41 | } 42 | } -------------------------------------------------------------------------------- /sweetdependency-gradle-plugin/src/main/java/com/highcapable/sweetdependency/plugin/config/content/SweetDependencyConfigs.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * SweetDependency - An easy autowire and manage dependencies Gradle plugin. 3 | * Copyright (C) 2019 HighCapable 4 | * https://github.com/HighCapable/SweetDependency 5 | * 6 | * Apache License Version 2.0 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * https://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | * 20 | * This file is created by fankes on 2023/6/29. 21 | */ 22 | package com.highcapable.sweetdependency.plugin.config.content 23 | 24 | import com.highcapable.sweetdependency.SweetDependency 25 | import com.highcapable.sweetdependency.document.RootConfigDocument 26 | import com.highcapable.sweetdependency.document.mapping.RootConfigDocumentMapping 27 | import com.highcapable.sweetdependency.exception.SweetDependencyUnresolvedException 28 | import com.highcapable.sweetdependency.plugin.config.factory.build 29 | import com.highcapable.sweetdependency.plugin.config.proxy.ISweetDependencyConfigs 30 | import com.highcapable.sweetdependency.utils.debug.SError 31 | import com.highcapable.sweetdependency.utils.debug.SLog 32 | import com.highcapable.sweetdependency.utils.yaml.factory.YamlException 33 | import kotlin.properties.Delegates 34 | 35 | /** 36 | * [SweetDependency] 配置类实现类 37 | */ 38 | internal object SweetDependencyConfigs { 39 | 40 | /** 当前配置 */ 41 | internal var configs by Delegates.notNull() 42 | 43 | /** 当前文档实体 */ 44 | internal var document by Delegates.notNull() 45 | 46 | /** 当前文档测绘实例 */ 47 | internal var documentMapping by Delegates.notNull() 48 | 49 | /** 50 | * 插件启用后执行 51 | * @param block 方法体 52 | */ 53 | internal inline fun withPluginEnable(block: () -> Unit) { 54 | if (configs.isEnable) block() else SLog.warn("${SweetDependency.TAG} is disabled (won't do anything)", noRepeat = true) 55 | } 56 | 57 | /** 58 | * 初始化配置 (从文件) 59 | * @param configs 当前配置 60 | * @param isThrowOnError 是否在发生错误的时候抛出异常 - 默认是 61 | * @throws SweetDependencyUnresolvedException 如果设置了 [isThrowOnError] 且发生错误 62 | */ 63 | internal fun initialize(configs: ISweetDependencyConfigs, isThrowOnError: Boolean = true) { 64 | this.configs = configs 65 | runCatching { 66 | configs.build().also { 67 | document = it.first 68 | documentMapping = it.second 69 | } 70 | }.onFailure { 71 | if (isThrowOnError) when (it) { 72 | is YamlException -> SError.make("Failed to parse config file: ${configs.configFilePath}\nPlease check if there are syntax errors", it) 73 | is SweetDependencyUnresolvedException -> throw it 74 | else -> SError.make("Failed to load config file: ${configs.configFilePath}", it) 75 | } 76 | } 77 | } 78 | } -------------------------------------------------------------------------------- /sweetdependency-gradle-plugin/src/main/java/com/highcapable/sweetdependency/plugin/config/factory/SweetDependencyConfigsFactory.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * SweetDependency - An easy autowire and manage dependencies Gradle plugin. 3 | * Copyright (C) 2019 HighCapable 4 | * https://github.com/HighCapable/SweetDependency 5 | * 6 | * Apache License Version 2.0 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * https://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | * 20 | * This file is created by fankes on 2023/5/21. 21 | */ 22 | package com.highcapable.sweetdependency.plugin.config.factory 23 | 24 | import com.highcapable.sweetdependency.document.RootConfigDocument 25 | import com.highcapable.sweetdependency.document.mapping.RootConfigDocumentMapping 26 | import com.highcapable.sweetdependency.plugin.config.proxy.ISweetDependencyConfigs 27 | import com.highcapable.sweetdependency.utils.debug.SError 28 | import com.highcapable.sweetdependency.utils.debug.SLog 29 | import com.highcapable.sweetdependency.utils.toFile 30 | import com.highcapable.sweetdependency.utils.yaml.Yaml 31 | import java.io.File 32 | 33 | /** 34 | * 获取并解析配置文件 [RootConfigDocument] 实体和 [RootConfigDocumentMapping] 35 | * @return [Pair]<[RootConfigDocument], [RootConfigDocumentMapping]> 36 | */ 37 | internal fun ISweetDependencyConfigs.build() = configFilePath.loadOrCreateEmpty() to RootConfigDocumentMapping(this) 38 | 39 | /** 40 | * 通过字符串路径获取或创建配置文件 [RootConfigDocument] 实体 41 | * @return [RootConfigDocument] 42 | */ 43 | private fun String.loadOrCreateEmpty(): RootConfigDocument { 44 | toFile().apply { 45 | if (!name.endsWith(".yaml") && !name.endsWith(".yml")) 46 | SError.make("Config file name must be end with \".yaml\" or \".yml\"") 47 | }.createTemplateFileOrNot() 48 | return Yaml.loadFromFile(path = this) 49 | } 50 | 51 | /** 自动创建模版配置文件 */ 52 | private fun File.createTemplateFileOrNot() { 53 | fun createTemplateFile() { 54 | writeText(RootConfigDocument.defaultContent) 55 | SLog.info("Automatically created config file: $absolutePath") 56 | } 57 | runCatching { 58 | when { 59 | !exists() && !parentFile.exists() -> { 60 | parentFile.mkdirs() 61 | createTemplateFile() 62 | } 63 | !exists() -> createTemplateFile() 64 | exists() && isDirectory -> SError.make("Tries to create file path is a directory") 65 | } 66 | }.onFailure { SError.make("Could not automatically created config file: $absolutePath", it) } 67 | } -------------------------------------------------------------------------------- /sweetdependency-gradle-plugin/src/main/java/com/highcapable/sweetdependency/plugin/config/proxy/ISweetDependencyConfigs.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * SweetDependency - An easy autowire and manage dependencies Gradle plugin. 3 | * Copyright (C) 2019 HighCapable 4 | * https://github.com/HighCapable/SweetDependency 5 | * 6 | * Apache License Version 2.0 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * https://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | * 20 | * This file is created by fankes on 2023/5/18. 21 | */ 22 | package com.highcapable.sweetdependency.plugin.config.proxy 23 | 24 | import com.highcapable.sweetdependency.SweetDependency 25 | import org.gradle.api.initialization.Settings 26 | 27 | /** 28 | * [SweetDependency] 配置类接口类 29 | */ 30 | internal interface ISweetDependencyConfigs { 31 | 32 | companion object { 33 | 34 | /** 35 | * 默认的配置文件名称 36 | * 37 | * "sweet-dependency-config.yaml" 38 | */ 39 | internal const val DEFAULT_CONFIG_FILE_NAME = "sweet-dependency-config.yaml" 40 | } 41 | 42 | /** 是否启用插件 */ 43 | val isEnable: Boolean 44 | 45 | /** 是否启用调试模式 */ 46 | val isDebug: Boolean 47 | 48 | /** [SweetDependency] 的配置文件路径 */ 49 | val configFilePath: String 50 | 51 | /** 是否使用 [Settings.dependencyResolutionManagement] 管理库依赖 */ 52 | val isUseDependencyResolutionManagement: Boolean 53 | 54 | /** 是否启用依赖自动装配日志 */ 55 | val isEnableDependenciesAutowireLog: Boolean 56 | 57 | /** 是否启用详细模式 */ 58 | val isEnableVerboseMode: Boolean 59 | } -------------------------------------------------------------------------------- /sweetdependency-gradle-plugin/src/main/java/com/highcapable/sweetdependency/plugin/extension/accessors/proxy/IExtensionAccessors.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * SweetDependency - An easy autowire and manage dependencies Gradle plugin. 3 | * Copyright (C) 2019 HighCapable 4 | * https://github.com/HighCapable/SweetDependency 5 | * 6 | * Apache License Version 2.0 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * https://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | * 20 | * This file is created by fankes on 2023/6/19. 21 | */ 22 | package com.highcapable.sweetdependency.plugin.extension.accessors.proxy 23 | 24 | /** 25 | * 扩展可访问 [Class] 定义空间接口 26 | */ 27 | internal interface IExtensionAccessors -------------------------------------------------------------------------------- /sweetdependency-gradle-plugin/src/main/java/com/highcapable/sweetdependency/plugin/extension/dsl/configure/SweetDependencyConfigureExtension.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * SweetDependency - An easy autowire and manage dependencies Gradle plugin. 3 | * Copyright (C) 2019 HighCapable 4 | * https://github.com/HighCapable/SweetDependency 5 | * 6 | * Apache License Version 2.0 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * https://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | * 20 | * This file is created by fankes on 2023/6/26. 21 | */ 22 | @file:Suppress("MemberVisibilityCanBePrivate") 23 | 24 | package com.highcapable.sweetdependency.plugin.extension.dsl.configure 25 | 26 | import com.highcapable.sweetdependency.SweetDependency 27 | import com.highcapable.sweetdependency.environment.Environment 28 | import com.highcapable.sweetdependency.plugin.config.proxy.ISweetDependencyConfigs 29 | import org.gradle.api.initialization.Settings 30 | 31 | /** 32 | * [SweetDependency] 配置方法体实现类 33 | */ 34 | open class SweetDependencyConfigureExtension internal constructor() { 35 | 36 | internal companion object { 37 | 38 | /** [SweetDependencyConfigureExtension] 扩展名称 */ 39 | internal const val NAME = "sweetDependency" 40 | } 41 | 42 | /** 43 | * 是否启用插件 44 | * 45 | * 默认启用 - 如果你想关闭插件 - 在这里设置就可以了 46 | */ 47 | var isEnable = true 48 | @JvmName("enable") set 49 | 50 | /** 51 | * 是否启用调试模式 52 | * 53 | * 默认不启用 - 启用后将在自动装配时输出详细的依赖搜索信息 54 | */ 55 | var isDebug = false 56 | @JvmName("debug") set 57 | 58 | /** 59 | * [SweetDependency] 配置文件名称 60 | * 61 | * 默认为 [ISweetDependencyConfigs.DEFAULT_CONFIG_FILE_NAME] 62 | */ 63 | var configFileName = ISweetDependencyConfigs.DEFAULT_CONFIG_FILE_NAME 64 | @JvmName("configFileName") set 65 | 66 | /** 67 | * 是否使用 [Settings.dependencyResolutionManagement] 管理库依赖 68 | * 69 | * 此功能默认启用 - 如果你的项目必须存在自定义的 "repositories" 方法块 - 请关闭此功能 70 | * 71 | * - 注意:关闭后配置文件中的 "repositories-mode" 选项将不再有效 72 | */ 73 | var isUseDependencyResolutionManagement = true 74 | @JvmName("useDependencyResolutionManagement") set 75 | 76 | /** 77 | * 是否启用依赖自动装配日志 78 | * 79 | * 此功能默认启用 - 会在当前根项目 (Root Project) 的 build 目录下创建日志文件 80 | */ 81 | var isEnableDependenciesAutowireLog = true 82 | @JvmName("enableDependenciesAutowireLog") set 83 | 84 | /** 85 | * 是否启用详细模式 86 | * 87 | * 此功能默认启用 - 关闭后 [SweetDependency] 将会在非必要情况下保持安静 (省略非必要日志) 88 | */ 89 | var isEnableVerboseMode = true 90 | @JvmName("enableVerboseMode") set 91 | 92 | /** 93 | * 构造 [ISweetDependencyConfigs] 94 | * @return [ISweetDependencyConfigs] 95 | */ 96 | internal fun build(): ISweetDependencyConfigs { 97 | val currentEnable = isEnable 98 | val currentDebug = isDebug 99 | val currentConfigFilePath = Environment.resourcesDir(configFileName).absolutePath 100 | val currentUseDependencyResolutionManagement = isUseDependencyResolutionManagement 101 | val currentEnableDependenciesAutowireLog = isEnableDependenciesAutowireLog 102 | val currentEnableVerboseMode = isEnableVerboseMode 103 | return object : ISweetDependencyConfigs { 104 | override val isEnable get() = currentEnable 105 | override val isDebug get() = currentDebug 106 | override val configFilePath get() = currentConfigFilePath 107 | override val isUseDependencyResolutionManagement get() = currentUseDependencyResolutionManagement 108 | override val isEnableDependenciesAutowireLog get() = currentEnableDependenciesAutowireLog 109 | override val isEnableVerboseMode get() = currentEnableVerboseMode 110 | } 111 | } 112 | } -------------------------------------------------------------------------------- /sweetdependency-gradle-plugin/src/main/java/com/highcapable/sweetdependency/plugin/extension/dsl/manager/SweetDependencyAutowireExtension.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * SweetDependency - An easy autowire and manage dependencies Gradle plugin. 3 | * Copyright (C) 2019 HighCapable 4 | * https://github.com/HighCapable/SweetDependency 5 | * 6 | * Apache License Version 2.0 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * https://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | * 20 | * This file is created by fankes on 2023/6/26. 21 | */ 22 | package com.highcapable.sweetdependency.plugin.extension.dsl.manager 23 | 24 | import com.highcapable.sweetdependency.manager.helper.DependencyDeployHelper 25 | import org.gradle.api.Project 26 | 27 | /** 28 | * 依赖扩展功能配置方法体实现类 29 | * @param project 当前项目 30 | */ 31 | open class SweetDependencyAutowireExtension internal constructor(private val project: Project) { 32 | 33 | internal companion object { 34 | 35 | /** [SweetDependencyAutowireExtension] 扩展名称 */ 36 | internal const val NAME = "sweet" 37 | } 38 | 39 | /** 40 | * 自动装配依赖 41 | * @param params 参数数组 42 | * @return [Any] 43 | */ 44 | fun autowire(vararg params: String) = DependencyDeployHelper.resolveAutowire(project, params) 45 | } -------------------------------------------------------------------------------- /sweetdependency-gradle-plugin/src/main/java/com/highcapable/sweetdependency/plugin/helper/PluginUpdateHelper.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * SweetDependency - An easy autowire and manage dependencies Gradle plugin. 3 | * Copyright (C) 2019 HighCapable 4 | * https://github.com/HighCapable/SweetDependency 5 | * 6 | * Apache License Version 2.0 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * https://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | * 20 | * This file is created by fankes on 2023/7/30. 21 | */ 22 | package com.highcapable.sweetdependency.plugin.helper 23 | 24 | import com.highcapable.sweetdependency.SweetDependency 25 | import com.highcapable.sweetdependency.generated.SweetDependencyProperties 26 | import com.highcapable.sweetdependency.gradle.helper.GradleHelper 27 | import com.highcapable.sweetdependency.utils.debug.SLog 28 | import com.highcapable.sweetdependency.utils.executeUrlBody 29 | import org.xml.sax.InputSource 30 | import java.io.StringReader 31 | import javax.xml.parsers.DocumentBuilderFactory 32 | 33 | /** 34 | * 插件自身检查更新工具类 35 | */ 36 | internal object PluginUpdateHelper { 37 | 38 | /** OSS Release URL 地址 */ 39 | private const val SONATYPE_OSS_RELEASES_URL = "https://s01.oss.sonatype.org/content/repositories/releases" 40 | 41 | /** 依赖配置文件名 */ 42 | private const val METADATA_FILE_NAME = "maven-metadata.xml" 43 | 44 | /** 插件自身依赖 URL 名称 */ 45 | private val groupUrlNotation = 46 | "${SweetDependencyProperties.PROJECT_GROUP_NAME.replace(".","/")}/${SweetDependencyProperties.GRADLE_PLUGIN_MODULE_NAME}" 47 | 48 | /** 检查更新 URL 地址 */ 49 | private val releaseUrl = "$SONATYPE_OSS_RELEASES_URL/$groupUrlNotation/$METADATA_FILE_NAME" 50 | 51 | /** 检查更新 */ 52 | internal fun checkingForUpdate() { 53 | if (GradleHelper.isOfflineMode) return 54 | val latestVersion = releaseUrl.executeUrlBody(isShowFailure = false).trim().findLatest() 55 | if (latestVersion.isNotBlank() && latestVersion != SweetDependency.VERSION) SLog.note( 56 | """ 57 | Plugin update is available, the current version is ${SweetDependency.VERSION}, please update to $latestVersion 58 | You can modify your plugin version in your project's settings.gradle or settings.gradle.kts 59 | plugins { 60 | id("${SweetDependencyProperties.PROJECT_GROUP_NAME}") version "$latestVersion" 61 | ... 62 | } 63 | For more information, you can visit ${SweetDependency.PROJECT_URL} 64 | """.trimIndent(), SLog.UP 65 | ) 66 | } 67 | 68 | /** 69 | * 解析 [METADATA_FILE_NAME] 内容并获取 "latest" 70 | * @return [String] 71 | */ 72 | private fun String.findLatest() = runCatching { 73 | if (!(contains("")) || !endsWith("")) return@runCatching "" 74 | DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(InputSource(StringReader(this))).let { document -> 75 | document.getElementsByTagName("latest")?.let { if (it.length > 0) it.item(0)?.textContent ?: "" else "" } 76 | } 77 | }.getOrNull() ?: "" 78 | } -------------------------------------------------------------------------------- /sweetdependency-gradle-plugin/src/main/java/com/highcapable/sweetdependency/plugin/impl/base/BaseExtensionImpl.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * SweetDependency - An easy autowire and manage dependencies Gradle plugin. 3 | * Copyright (C) 2019 HighCapable 4 | * https://github.com/HighCapable/SweetDependency 5 | * 6 | * Apache License Version 2.0 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * https://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | * 20 | * This file is created by fankes on 2023/5/27. 21 | */ 22 | package com.highcapable.sweetdependency.plugin.impl.base 23 | 24 | import com.highcapable.sweetdependency.gradle.delegate.ProjectTransaction 25 | import com.highcapable.sweetdependency.plugin.config.proxy.ISweetDependencyConfigs 26 | import org.gradle.api.initialization.Settings 27 | 28 | /** 29 | * 扩展父类实现类 30 | */ 31 | internal abstract class BaseExtensionImpl internal constructor() { 32 | 33 | /** 34 | * 当初始化时回调 35 | * @param settings 当前设置 36 | * @param configs 当前配置 37 | */ 38 | internal abstract fun onInitialization(settings: Settings, configs: ISweetDependencyConfigs) 39 | 40 | /** 41 | * 当开始事务时回调 42 | * @param transaction 当前实例 43 | */ 44 | internal abstract fun onTransaction(transaction: ProjectTransaction) 45 | } -------------------------------------------------------------------------------- /sweetdependency-gradle-plugin/src/main/java/com/highcapable/sweetdependency/plugin/task/AutowireDependenciesTask.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * SweetDependency - An easy autowire and manage dependencies Gradle plugin. 3 | * Copyright (C) 2019 HighCapable 4 | * https://github.com/HighCapable/SweetDependency 5 | * 6 | * Apache License Version 2.0 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * https://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | * 20 | * This file is created by fankes on 2023/6/29. 21 | */ 22 | package com.highcapable.sweetdependency.plugin.task 23 | 24 | import com.highcapable.sweetdependency.gradle.entity.DependencyUpdateMode 25 | import com.highcapable.sweetdependency.manager.DependencyManager 26 | import com.highcapable.sweetdependency.plugin.config.content.SweetDependencyConfigs 27 | import com.highcapable.sweetdependency.plugin.task.base.BaseTask 28 | 29 | /** 30 | * 依赖自动装配 Gradle Task 31 | */ 32 | internal class AutowireDependenciesTask : BaseTask() { 33 | 34 | override fun onTransaction() = SweetDependencyConfigs.withPluginEnable { 35 | DependencyManager.autowireAndUpdate( 36 | DependencyUpdateMode( 37 | DependencyUpdateMode.DependencyType.ALL, 38 | DependencyUpdateMode.UpdateType.ONLY_AUTOWIRE 39 | ), isRunningOnSync = false 40 | ) 41 | } 42 | } -------------------------------------------------------------------------------- /sweetdependency-gradle-plugin/src/main/java/com/highcapable/sweetdependency/plugin/task/AutowireLibrariesTask.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * SweetDependency - An easy autowire and manage dependencies Gradle plugin. 3 | * Copyright (C) 2019 HighCapable 4 | * https://github.com/HighCapable/SweetDependency 5 | * 6 | * Apache License Version 2.0 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * https://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | * 20 | * This file is created by fankes on 2023/8/16. 21 | */ 22 | package com.highcapable.sweetdependency.plugin.task 23 | 24 | import com.highcapable.sweetdependency.gradle.entity.DependencyUpdateMode 25 | import com.highcapable.sweetdependency.manager.DependencyManager 26 | import com.highcapable.sweetdependency.plugin.config.content.SweetDependencyConfigs 27 | import com.highcapable.sweetdependency.plugin.task.base.BaseTask 28 | 29 | /** 30 | * 依赖自动装配 Gradle Task 31 | */ 32 | internal class AutowireLibrariesTask : BaseTask() { 33 | 34 | override fun onTransaction() = SweetDependencyConfigs.withPluginEnable { 35 | DependencyManager.autowireAndUpdate( 36 | DependencyUpdateMode( 37 | DependencyUpdateMode.DependencyType.LIBRARIES, 38 | DependencyUpdateMode.UpdateType.ONLY_AUTOWIRE 39 | ), isRunningOnSync = false 40 | ) 41 | } 42 | } -------------------------------------------------------------------------------- /sweetdependency-gradle-plugin/src/main/java/com/highcapable/sweetdependency/plugin/task/AutowirePluginsTask.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * SweetDependency - An easy autowire and manage dependencies Gradle plugin. 3 | * Copyright (C) 2019 HighCapable 4 | * https://github.com/HighCapable/SweetDependency 5 | * 6 | * Apache License Version 2.0 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * https://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | * 20 | * This file is created by fankes on 2023/8/16. 21 | */ 22 | package com.highcapable.sweetdependency.plugin.task 23 | 24 | import com.highcapable.sweetdependency.gradle.entity.DependencyUpdateMode 25 | import com.highcapable.sweetdependency.manager.DependencyManager 26 | import com.highcapable.sweetdependency.plugin.config.content.SweetDependencyConfigs 27 | import com.highcapable.sweetdependency.plugin.task.base.BaseTask 28 | 29 | /** 30 | * 依赖自动装配 Gradle Task 31 | */ 32 | internal class AutowirePluginsTask : BaseTask() { 33 | 34 | override fun onTransaction() = SweetDependencyConfigs.withPluginEnable { 35 | DependencyManager.autowireAndUpdate( 36 | DependencyUpdateMode( 37 | DependencyUpdateMode.DependencyType.PLUGINS, 38 | DependencyUpdateMode.UpdateType.ONLY_AUTOWIRE 39 | ), isRunningOnSync = false 40 | ) 41 | } 42 | } -------------------------------------------------------------------------------- /sweetdependency-gradle-plugin/src/main/java/com/highcapable/sweetdependency/plugin/task/CreateDependenciesMigrationTemplateTask.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * SweetDependency - An easy autowire and manage dependencies Gradle plugin. 3 | * Copyright (C) 2019 HighCapable 4 | * https://github.com/HighCapable/SweetDependency 5 | * 6 | * Apache License Version 2.0 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * https://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | * 20 | * This file is created by fankes on 2023/6/29. 21 | */ 22 | package com.highcapable.sweetdependency.plugin.task 23 | 24 | import com.highcapable.sweetdependency.manager.transaction.DependencyMigrationTemplateTransaction 25 | import com.highcapable.sweetdependency.plugin.config.content.SweetDependencyConfigs 26 | import com.highcapable.sweetdependency.plugin.task.base.BaseTask 27 | 28 | /** 29 | * 创建依赖迁移模板 Gradle Task 30 | */ 31 | internal class CreateDependenciesMigrationTemplateTask : BaseTask() { 32 | 33 | override fun onTransaction() = SweetDependencyConfigs.withPluginEnable { DependencyMigrationTemplateTransaction.createTemplate() } 34 | } -------------------------------------------------------------------------------- /sweetdependency-gradle-plugin/src/main/java/com/highcapable/sweetdependency/plugin/task/SweetDependencyDebugTask.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * SweetDependency - An easy autowire and manage dependencies Gradle plugin. 3 | * Copyright (C) 2019 HighCapable 4 | * https://github.com/HighCapable/SweetDependency 5 | * 6 | * Apache License Version 2.0 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * https://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | * 20 | * This file is created by fankes on 2023/6/29. 21 | */ 22 | package com.highcapable.sweetdependency.plugin.task 23 | 24 | import com.highcapable.sweetdependency.manager.transaction.RuntimeDebugTransaction 25 | import com.highcapable.sweetdependency.plugin.config.content.SweetDependencyConfigs 26 | import com.highcapable.sweetdependency.plugin.task.base.BaseTask 27 | 28 | /** 29 | * 调试 Gradle Task 30 | */ 31 | internal class SweetDependencyDebugTask : BaseTask() { 32 | 33 | override fun onTransaction() = SweetDependencyConfigs.withPluginEnable { RuntimeDebugTransaction.dump() } 34 | } -------------------------------------------------------------------------------- /sweetdependency-gradle-plugin/src/main/java/com/highcapable/sweetdependency/plugin/task/UpdateAllDependenciesTask.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * SweetDependency - An easy autowire and manage dependencies Gradle plugin. 3 | * Copyright (C) 2019 HighCapable 4 | * https://github.com/HighCapable/SweetDependency 5 | * 6 | * Apache License Version 2.0 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * https://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | * 20 | * This file is created by fankes on 2023/8/14. 21 | */ 22 | package com.highcapable.sweetdependency.plugin.task 23 | 24 | import com.highcapable.sweetdependency.gradle.entity.DependencyUpdateMode 25 | import com.highcapable.sweetdependency.manager.DependencyManager 26 | import com.highcapable.sweetdependency.plugin.config.content.SweetDependencyConfigs 27 | import com.highcapable.sweetdependency.plugin.task.base.BaseTask 28 | 29 | /** 30 | * 依赖自动装配、更新 (全部) Gradle Task 31 | */ 32 | internal class UpdateAllDependenciesTask : BaseTask() { 33 | 34 | override fun onTransaction() = SweetDependencyConfigs.withPluginEnable { 35 | DependencyManager.autowireAndUpdate( 36 | DependencyUpdateMode( 37 | DependencyUpdateMode.DependencyType.ALL, 38 | DependencyUpdateMode.UpdateType.UPDATE_ALL 39 | ), isRunningOnSync = false 40 | ) 41 | } 42 | } -------------------------------------------------------------------------------- /sweetdependency-gradle-plugin/src/main/java/com/highcapable/sweetdependency/plugin/task/UpdateAllLibrariesTask.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * SweetDependency - An easy autowire and manage dependencies Gradle plugin. 3 | * Copyright (C) 2019 HighCapable 4 | * https://github.com/HighCapable/SweetDependency 5 | * 6 | * Apache License Version 2.0 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * https://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | * 20 | * This file is created by fankes on 2023/8/16. 21 | */ 22 | package com.highcapable.sweetdependency.plugin.task 23 | 24 | import com.highcapable.sweetdependency.gradle.entity.DependencyUpdateMode 25 | import com.highcapable.sweetdependency.manager.DependencyManager 26 | import com.highcapable.sweetdependency.plugin.config.content.SweetDependencyConfigs 27 | import com.highcapable.sweetdependency.plugin.task.base.BaseTask 28 | 29 | /** 30 | * 依赖自动装配、更新 (全部) Gradle Task 31 | */ 32 | internal class UpdateAllLibrariesTask : BaseTask() { 33 | 34 | override fun onTransaction() = SweetDependencyConfigs.withPluginEnable { 35 | DependencyManager.autowireAndUpdate( 36 | DependencyUpdateMode( 37 | DependencyUpdateMode.DependencyType.LIBRARIES, 38 | DependencyUpdateMode.UpdateType.UPDATE_ALL 39 | ), isRunningOnSync = false 40 | ) 41 | } 42 | } -------------------------------------------------------------------------------- /sweetdependency-gradle-plugin/src/main/java/com/highcapable/sweetdependency/plugin/task/UpdateAllPluginsTask.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * SweetDependency - An easy autowire and manage dependencies Gradle plugin. 3 | * Copyright (C) 2019 HighCapable 4 | * https://github.com/HighCapable/SweetDependency 5 | * 6 | * Apache License Version 2.0 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * https://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | * 20 | * This file is created by fankes on 2023/8/16. 21 | */ 22 | package com.highcapable.sweetdependency.plugin.task 23 | 24 | import com.highcapable.sweetdependency.gradle.entity.DependencyUpdateMode 25 | import com.highcapable.sweetdependency.manager.DependencyManager 26 | import com.highcapable.sweetdependency.plugin.config.content.SweetDependencyConfigs 27 | import com.highcapable.sweetdependency.plugin.task.base.BaseTask 28 | 29 | /** 30 | * 依赖自动装配、更新 (全部) Gradle Task 31 | */ 32 | internal class UpdateAllPluginsTask : BaseTask() { 33 | 34 | override fun onTransaction() = SweetDependencyConfigs.withPluginEnable { 35 | DependencyManager.autowireAndUpdate( 36 | DependencyUpdateMode( 37 | DependencyUpdateMode.DependencyType.PLUGINS, 38 | DependencyUpdateMode.UpdateType.UPDATE_ALL 39 | ), isRunningOnSync = false 40 | ) 41 | } 42 | } -------------------------------------------------------------------------------- /sweetdependency-gradle-plugin/src/main/java/com/highcapable/sweetdependency/plugin/task/UpdateOptionalDependenciesTask.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * SweetDependency - An easy autowire and manage dependencies Gradle plugin. 3 | * Copyright (C) 2019 HighCapable 4 | * https://github.com/HighCapable/SweetDependency 5 | * 6 | * Apache License Version 2.0 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * https://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | * 20 | * This file is created by fankes on 2023/6/29. 21 | */ 22 | package com.highcapable.sweetdependency.plugin.task 23 | 24 | import com.highcapable.sweetdependency.gradle.entity.DependencyUpdateMode 25 | import com.highcapable.sweetdependency.manager.DependencyManager 26 | import com.highcapable.sweetdependency.plugin.config.content.SweetDependencyConfigs 27 | import com.highcapable.sweetdependency.plugin.task.base.BaseTask 28 | 29 | /** 30 | * 依赖自动装配、更新 (可选) Gradle Task 31 | */ 32 | internal class UpdateOptionalDependenciesTask : BaseTask() { 33 | 34 | override fun onTransaction() = SweetDependencyConfigs.withPluginEnable { 35 | DependencyManager.autowireAndUpdate( 36 | DependencyUpdateMode( 37 | DependencyUpdateMode.DependencyType.ALL, 38 | DependencyUpdateMode.UpdateType.UPDATE_OPTIONAL 39 | ), isRunningOnSync = false 40 | ) 41 | } 42 | } -------------------------------------------------------------------------------- /sweetdependency-gradle-plugin/src/main/java/com/highcapable/sweetdependency/plugin/task/UpdateOptionalLibrariesTask.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * SweetDependency - An easy autowire and manage dependencies Gradle plugin. 3 | * Copyright (C) 2019 HighCapable 4 | * https://github.com/HighCapable/SweetDependency 5 | * 6 | * Apache License Version 2.0 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * https://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | * 20 | * This file is created by fankes on 2023/8/16. 21 | */ 22 | package com.highcapable.sweetdependency.plugin.task 23 | 24 | import com.highcapable.sweetdependency.gradle.entity.DependencyUpdateMode 25 | import com.highcapable.sweetdependency.manager.DependencyManager 26 | import com.highcapable.sweetdependency.plugin.config.content.SweetDependencyConfigs 27 | import com.highcapable.sweetdependency.plugin.task.base.BaseTask 28 | 29 | /** 30 | * 依赖自动装配、更新 (可选) Gradle Task 31 | */ 32 | internal class UpdateOptionalLibrariesTask : BaseTask() { 33 | 34 | override fun onTransaction() = SweetDependencyConfigs.withPluginEnable { 35 | DependencyManager.autowireAndUpdate( 36 | DependencyUpdateMode( 37 | DependencyUpdateMode.DependencyType.LIBRARIES, 38 | DependencyUpdateMode.UpdateType.UPDATE_OPTIONAL 39 | ), isRunningOnSync = false 40 | ) 41 | } 42 | } -------------------------------------------------------------------------------- /sweetdependency-gradle-plugin/src/main/java/com/highcapable/sweetdependency/plugin/task/UpdateOptionalPluginsTask.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * SweetDependency - An easy autowire and manage dependencies Gradle plugin. 3 | * Copyright (C) 2019 HighCapable 4 | * https://github.com/HighCapable/SweetDependency 5 | * 6 | * Apache License Version 2.0 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * https://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | * 20 | * This file is created by fankes on 2023/8/16. 21 | */ 22 | package com.highcapable.sweetdependency.plugin.task 23 | 24 | import com.highcapable.sweetdependency.gradle.entity.DependencyUpdateMode 25 | import com.highcapable.sweetdependency.manager.DependencyManager 26 | import com.highcapable.sweetdependency.plugin.config.content.SweetDependencyConfigs 27 | import com.highcapable.sweetdependency.plugin.task.base.BaseTask 28 | 29 | /** 30 | * 依赖自动装配、更新 (可选) Gradle Task 31 | */ 32 | internal class UpdateOptionalPluginsTask : BaseTask() { 33 | 34 | override fun onTransaction() = SweetDependencyConfigs.withPluginEnable { 35 | DependencyManager.autowireAndUpdate( 36 | DependencyUpdateMode( 37 | DependencyUpdateMode.DependencyType.PLUGINS, 38 | DependencyUpdateMode.UpdateType.UPDATE_OPTIONAL 39 | ), isRunningOnSync = false 40 | ) 41 | } 42 | } -------------------------------------------------------------------------------- /sweetdependency-gradle-plugin/src/main/java/com/highcapable/sweetdependency/plugin/task/base/BaseTask.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * SweetDependency - An easy autowire and manage dependencies Gradle plugin. 3 | * Copyright (C) 2019 HighCapable 4 | * https://github.com/HighCapable/SweetDependency 5 | * 6 | * Apache License Version 2.0 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * https://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | * 20 | * This file is created by fankes on 2023/6/29. 21 | */ 22 | package com.highcapable.sweetdependency.plugin.task.base 23 | 24 | /** 25 | * Gradle Task 父类实现类 26 | */ 27 | internal abstract class BaseTask internal constructor() { 28 | 29 | /** 当开始事务时回调 */ 30 | internal abstract fun onTransaction() 31 | } -------------------------------------------------------------------------------- /sweetdependency-gradle-plugin/src/main/java/com/highcapable/sweetdependency/utils/FileFactory.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * SweetDependency - An easy autowire and manage dependencies Gradle plugin. 3 | * Copyright (C) 2019 HighCapable 4 | * https://github.com/HighCapable/SweetDependency 5 | * 6 | * Apache License Version 2.0 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * https://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | * 20 | * This file is created by fankes on 2023/5/17. 21 | */ 22 | @file:Suppress("unused") 23 | 24 | package com.highcapable.sweetdependency.utils 25 | 26 | import com.highcapable.sweetdependency.utils.debug.SError 27 | import java.io.File 28 | import java.nio.file.Paths 29 | import java.util.zip.ZipFile 30 | 31 | /** 32 | * 字符串路径转换为文件 33 | * 34 | * 自动调用 [parseFileSeparator] 35 | * @return [File] 36 | */ 37 | internal fun String.toFile() = File(parseFileSeparator()) 38 | 39 | /** 40 | * 格式化到当前操作系统的文件分隔符 41 | * @return [String] 42 | */ 43 | internal fun String.parseFileSeparator() = replace("/", File.separator).replace("\\", File.separator) 44 | 45 | /** 46 | * 格式化到 Unix 操作系统的文件分隔符 47 | * @return [String] 48 | */ 49 | internal fun String.parseUnixFileSeparator() = replace("\\", "/") 50 | 51 | /** 52 | * 字符串文件路径转换到相对文件路径 53 | * @param basePath 基于路径 54 | * @param rootPath 根路径 - 不填将不校验完整路径 55 | * @return [String] 56 | */ 57 | internal fun String.toRelativeFilePath(basePath: String, rootPath: String = "") = 58 | parseFileSeparator().runCatching { 59 | if (rootPath.isNotBlank() && !contains(rootPath)) return this 60 | return Paths.get(basePath).relativize(Paths.get(this)).toString() 61 | }.getOrNull() ?: parseFileSeparator() 62 | 63 | /** 64 | * 字符串文件路径转换到绝对文件路径 65 | * @param basePath 基于路径 66 | * @return [String] 67 | */ 68 | internal fun String.toAbsoluteFilePath(basePath: String) = 69 | parseFileSeparator().runCatching { 70 | if (Paths.get(this).isAbsolute) return this 71 | Paths.get(basePath).resolve(Paths.get(this)).normalize().toString() 72 | }.getOrNull() ?: parseFileSeparator() 73 | 74 | /** 75 | * 字符串文件路径转换到绝对文件路径数组 76 | * @param basePath 基于路径 77 | * @return [MutableList]<[String]> 78 | */ 79 | internal fun String.toAbsoluteFilePaths(basePath: String) = 80 | toAbsoluteFilePath(basePath).let { path -> 81 | mutableListOf().apply { 82 | when { 83 | path.toFile().let { it.exists() && it.isFile } -> add(path) 84 | path.toFile().let { it.exists() && it.isDirectory } -> SError.make("The file path $path is a directory") 85 | else -> { 86 | /** 87 | * 是否匹配文件扩展名 88 | * @param condition 条件 89 | * @return [Boolean] 90 | */ 91 | fun String.isMatch(condition: String) = 92 | condition.let { if (it == "*") "*.*" else it }.replace(".", "\\.").replace("*", ".*").toRegex().matches(this) 93 | val condition = path.split(File.separator) 94 | if (path.contains(File.separator) && condition[condition.lastIndex].contains("*")) 95 | path.toFile().parentFile?.listFiles()?.forEach { if (it.name.isMatch(condition[condition.lastIndex])) add(it.absolutePath) } 96 | else SError.make("Could not resolve file path $path") 97 | } 98 | } 99 | } 100 | } 101 | 102 | /** 103 | * 检查文件是否为合法的压缩包文件 104 | * 105 | * - 如果不是文件 (可能是目录) - 返回 true 106 | * - 如果文件不存在 - 返回 false 107 | * @return [Boolean] 108 | */ 109 | internal fun File.isValidZip(): Boolean { 110 | if (!isFile) return true 111 | if (!exists()) return false 112 | return runCatching { ZipFile(this).use {}; true }.getOrNull() ?: false 113 | } 114 | 115 | /** 116 | * 检查目录是否为空 117 | * 118 | * - 如果不是目录 (可能是文件) - 返回 true 119 | * - 如果文件不存在 - 返回 true 120 | * @return [Boolean] 121 | */ 122 | internal fun File.isEmpty() = !exists() || !isDirectory || listFiles().isNullOrEmpty() 123 | 124 | /** 删除目录下的空子目录 */ 125 | internal fun File.deleteEmptyRecursively() { 126 | listFiles { file -> file.isDirectory }?.forEach { subDir -> 127 | subDir.deleteEmptyRecursively() 128 | if (subDir.listFiles()?.isEmpty() == true) subDir.delete() 129 | } 130 | } 131 | 132 | /** 133 | * 获取当前文件内容的字符串内容 (同步) 134 | * @return [String] 135 | */ 136 | internal fun String.executeFileBody() = runCatching { toFile().readText() }.getOrNull() ?: "" -------------------------------------------------------------------------------- /sweetdependency-gradle-plugin/src/main/java/com/highcapable/sweetdependency/utils/HttpFactory.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * SweetDependency - An easy autowire and manage dependencies Gradle plugin. 3 | * Copyright (C) 2019 HighCapable 4 | * https://github.com/HighCapable/SweetDependency 5 | * 6 | * Apache License Version 2.0 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * https://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | * 20 | * This file is created by fankes on 2023/6/15. 21 | */ 22 | package com.highcapable.sweetdependency.utils 23 | 24 | import com.highcapable.sweetdependency.utils.debug.SError 25 | import com.highcapable.sweetdependency.utils.debug.SLog 26 | import okhttp3.Credentials 27 | import okhttp3.OkHttpClient 28 | import okhttp3.Request 29 | import java.util.concurrent.TimeUnit 30 | 31 | /** 32 | * 获取当前 URL 地址的请求体字符串内容 (GET) (同步) 33 | * @param username 用户名 34 | * @param password 密码 35 | * @param isShowFailure 是否显示错误 - 默认是 36 | * @return [String] 37 | */ 38 | internal fun String.executeUrlBody(username: String = "", password: String = "", isShowFailure: Boolean = true) = runCatching { 39 | OkHttpClient() 40 | .newBuilder() 41 | .connectTimeout(10000, TimeUnit.MILLISECONDS) 42 | .authenticator { _, response -> 43 | if (response.code == 400 || response.code == 401) 44 | response.request.newBuilder() 45 | .header("Authorization", Credentials.basic(username, password)) 46 | .build() 47 | else null 48 | }.build().newCall( 49 | Request.Builder().url(when { 50 | startsWith("https://") -> "https://" + replace("https://", "").replace("//", "/") 51 | startsWith("http://") -> "http://" + replace("http://", "").replace("//", "/") 52 | else -> SError.make("Invalid URL: $this") 53 | }).get().build() 54 | ).execute().let { 55 | if (it.code == 200 || it.code == 404) it.body?.string() ?: "" 56 | else SError.make("Request failed with code ${it.code}") 57 | } 58 | }.onFailure { if (isShowFailure) SLog.error("Failed to connect to $this\n$it") }.getOrNull() ?: "" -------------------------------------------------------------------------------- /sweetdependency-gradle-plugin/src/main/java/com/highcapable/sweetdependency/utils/ThreadPoolFactory.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * SweetDependency - An easy autowire and manage dependencies Gradle plugin. 3 | * Copyright (C) 2019 HighCapable 4 | * https://github.com/HighCapable/SweetDependency 5 | * 6 | * Apache License Version 2.0 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * https://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | * 20 | * This file is created by fankes on 2023/7/16. 21 | */ 22 | package com.highcapable.sweetdependency.utils 23 | 24 | import java.util.concurrent.ExecutorService 25 | import java.util.concurrent.Executors 26 | 27 | /** 28 | * 创建当前线程池服务 29 | * @return [ExecutorService] 30 | */ 31 | private val currentThreadPool get() = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors()) 32 | 33 | /** 34 | * 启动 [Thread] 延迟等待 [block] 的结果 [T] 35 | * @param delayMs 延迟毫秒 - 默认 1 ms 36 | * @param block 方法块 37 | * @return [T] 38 | */ 39 | internal inline fun T.await(delayMs: Long = 1, crossinline block: (T) -> Unit): T { 40 | currentThreadPool.apply { 41 | execute { 42 | if (delayMs > 0) Thread.sleep(delayMs) 43 | block(this@await) 44 | shutdown() 45 | } 46 | }; return this 47 | } -------------------------------------------------------------------------------- /sweetdependency-gradle-plugin/src/main/java/com/highcapable/sweetdependency/utils/ThrowableFactory.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * SweetDependency - An easy autowire and manage dependencies Gradle plugin. 3 | * Copyright (C) 2019 HighCapable 4 | * https://github.com/HighCapable/SweetDependency 5 | * 6 | * Apache License Version 2.0 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * https://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | * 20 | * This file is created by fankes on 2023/6/19. 21 | */ 22 | package com.highcapable.sweetdependency.utils 23 | 24 | import java.io.PrintWriter 25 | import java.io.StringWriter 26 | 27 | /** 28 | * 写出异常堆栈到字符串 29 | * @return [String] 30 | */ 31 | internal fun Throwable.dumpToString() = StringWriter().apply { printStackTrace(PrintWriter(this).apply { flush() }) }.toString() -------------------------------------------------------------------------------- /sweetdependency-gradle-plugin/src/main/java/com/highcapable/sweetdependency/utils/VariableFactory.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * SweetDependency - An easy autowire and manage dependencies Gradle plugin. 3 | * Copyright (C) 2019 HighCapable 4 | * https://github.com/HighCapable/SweetDependency 5 | * 6 | * Apache License Version 2.0 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * https://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | * 20 | * This file is created by fankes on 2023/6/14. 21 | */ 22 | package com.highcapable.sweetdependency.utils 23 | 24 | /** 25 | * 允许 [MutableList] 进行 [orEmpty] 操作后返回 [MutableList] 26 | * @return [MutableList]<[T]> 27 | */ 28 | internal fun MutableList?.orEmpty() = this ?: emptyList().toMutableList() 29 | 30 | /** 31 | * 允许 [MutableList] 进行 [filter] 操作后返回 [MutableList] 32 | * @param predicate 方法体 33 | * @return [MutableList]<[T]> 34 | */ 35 | internal inline fun MutableList.filter(predicate: (T) -> Boolean) = filterTo(mutableListOf(), predicate).toMutableList() 36 | 37 | /** 38 | * 允许 [MutableMap] 进行 [filter] 操作后返回 [MutableMap] 39 | * @param predicate 方法体 40 | * @return [MutableMap]<[K], [V]> 41 | */ 42 | internal inline fun MutableMap.filter(predicate: (Map.Entry) -> Boolean) = filterTo(mutableMapOf(), predicate).toMutableMap() 43 | 44 | /** 45 | * 获取 [MutableMap] 第一位元素 (数组为空返回 null) 46 | * @return [MutableMap.MutableEntry]<[K], [V]> or null 47 | */ 48 | internal fun MutableMap.single() = entries.firstOrNull() 49 | 50 | /** 51 | * 当数组不为空时返回非空 52 | * @return [T] or null 53 | */ 54 | internal inline fun > T.noEmpty() = takeIf { it.isNotEmpty() } 55 | 56 | /** 57 | * 当字符串不为空白时返回非空 58 | * @return [T] or null 59 | */ 60 | internal inline fun T.noBlank() = takeIf { it.isNotBlank() } 61 | 62 | /** 63 | * 判断数组中是否存在重复元素 64 | * @return [Boolean] 65 | */ 66 | internal fun List<*>.hasDuplicate() = distinct().size != size 67 | 68 | /** 69 | * 查找数组中的重复元素 70 | * @return [List]<[T]> 71 | */ 72 | internal inline fun List.findDuplicates() = distinct().filter { e -> count { it == e } > 1 }.distinct() 73 | 74 | /** 75 | * 字符串数组转换为内容字符串 76 | * @return [String] 77 | */ 78 | internal fun List.joinToContent() = joinToString("\n").trim() 79 | 80 | /** 81 | * 空格字符串数组转换为 [MutableList] 82 | * @return [MutableList]<[String]> 83 | */ 84 | internal fun String.toSpaceList() = when { 85 | contains(" ") -> replace("\\s+".toRegex(), " ").split(" ").toMutableList() 86 | isNotBlank() -> mutableListOf(this) 87 | else -> mutableListOf() 88 | } 89 | 90 | /** 91 | * 下划线、分隔线、点、空格命名字符串转小驼峰命名字符串 92 | * @return [String] 93 | */ 94 | internal fun String.camelcase() = runCatching { 95 | split("_", ".", "-", " ").map { it.replaceFirstChar { e -> e.titlecase() } }.let { words -> 96 | words.first().replaceFirstChar { it.lowercase() } + words.drop(1).joinToString("") 97 | } 98 | }.getOrNull() ?: this 99 | 100 | /** 101 | * 下划线、分隔线、点、空格命名字符串转大驼峰命名字符串 102 | * @return [String] 103 | */ 104 | internal fun String.uppercamelcase() = camelcase().capitalize() 105 | 106 | /** 107 | * 字符串首字母大写 108 | * @return [String] 109 | */ 110 | internal fun String.capitalize() = replaceFirstChar { it.uppercaseChar() } 111 | 112 | /** 113 | * 字符串首字母小写 114 | * @return [String] 115 | */ 116 | internal fun String.uncapitalize() = replaceFirstChar { it.lowercaseChar() } 117 | 118 | /** 119 | * 转换字符串第一位数字到外观近似大写字母 120 | * @return [String] 121 | */ 122 | internal fun String.firstNumberToLetter() = 123 | if (isNotBlank()) (mapOf( 124 | '0' to 'O', '1' to 'I', 125 | '2' to 'Z', '3' to 'E', 126 | '4' to 'A', '5' to 'S', 127 | '6' to 'G', '7' to 'T', 128 | '8' to 'B', '9' to 'P' 129 | )[first()] ?: first()) + substring(1) 130 | else this 131 | 132 | /** 133 | * 转换字符串为非 Java 关键方法引用名称 134 | * @return [String] 135 | */ 136 | internal fun String.toNonJavaName() = if (lowercase() == "class") replace("lass", "lazz") else this 137 | 138 | /** 139 | * 字符串中是否存在插值符号 ${...} 140 | * @return [Boolean] 141 | */ 142 | internal fun String.hasInterpolation() = contains("\${") && contains("}") 143 | 144 | /** 145 | * 替换字符串中的插值符号 ${...} 146 | * @param result 回调结果 147 | * @return [String] 148 | */ 149 | internal fun String.replaceInterpolation(result: (groupValue: String) -> CharSequence) = 150 | "\\$\\{(.+?)}".toRegex().replace(this) { result(it.groupValues[1]) } -------------------------------------------------------------------------------- /sweetdependency-gradle-plugin/src/main/java/com/highcapable/sweetdependency/utils/code/entity/MavenPomData.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * SweetDependency - An easy autowire and manage dependencies Gradle plugin. 3 | * Copyright (C) 2019 HighCapable 4 | * https://github.com/HighCapable/SweetDependency 5 | * 6 | * Apache License Version 2.0 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * https://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | * 20 | * This file is created by fankes on 2023/8/24. 21 | */ 22 | package com.highcapable.sweetdependency.utils.code.entity 23 | 24 | /** 25 | * Maven POM 实体 26 | * @param groupId Group ID 27 | * @param artifactId Artifact Id 28 | * @param version 版本 29 | */ 30 | internal data class MavenPomData(internal val groupId: String, internal val artifactId: String, internal val version: String) { 31 | 32 | /** 33 | * 获取 [MavenPomData] 相对路径 34 | * @return [String] 35 | */ 36 | internal val relativePomPath get() = "${groupId.toPomPathName()}/$artifactId/$version" 37 | 38 | /** 39 | * 转换到 [MavenPomData] 目录名称 40 | * @return [String] 41 | */ 42 | private fun String.toPomPathName() = trim().replace(".", "/").replace("_", "/").replace(":", "/").replace("-", "/") 43 | } -------------------------------------------------------------------------------- /sweetdependency-gradle-plugin/src/main/java/com/highcapable/sweetdependency/utils/code/factory/CodeCompilerFactory.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * SweetDependency - An easy autowire and manage dependencies Gradle plugin. 3 | * Copyright (C) 2019 HighCapable 4 | * https://github.com/HighCapable/SweetDependency 5 | * 6 | * Apache License Version 2.0 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * https://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | * 20 | * This file is created by fankes on 2023/8/6. 21 | */ 22 | @file:Suppress("unused") 23 | 24 | package com.highcapable.sweetdependency.utils.code.factory 25 | 26 | import com.highcapable.sweetdependency.plugin.SweetDependencyExtension 27 | import com.highcapable.sweetdependency.utils.code.CodeCompiler 28 | import com.highcapable.sweetdependency.utils.code.entity.MavenPomData 29 | import com.squareup.javapoet.JavaFile 30 | import javax.tools.JavaFileObject 31 | 32 | /** 33 | * 编译 [JavaFile] 为 Maven 依赖 34 | * @param pomData Maven POM 实体 35 | * @param outputDirPath 编译输出目录路径 36 | * @param compileOnlyFiles [JavaFile] 仅编译数组 - 默认空 37 | * @throws SweetDependencyExtension 如果编译失败 38 | */ 39 | @JvmName("compileWithJavaFile") 40 | internal fun JavaFile.compile(pomData: MavenPomData, outputDirPath: String, compileOnlyFiles: List = mutableListOf()) = 41 | CodeCompiler.compile( 42 | pomData = pomData, 43 | outputDirPath = outputDirPath, 44 | files = listOf(toJavaFileObject()), 45 | compileOnlyFiles = mutableListOf().also { compileOnlyFiles.forEach { e -> it.add(e.toJavaFileObject()) } } 46 | ) 47 | 48 | /** 49 | * 编译 [JavaFile] 为 Maven 依赖 50 | * @param pomData Maven POM 实体 51 | * @param outputDirPath 编译输出目录路径 52 | * @param compileOnlyFiles [JavaFile] 仅编译数组 - 默认空 53 | * @throws SweetDependencyExtension 如果编译失败 54 | */ 55 | @JvmName("compileWithJavaFile") 56 | internal fun List.compile(pomData: MavenPomData, outputDirPath: String, compileOnlyFiles: List = mutableListOf()) = 57 | CodeCompiler.compile( 58 | pomData = pomData, 59 | outputDirPath = outputDirPath, 60 | files = mutableListOf().also { forEach { e -> it.add(e.toJavaFileObject()) } }, 61 | compileOnlyFiles = mutableListOf().also { compileOnlyFiles.forEach { e -> it.add(e.toJavaFileObject()) } } 62 | ) 63 | 64 | /** 65 | * 编译 [JavaFileObject] 为 Maven 依赖 66 | * @param pomData Maven POM 实体 67 | * @param outputDirPath 编译输出目录路径 68 | * @param compileOnlyFiles [JavaFileObject] 仅编译数组 - 默认空 69 | * @throws SweetDependencyExtension 如果编译失败 70 | */ 71 | @JvmName("compileWithJavaFileObject") 72 | internal fun JavaFileObject.compile(pomData: MavenPomData, outputDirPath: String, compileOnlyFiles: List = mutableListOf()) = 73 | CodeCompiler.compile(pomData, outputDirPath, listOf(this), compileOnlyFiles) 74 | 75 | /** 76 | * 编译 [JavaFileObject] 为 Maven 依赖 77 | * @param pomData Maven POM 实体 78 | * @param outputDirPath 编译输出目录路径 79 | * @param compileOnlyFiles [JavaFileObject] 仅编译数组 - 默认空 80 | * @throws SweetDependencyExtension 如果编译失败 81 | */ 82 | @JvmName("compileWithJavaFileObject") 83 | internal fun List.compile(pomData: MavenPomData, outputDirPath: String, compileOnlyFiles: List = mutableListOf()) = 84 | CodeCompiler.compile(pomData, outputDirPath, files = this, compileOnlyFiles) -------------------------------------------------------------------------------- /sweetdependency-gradle-plugin/src/main/java/com/highcapable/sweetdependency/utils/debug/SError.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * SweetDependency - An easy autowire and manage dependencies Gradle plugin. 3 | * Copyright (C) 2019 HighCapable 4 | * https://github.com/HighCapable/SweetDependency 5 | * 6 | * Apache License Version 2.0 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * https://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | * 20 | * This file is created by fankes on 2023/5/31. 21 | */ 22 | package com.highcapable.sweetdependency.utils.debug 23 | 24 | import com.highcapable.sweetdependency.exception.SweetDependencyUnresolvedException 25 | 26 | /** 27 | * 全局异常管理类 28 | */ 29 | internal object SError { 30 | 31 | /** 32 | * 抛出异常 33 | * @param msg 消息内容 34 | * @throws e 异常内容 - 默认空 35 | * @throws SweetDependencyUnresolvedException 36 | */ 37 | internal fun make(msg: String, e: Throwable? = null): Nothing = throw SweetDependencyUnresolvedException(msg, e) 38 | } -------------------------------------------------------------------------------- /sweetdependency-gradle-plugin/src/main/java/com/highcapable/sweetdependency/utils/yaml/Yaml.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * SweetDependency - An easy autowire and manage dependencies Gradle plugin. 3 | * Copyright (C) 2019 HighCapable 4 | * https://github.com/HighCapable/SweetDependency 5 | * 6 | * Apache License Version 2.0 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * https://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | * 20 | * This file is created by fankes on 2023/5/17. 21 | */ 22 | @file:Suppress("unused") 23 | 24 | package com.highcapable.sweetdependency.utils.yaml 25 | 26 | import com.charleskorn.kaml.YamlConfiguration 27 | import com.charleskorn.kaml.yamlMap 28 | import com.highcapable.sweetdependency.gradle.helper.GradleHelper 29 | import com.highcapable.sweetdependency.utils.hasInterpolation 30 | import com.highcapable.sweetdependency.utils.replaceInterpolation 31 | import com.highcapable.sweetdependency.utils.toFile 32 | import com.highcapable.sweetdependency.utils.yaml.factory.YamlMapEntries 33 | import com.highcapable.sweetdependency.utils.yaml.proxy.IYamlDocument 34 | import kotlinx.serialization.decodeFromString 35 | import kotlinx.serialization.serializer 36 | import com.charleskorn.kaml.Yaml as Kaml 37 | 38 | /** 39 | * YAML 文档处理类 40 | */ 41 | internal object Yaml { 42 | 43 | /** 44 | * 获取 [Kaml] 对象 45 | * @return [Kaml] 46 | */ 47 | private val kaml by lazy { Kaml(configuration = YamlConfiguration(encodeDefaults = false)) } 48 | 49 | /** 50 | * 从文件解析到 [IYamlDocument] 51 | * @param path 文件路径 52 | * @return [T] 53 | */ 54 | internal inline fun loadFromFile(path: String) = loadFromString(path.toFile().readText()) 55 | 56 | /** 57 | * 从字符串解析到 [IYamlDocument] 58 | * @param string 字符串 59 | * @return [T] 60 | */ 61 | internal inline fun loadFromString(string: String) = kaml.decodeFromString(string.flattened()) 62 | 63 | /** 64 | * 从文件解析到 [YamlMapEntries] 65 | * @param path 文件路径 66 | * @return [YamlMapEntries] 67 | */ 68 | internal fun loadFromFileAsNode(path: String) = loadFromStringAsNode(path.toFile().readText()) 69 | 70 | /** 71 | * 从字符串解析到 [YamlMapEntries] 72 | * @param string 字符串 73 | * @return [YamlMapEntries] 74 | */ 75 | internal fun loadFromStringAsNode(string: String) = kaml.parseToYamlNode(string.flattened()).yamlMap.entries 76 | 77 | /** 78 | * 序列化 [IYamlDocument] 到文件 79 | * @param path 文件路径 80 | * @param formatter 回调字符串格式化方式 81 | */ 82 | internal inline fun parseToFile(doc: T, path: String, formatter: String.() -> String = { this }) = 83 | path.toFile().writeText(kaml.encodeToString(serializer(), doc).let(formatter)) 84 | 85 | /** 86 | * 字符串平坦化处理 87 | * 88 | * - 去除字符串中以 # 开头的注释行并去除空行 89 | * - 调用 [interpFromEnv] 解析可被插值的字符串 90 | * @return [String] 91 | */ 92 | private fun String.flattened() = trimIndent() 93 | .replace("(^|\\s)#.*".toRegex(), "") 94 | .replace("(?m)^\\s*$(\\n|\\r\\n?)".toRegex(), "") 95 | .let { if (it.hasInterpolation()) it.interpFromEnv() else it } 96 | .trim() 97 | 98 | /** 99 | * 将系统属性资源值插入到当前字符串中 100 | * 101 | * 形如:${...} 102 | * 103 | * 会按照以下顺序进行查找 ↓ 104 | * 105 | * - 项目 properties 106 | * - 用户 properties 107 | * - 系统 properties 108 | * - 系统环境变量 109 | * @return [String] 110 | */ 111 | private fun String.interpFromEnv() = replaceInterpolation { key -> 112 | GradleHelper.projectProperties?.get(key)?.toString() 113 | ?: GradleHelper.userProperties?.get(key)?.toString() 114 | ?: runCatching { System.getProperties()[key]?.toString() }.getOrNull() 115 | ?: runCatching { System.getenv(key) }.getOrNull() ?: "" 116 | } 117 | } -------------------------------------------------------------------------------- /sweetdependency-gradle-plugin/src/main/java/com/highcapable/sweetdependency/utils/yaml/factory/YamlFactory.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * SweetDependency - An easy autowire and manage dependencies Gradle plugin. 3 | * Copyright (C) 2019 HighCapable 4 | * https://github.com/HighCapable/SweetDependency 5 | * 6 | * Apache License Version 2.0 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * https://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | * 20 | * This file is created by fankes on 2023/5/19. 21 | */ 22 | package com.highcapable.sweetdependency.utils.yaml.factory 23 | 24 | import com.charleskorn.kaml.YamlException 25 | import com.charleskorn.kaml.YamlMap 26 | import com.charleskorn.kaml.YamlNode 27 | import com.charleskorn.kaml.YamlScalar 28 | 29 | /** YAML 异常类型定义 */ 30 | internal typealias YamlException = YamlException 31 | 32 | /** YAML 节点数组类型定义 */ 33 | internal typealias YamlMapEntries = Map 34 | 35 | /** 36 | * 转换为 YAML 节点数组 37 | * @return [YamlMapEntries] or null 38 | */ 39 | internal fun YamlNode.asMap() = (this as? YamlMap)?.entries 40 | 41 | /** 42 | * 获取 YAML 节点是否存在 43 | * @param key 节点名称 44 | * @return [Boolean] 45 | */ 46 | internal fun YamlMapEntries.isKeyExist(key: String) = keys.singleOrNull { it.content == key } != null -------------------------------------------------------------------------------- /sweetdependency-gradle-plugin/src/main/java/com/highcapable/sweetdependency/utils/yaml/proxy/IYamlDocument.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * SweetDependency - An easy autowire and manage dependencies Gradle plugin. 3 | * Copyright (C) 2019 HighCapable 4 | * https://github.com/HighCapable/SweetDependency 5 | * 6 | * Apache License Version 2.0 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * https://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | * 20 | * This file is created by fankes on 2023/5/20. 21 | */ 22 | package com.highcapable.sweetdependency.utils.yaml.proxy 23 | 24 | import java.io.Serializable 25 | 26 | /** 27 | * YAML 文档接口 28 | */ 29 | internal interface IYamlDocument : Serializable -------------------------------------------------------------------------------- /sweetdependency-gradle-plugin/src/main/java/org/gradle/kotlin/dsl/SweetDependencyProjectExtensionFactory.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * SweetDependency - An easy autowire and manage dependencies Gradle plugin. 3 | * Copyright (C) 2019 HighCapable 4 | * https://github.com/HighCapable/SweetDependency 5 | * 6 | * Apache License Version 2.0 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * https://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | * 20 | * This file is created by fankes on 2023/6/25. 21 | */ 22 | @file:Suppress("unused", "UnusedReceiverParameter") 23 | 24 | package org.gradle.kotlin.dsl 25 | 26 | import com.highcapable.sweetdependency.manager.helper.DependencyDeployHelper 27 | import org.gradle.api.artifacts.dsl.DependencyHandler 28 | import org.gradle.plugin.use.PluginDependenciesSpec 29 | import org.gradle.plugin.use.PluginDependencySpec 30 | 31 | /** 32 | * 自动装配插件依赖 33 | * @param params 参数数组 34 | * @return [PluginDependencySpec] 35 | */ 36 | fun PluginDependenciesSpec.autowire(vararg params: Any) = DependencyDeployHelper.resolveAutowire(spec = this, params) 37 | 38 | /** 39 | * 自动装配依赖 40 | * @param params 参数数组 41 | * @return [Any] 42 | */ 43 | fun DependencyHandler.autowire(vararg params: String) = DependencyDeployHelper.resolveAutowire(params = params) -------------------------------------------------------------------------------- /sweetdependency-gradle-plugin/src/main/java/org/gradle/kotlin/dsl/SweetDependencySettingsExtensionFactory.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * SweetDependency - An easy autowire and manage dependencies Gradle plugin. 3 | * Copyright (C) 2019 HighCapable 4 | * https://github.com/HighCapable/SweetDependency 5 | * 6 | * Apache License Version 2.0 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * https://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | * 20 | * This file is created by fankes on 2023/6/3. 21 | */ 22 | @file:Suppress("unused") 23 | 24 | package org.gradle.kotlin.dsl 25 | 26 | import com.highcapable.sweetdependency.gradle.factory.configure 27 | import com.highcapable.sweetdependency.gradle.factory.get 28 | import com.highcapable.sweetdependency.plugin.extension.dsl.configure.SweetDependencyConfigureExtension 29 | import org.gradle.api.Action 30 | import org.gradle.api.initialization.Settings 31 | 32 | /** 33 | * WORKAROUND: for some reason a type-safe accessor is not generated for the extension, 34 | * even though it is present in the extension container where the plugin is applied. 35 | * This seems to work fine, and the extension methods are only available when the plugin 36 | * is actually applied. 37 | * 38 | * See related link [here](https://stackoverflow.com/questions/72627792/gradle-settings-plugin-extension) 39 | */ 40 | 41 | /** 42 | * Retrieves the [SweetDependencyConfigureExtension] extension. 43 | * @return [SweetDependencyConfigureExtension] 44 | */ 45 | val Settings.sweetDependency get() = get(SweetDependencyConfigureExtension.NAME) 46 | 47 | /** 48 | * Configures the [SweetDependencyConfigureExtension] extension. 49 | * @param configure 50 | */ 51 | fun Settings.sweetDependency(configure: Action) = configure(SweetDependencyConfigureExtension.NAME, configure) --------------------------------------------------------------------------------