diff --git a/flexilocale-gradle-plugin/src/main/kotlin/com/highcapable/flexilocale/plugin/config/proxy/IFlexiLocaleConfigs.kt b/flexilocale-gradle-plugin/src/main/kotlin/com/highcapable/flexilocale/plugin/config/proxy/IFlexiLocaleConfigs.kt index b670398..a6a8013 100644 --- a/flexilocale-gradle-plugin/src/main/kotlin/com/highcapable/flexilocale/plugin/config/proxy/IFlexiLocaleConfigs.kt +++ b/flexilocale-gradle-plugin/src/main/kotlin/com/highcapable/flexilocale/plugin/config/proxy/IFlexiLocaleConfigs.kt @@ -37,6 +37,11 @@ internal interface IFlexiLocaleConfigs { * "build/generated/[FlexiLocaleProperties.PROJECT_MODULE_NAME]" */ internal const val DEFAULT_GENERATE_DIR_PATH = "build/generated/${FlexiLocaleProperties.PROJECT_MODULE_NAME}" + + /** + * 默认的部署 `sourceSet` 名称 + */ + internal const val DEFAULT_SOURCE_SET_NAME = "main" } /** 是否启用插件 */ @@ -45,6 +50,9 @@ internal interface IFlexiLocaleConfigs { /** 自定义生成的目录路径 */ val generateDirPath: String + /** 自定义部署的 `sourceSet` 名称 */ + val sourceSetName: String + /** 自定义生成的包名 */ val packageName: String @@ -58,5 +66,5 @@ internal interface IFlexiLocaleConfigs { * 获取内部 [hashCode] * @return [Int] */ - fun innerHashCode() = "$isEnable$generateDirPath$packageName$className$isEnableRestrictedAccess".hashCode() + fun innerHashCode() = "$isEnable$generateDirPath$sourceSetName$packageName$className$isEnableRestrictedAccess".hashCode() } \ No newline at end of file diff --git a/flexilocale-gradle-plugin/src/main/kotlin/com/highcapable/flexilocale/plugin/extension/dsl/configure/FlexiLocaleConfigureExtension.kt b/flexilocale-gradle-plugin/src/main/kotlin/com/highcapable/flexilocale/plugin/extension/dsl/configure/FlexiLocaleConfigureExtension.kt index cb0023e..9867b52 100644 --- a/flexilocale-gradle-plugin/src/main/kotlin/com/highcapable/flexilocale/plugin/extension/dsl/configure/FlexiLocaleConfigureExtension.kt +++ b/flexilocale-gradle-plugin/src/main/kotlin/com/highcapable/flexilocale/plugin/extension/dsl/configure/FlexiLocaleConfigureExtension.kt @@ -59,6 +59,16 @@ open class FlexiLocaleConfigureExtension internal constructor() { var generateDirPath = IFlexiLocaleConfigs.DEFAULT_GENERATE_DIR_PATH @JvmName("generateDirPath") set + /** + * 自定义部署的 `sourceSet` 名称 + * + * 如果你的项目源码部署名称不是默认值 - 可以在这里自定义 + * + * 默认为 [IFlexiLocaleConfigs.DEFAULT_SOURCE_SET_NAME] + */ + var sourceSetName = IFlexiLocaleConfigs.DEFAULT_SOURCE_SET_NAME + @JvmName("sourceSetName") set + /** * 自定义生成的包名 * @@ -104,12 +114,14 @@ open class FlexiLocaleConfigureExtension internal constructor() { className.checkingValidClassName() val currentEnable = isEnable val currentGenerateDirPath = project.file(generateDirPath).absolutePath + val currentSourceSetName = sourceSetName val currentPackageName = packageName val currentClassName = "${className.ifBlank { project.fullName().uppercamelcase() }}Locale" val currentEnableRestrictedAccess = isEnableRestrictedAccess return object : IFlexiLocaleConfigs { override val isEnable get() = currentEnable override val generateDirPath get() = currentGenerateDirPath + override val sourceSetName get() = currentSourceSetName override val packageName get() = currentPackageName override val className get() = currentClassName override val isEnableRestrictedAccess get() = currentEnableRestrictedAccess diff --git a/flexilocale-gradle-plugin/src/main/kotlin/com/highcapable/flexilocale/plugin/helper/LocaleAnalysisHelper.kt b/flexilocale-gradle-plugin/src/main/kotlin/com/highcapable/flexilocale/plugin/helper/LocaleAnalysisHelper.kt index a5bfb25..38629cb 100644 --- a/flexilocale-gradle-plugin/src/main/kotlin/com/highcapable/flexilocale/plugin/helper/LocaleAnalysisHelper.kt +++ b/flexilocale-gradle-plugin/src/main/kotlin/com/highcapable/flexilocale/plugin/helper/LocaleAnalysisHelper.kt @@ -130,8 +130,12 @@ internal object LocaleAnalysisHelper { */ private fun initializePlugins(project: Project) { runCatching { - fun BaseExtension.updateSourceDirs() = sourceSets.configureEach { kotlin.srcDir(configs.generateDirPath) } - fun KotlinProjectExtension.updateSourceDirs() = sourceSets.configureEach { kotlin.srcDir(configs.generateDirPath) } + fun BaseExtension.updateSourceDirs() = sourceSets.firstOrNull { + it.name == configs.sourceSetName + }?.kotlin?.srcDir(configs.generateDirPath) ?: FLog.warn("Could not found source set \"${configs.sourceSetName}\"") + fun KotlinProjectExtension.updateSourceDirs() = sourceSets.firstOrNull { + it.name == configs.sourceSetName + }?.kotlin?.srcDir(configs.generateDirPath) ?: FLog.warn("Could not found source set \"${configs.sourceSetName}\"") fun BaseVariant.updateResDirectories() = sourceSets.forEach { provide -> provide.resDirectories?.also { resDirectories.addAll(it) } } project.plugins.withId(APPLICATION_PLUGIN_NAME) { project.get().also { extension ->