[KAPT] Disable JPMS when running annotation processing
If sources contain module-info.java javac tries to validate modules existence/visibility during AP phase and fails, because we don't specify modules-path/patch-module. All these checks will be done in kotlin compiler and in javac for java classes. And it is not necessary to do it in AP too. So we go for easiest path possible - disable jpms for AP. #KT-32202 Fixed
This commit is contained in:
@@ -120,12 +120,10 @@ open class KaptContext(val options: KaptOptions, val withJdk: Boolean, val logge
|
||||
options.compileClasspath + options.compiledSources + options.classesOutputDir
|
||||
}
|
||||
|
||||
putJavacOption("CLASSPATH", "CLASS_PATH",
|
||||
compileClasspath.joinToString(File.pathSeparator) { it.canonicalPath })
|
||||
putJavacOption("CLASSPATH", "CLASS_PATH", compileClasspath.makePathsString())
|
||||
|
||||
@Suppress("SpellCheckingInspection")
|
||||
putJavacOption("PROCESSORPATH", "PROCESSOR_PATH",
|
||||
options.processingClasspath.joinToString(File.pathSeparator) { it.canonicalPath })
|
||||
putJavacOption("PROCESSORPATH", "PROCESSOR_PATH", options.processingClasspath.makePathsString())
|
||||
|
||||
put(Option.S, options.sourcesOutputDir.canonicalPath)
|
||||
put(Option.D, options.classesOutputDir.canonicalPath)
|
||||
@@ -164,4 +162,10 @@ open class KaptContext(val options: KaptOptions, val withJdk: Boolean, val logge
|
||||
compiler.close()
|
||||
fileManager.close()
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
const val MODULE_INFO_FILE = "module-info.java"
|
||||
|
||||
private fun Iterable<File>.makePathsString(): String = joinToString(File.pathSeparator) { it.canonicalPath }
|
||||
}
|
||||
}
|
||||
|
||||
+13
-4
@@ -38,9 +38,18 @@ fun KaptContext.doAnnotationProcessing(
|
||||
|
||||
val wrappedProcessors = processors.map { ProcessorWrapper(it) }
|
||||
|
||||
val javaSourcesToProcess = run {
|
||||
//module descriptor should be in root package, but here we filter it from everywhere (bc we don't have knowledge about root here)
|
||||
val filtered = javaSourceFiles.filterNot { it.name == KaptContext.MODULE_INFO_FILE }
|
||||
if (filtered.size != javaSourceFiles.size) {
|
||||
logger.info("${KaptContext.MODULE_INFO_FILE} is removed from sources files to disable JPMS")
|
||||
}
|
||||
filtered
|
||||
}
|
||||
|
||||
val compilerAfterAP: JavaCompiler
|
||||
try {
|
||||
if (javaSourceFiles.isEmpty() && binaryTypesToReprocess.isEmpty() && additionalSources.isEmpty()) {
|
||||
if (javaSourcesToProcess.isEmpty() && binaryTypesToReprocess.isEmpty() && additionalSources.isEmpty()) {
|
||||
if (logger.isVerbose) {
|
||||
logger.info("Skipping annotation processing as all sources are up-to-date.")
|
||||
}
|
||||
@@ -55,10 +64,10 @@ fun KaptContext.doAnnotationProcessing(
|
||||
}
|
||||
|
||||
if (logger.isVerbose) {
|
||||
logger.info("Processing java sources with annotation processors: ${javaSourceFiles.joinToString()}")
|
||||
logger.info("Processing java sources with annotation processors: ${javaSourcesToProcess.joinToString()}")
|
||||
logger.info("Processing types with annotation processors: ${binaryTypesToReprocess.joinToString()}")
|
||||
}
|
||||
val parsedJavaFiles = parseJavaFiles(javaSourceFiles)
|
||||
val parsedJavaFiles = parseJavaFiles(javaSourcesToProcess)
|
||||
|
||||
val sourcesStructureListener = cacheManager?.let {
|
||||
if (processors.any { it.isUnableToRunIncrementally() }) return@let null
|
||||
@@ -231,4 +240,4 @@ private fun KaptContext.initModulesIfNeeded(files: JavacList<JCTree.JCCompilatio
|
||||
}
|
||||
|
||||
return files
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user