refactor: using new way to checking load build script class exists

This commit is contained in:
2023-09-06 19:33:17 +08:00
parent ff0ae7f0ab
commit 6fedc9ef50
2 changed files with 11 additions and 4 deletions

View File

@@ -85,9 +85,9 @@ internal fun Project.addDependencyToBuildScript(repositoryPath: String, pomData:
/**
* 装载构建脚本的 [Class]
* @param name [Class] 完整名称
* @return [Class]
* @return [Class] or null
*/
internal fun Project.loadBuildScriptClass(name: String) = buildscript.classLoader.loadClass(name)
internal fun Project.loadBuildScriptClass(name: String) = runCatching { buildscript.classLoader.loadClass(name) }.getOrNull()
/**
* 获取指定项目部署的插件依赖数组 (实时)

View File

@@ -120,7 +120,7 @@ internal object DependencyDeployHelper {
* @param rootProject 当前根项目
*/
internal fun resolveAccessors(rootProject: Project) {
if (Dependencies.isOutdate || accessorsDir.isEmpty())
if (Dependencies.isOutdate || accessorsDir.resolve(accessorsPomData.relativePomPath).isEmpty())
accessorsGenerator.build().compile(accessorsPomData, accessorsDir.absolutePath, accessorsGenerator.compileStubFiles)
rootProject.addDependencyToBuildScript(accessorsDir.absolutePath, accessorsPomData)
}
@@ -132,7 +132,14 @@ internal object DependencyDeployHelper {
*/
internal fun deployAccessors(project: Project, extension: ExtensionAware) =
accessorsGenerator.librariesClasses.forEach { (name, className) ->
extension.getOrCreate(name, project.loadBuildScriptClass(className))
val accessorsClass = project.loadBuildScriptClass(className) ?: SError.make(
"""
Generated class "$className" not found, stop loading $project
Please check whether the initialization process is interrupted and re-run Gradle Sync
If this doesn't work, please manually delete the entire "${accessorsDir.absolutePath}" directory
""".trimIndent()
)
extension.getOrCreate(name, accessorsClass)
}
/**