1+ import org.gradle.api.Plugin
2+ import org.gradle.api.Project
3+ import com.android.build.gradle.LibraryExtension
4+ import org.gradle.api.JavaVersion
5+
6+ class PlutoGradlePlugin : Plugin <Project > {
7+ override fun apply (project : Project ) {
8+ applyPlugins(project)
9+ setProjectConfig(project)
10+ }
11+
12+ private fun applyPlugins (target : Project ) {
13+ target.apply {
14+ plugin(" android-library" )
15+ plugin(" kotlin-android" )
16+ }
17+ }
18+
19+ private fun setProjectConfig (target : Project ) {
20+ val version = Versioning .loadVersioningData()
21+ val verCode = version[" code" ] as Int
22+ val verPublish = version[" publish" ] as String
23+ val verGitSHA = version[" gitSha" ] as String
24+ target.android().apply {
25+ compileSdk = ProjectConfig .compileSdk
26+ buildToolsVersion = ProjectConfig .buildTools
27+ buildFeatures {
28+ buildConfig = true
29+ viewBinding = true
30+ }
31+ defaultConfig {
32+ minSdk = ProjectConfig .minSdk
33+ buildConfigField(" String" , " VERSION_NAME" , " \" $verPublish \" " )
34+ buildConfigField(" long" , " VERSION_CODE" , " $verCode " )
35+ buildConfigField(" String" , " GIT_SHA" , " \" $verGitSHA \" " )
36+ }
37+
38+ buildTypes {
39+ getByName(" release" ) {
40+ // isDebuggable = true
41+ isMinifyEnabled = false
42+ isShrinkResources = false
43+ }
44+ }
45+
46+ compileOptions {
47+ sourceCompatibility = JavaVersion .toVersion(ProjectConfig .java)
48+ targetCompatibility = JavaVersion .toVersion(ProjectConfig .java)
49+ }
50+ lint {
51+ abortOnError = false
52+ targetSdk = ProjectConfig .targetSdk
53+ }
54+ }
55+ }
56+
57+ private fun Project.android (): LibraryExtension {
58+ return extensions.getByType(LibraryExtension ::class .java)
59+ }
60+ }
0 commit comments