Skip to content

Commit

Permalink
update readme
Browse files Browse the repository at this point in the history
  • Loading branch information
ltttttttttttt committed Oct 23, 2022
1 parent e9e326d commit bc0545f
Show file tree
Hide file tree
Showing 3 changed files with 128 additions and 39 deletions.
83 changes: 64 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,25 +49,6 @@ plugins {
id("com.google.devtools.ksp") version "1.7.10-1.0.6"//this, The left 1.7.10 corresponds to your the Kotlin version,more version: https://github.com/google/ksp/releases
}

buildTypes {
release {
...
kotlin {
sourceSets.main {
kotlin.srcDir("build/generated/ksp/release/kotlin")//this
}
}
}
debug {
...
kotlin {
sourceSets.main {
kotlin.srcDir("build/generated/ksp/debug/kotlin")//this
}
}
}
}

dependencies {
...
implementation("com.github.ltttttttttttt:Buff:$version")//this, such as 0.0.2
Expand Down Expand Up @@ -96,4 +77,68 @@ val buffBean = BuffBean(0)
val bean = buffBean.addBuff()//Transform to the BuffBeanWithBuff
bean.name//The name's getter and setter have the effect of MutableState<T>
bean.removeBuff()//Fallback to BuffBean(optional)
```

Step 4.Add ksp dir to the srcDir

Your app dir, build.gradle.kts add:

```kotlin
//If your project is the android, and the productFlavors is not set
android {
buildTypes {
release {
kotlin {
sourceSets.main {
kotlin.srcDir("build/generated/ksp/release/kotlin")
}
}
}
debug {
kotlin {
sourceSets.main {
kotlin.srcDir("build/generated/ksp/debug/kotlin")
}
}
}
}
kotlin {
sourceSets.test {
kotlin.srcDir("build/generated/ksp/test/kotlin")
}
}
}

//If your project is the android, and the productFlavors is set
applicationVariants.all {
outputs.all {
val flavorAndBuildTypeName = name
kotlin {
sourceSets.main {
kotlin.srcDir(
"build/generated/ksp/${
flavorAndBuildTypeName.split("-").let {
it.first() + it.last()[0].toUpperCase() + it.last().substring(1)
}
}/kotlin"
)
}
}
}
}
kotlin {
sourceSets.test {
kotlin.srcDir("build/generated/ksp/test/kotlin")
}
}

//If your project is the jvm or more
kotlin {
sourceSets.main {
kotlin.srcDir("build/generated/ksp/main/kotlin")
}
sourceSets.test {
kotlin.srcDir("build/generated/ksp/test/kotlin")
}
}
```
83 changes: 64 additions & 19 deletions README_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,25 +54,6 @@ plugins {
id("com.google.devtools.ksp") version "1.7.10-1.0.6"//this,前面的1.7.10对应你的kotlin版本,更多版本参考: https://github.com/google/ksp/releases
}

buildTypes {
release {
...
kotlin {
sourceSets.main {
kotlin.srcDir("build/generated/ksp/release/kotlin")//this todo 后续修改为自动获取
}
}
}
debug {
...
kotlin {
sourceSets.main {
kotlin.srcDir("build/generated/ksp/debug/kotlin")//this
}
}
}
}

dependencies {
...
implementation("com.github.ltttttttttttt:Buff:$version")//this,比如0.0.2
Expand Down Expand Up @@ -100,4 +81,68 @@ val buffBean = BuffBean(0)//这个BuffBean可以自己new出来,也可以通过
val bean = buffBean.addBuff()//增加Buff,类型改为BuffBeanWithBuff
bean.name//这个name的get和set就有了MutableState<T>的效果
bean.removeBuff()//退回为BuffBean(可选方法,可以不使用)
```

Step 4.将ksp的代码生成目录加入源码目录

在app模块目录内的build.gradle.kts内添加:

```kotlin
//如果你的是安卓项目,且未设置多渠道
android {
buildTypes {
release {
kotlin {
sourceSets.main {
kotlin.srcDir("build/generated/ksp/release/kotlin")
}
}
}
debug {
kotlin {
sourceSets.main {
kotlin.srcDir("build/generated/ksp/debug/kotlin")
}
}
}
}
kotlin {
sourceSets.test {
kotlin.srcDir("build/generated/ksp/test/kotlin")
}
}
}

//如果你的是安卓项目,且设置了多渠道
applicationVariants.all {
outputs.all {
val flavorAndBuildTypeName = name
kotlin {
sourceSets.main {
kotlin.srcDir(
"build/generated/ksp/${
flavorAndBuildTypeName.split("-").let {
it.first() + it.last()[0].toUpperCase() + it.last().substring(1)
}
}/kotlin"
)
}
}
}
}
kotlin {
sourceSets.test {
kotlin.srcDir("build/generated/ksp/test/kotlin")
}
}

//如果你的是jvm等项目
kotlin {
sourceSets.main {
kotlin.srcDir("build/generated/ksp/main/kotlin")
}
sourceSets.test {
kotlin.srcDir("build/generated/ksp/test/kotlin")
}
}
```
1 change: 0 additions & 1 deletion buff/src/main/java/com/lt/buff/BuffVisitor.kt
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ internal class BuffVisitor(private val environment: SymbolProcessorEnvironment)
.find { it.shortName.getShortName() == buffName } != null
val type = ksType.declaration.simpleName.getShortName()
val nullable = if (ksType.nullability == Nullability.NULLABLE) "?" else ""
environment.logger.warn(type)
//写入构造内的普通字段
file.appendText(" ${if (it.isVal) "val" else "var"} $name: ${if (isBuffBean) "$type$suffix$nullable" else "$type$nullable"},\n")
functionFields.add(FunctionFieldsInfo(name, true, isBuffBean))
Expand Down

0 comments on commit bc0545f

Please sign in to comment.