diff --git a/sweetproperty-gradle-plugin/src/main/java/com/highcapable/sweetproperty/utils/code/CodeCompiler.kt b/sweetproperty-gradle-plugin/src/main/java/com/highcapable/sweetproperty/utils/code/CodeCompiler.kt index 3adb194..b0bb31e 100644 --- a/sweetproperty-gradle-plugin/src/main/java/com/highcapable/sweetproperty/utils/code/CodeCompiler.kt +++ b/sweetproperty-gradle-plugin/src/main/java/com/highcapable/sweetproperty/utils/code/CodeCompiler.kt @@ -83,8 +83,8 @@ internal object CodeCompiler { sourceFile.writeText(it.getCharContent(true).toString()) } }; outputClassesDir.deleteEmptyRecursively() - writeMetaInf(outputClassesDir.absolutePath) - writeMetaInf(outputSourcesDir.absolutePath) + writeMetaInf(outputClassesDir) + writeMetaInf(outputSourcesDir) createJarAndPom(pomData, outputDir, outputBuildDir, outputClassesDir, outputSourcesDir) } else SError.make("Failed to compile java files into path: $outputDirPath\n$diagnosticsMessage") } @@ -98,30 +98,29 @@ internal object CodeCompiler { * @param sourcesDir 编译源码目录 */ private fun createJarAndPom(pomData: MavenPomData, outputDir: File, buildDir: File, classesDir: File, sourcesDir: File) { - val pomPath = "${pomData.groupId.toPomPathName()}/${pomData.artifactId}/${pomData.version}" - val pomDir = "${outputDir.absolutePath}/$pomPath".toFile().also { if (it.exists().not()) it.mkdirs() } + val pomDir = outputDir.resolve(pomData.relativePomPath).also { if (it.exists().not()) it.mkdirs() } packageToJar(classesDir, pomDir, pomData, isSourcesJar = false) packageToJar(sourcesDir, pomDir, pomData, isSourcesJar = true) - writePom(pomDir.absolutePath, pomData) + writePom(pomDir, pomData) buildDir.deleteRecursively() } /** * 写入 META-INF/MANIFEST.MF - * @param dirPath 当前目录路径 + * @param dir 当前目录 */ - private fun writeMetaInf(dirPath: String) { - val metaInfFile = "$dirPath/META-INF".toFile().apply { mkdirs() } - "${metaInfFile.absolutePath}/MANIFEST.MF".toFile().writeText("Manifest-Version: 1.0") + private fun writeMetaInf(dir: File) { + val metaInfDir = dir.resolve("META-INF").apply { mkdirs() } + metaInfDir.resolve("MANIFEST.MF").writeText("Manifest-Version: 1.0") } /** * 写入 POM - * @param dirPath 当前目录路径 + * @param dir 当前目录 * @param pomData Maven POM 实体 */ - private fun writePom(dirPath: String, pomData: MavenPomData) = - "$dirPath/${pomData.artifactId}-${pomData.version}.pom".toFile().writeText( + private fun writePom(dir: File, pomData: MavenPomData) = + dir.resolve("${pomData.artifactId}-${pomData.version}.pom").writeText( """