Support Java package prefix in Gradle plugin
Issue #KT-17150 Fixed
This commit is contained in:
+3
-4
@@ -17,6 +17,7 @@
|
||||
package org.jetbrains.kotlin.compilerRunner
|
||||
|
||||
import org.gradle.api.Project
|
||||
import org.jetbrains.kotlin.build.JvmSourceRoot
|
||||
import org.jetbrains.kotlin.cli.common.ExitCode
|
||||
import org.jetbrains.kotlin.cli.common.arguments.CommonCompilerArguments
|
||||
import org.jetbrains.kotlin.cli.common.arguments.K2JSCompilerArguments
|
||||
@@ -29,8 +30,6 @@ import org.jetbrains.kotlin.cli.common.messages.MessageRenderer
|
||||
import org.jetbrains.kotlin.com.intellij.openapi.util.io.FileUtil
|
||||
import org.jetbrains.kotlin.config.Services
|
||||
import org.jetbrains.kotlin.daemon.client.CompileServiceSession
|
||||
import org.jetbrains.kotlin.daemon.client.DaemonReportingTargets
|
||||
import org.jetbrains.kotlin.daemon.client.launchProcessWithFallback
|
||||
import org.jetbrains.kotlin.daemon.common.*
|
||||
import org.jetbrains.kotlin.gradle.plugin.ParentLastURLClassLoader
|
||||
import org.jetbrains.kotlin.gradle.plugin.kotlinDebug
|
||||
@@ -38,7 +37,6 @@ import org.jetbrains.kotlin.incremental.*
|
||||
import java.io.ByteArrayOutputStream
|
||||
import java.io.File
|
||||
import java.io.PrintStream
|
||||
import kotlin.concurrent.thread
|
||||
|
||||
internal const val KOTLIN_COMPILER_EXECUTION_STRATEGY_PROPERTY = "kotlin.compiler.execution.strategy"
|
||||
internal const val DAEMON_EXECUTION_STRATEGY = "daemon"
|
||||
@@ -85,6 +83,7 @@ internal class GradleCompilerRunner(private val project: Project) : KotlinCompil
|
||||
fun runJvmCompiler(
|
||||
sourcesToCompile: List<File>,
|
||||
javaSourceRoots: Iterable<File>,
|
||||
javaPackagePrefix: String?,
|
||||
args: K2JVMCompilerArguments,
|
||||
environment: GradleCompilerEnvironment
|
||||
): ExitCode {
|
||||
@@ -93,7 +92,7 @@ internal class GradleCompilerRunner(private val project: Project) : KotlinCompil
|
||||
isTest = false,
|
||||
outputDir = args.destinationAsFile,
|
||||
sourcesToCompile = sourcesToCompile,
|
||||
javaSourceRoots = javaSourceRoots,
|
||||
javaSourceRoots = javaSourceRoots.map { JvmSourceRoot(it, javaPackagePrefix) },
|
||||
classpath = args.classpathAsList,
|
||||
friendDirs = args.friendPaths?.map(::File) ?: emptyList())
|
||||
args.buildFile = buildFile.absolutePath
|
||||
|
||||
+9
-2
@@ -3,7 +3,9 @@ package org.jetbrains.kotlin.gradle.internal
|
||||
import org.gradle.api.GradleException
|
||||
import org.gradle.api.file.FileCollection
|
||||
import org.gradle.api.internal.ConventionTask
|
||||
import org.gradle.api.tasks.*
|
||||
import org.gradle.api.tasks.InputFiles
|
||||
import org.gradle.api.tasks.OutputDirectory
|
||||
import org.gradle.api.tasks.TaskAction
|
||||
import org.jetbrains.kotlin.cli.common.arguments.K2JVMCompilerArguments
|
||||
import org.jetbrains.kotlin.com.intellij.openapi.util.io.FileUtil
|
||||
import org.jetbrains.kotlin.compilerRunner.GradleCompilerEnvironment
|
||||
@@ -67,7 +69,12 @@ open class KaptTask : ConventionTask() {
|
||||
}
|
||||
|
||||
val compilerRunner = GradleCompilerRunner(project)
|
||||
val exitCode = compilerRunner.runJvmCompiler(sourceRoots.kotlinSourceFiles, sourceRoots.javaSourceRoots, args, environment)
|
||||
val exitCode = compilerRunner.runJvmCompiler(
|
||||
sourceRoots.kotlinSourceFiles,
|
||||
sourceRoots.javaSourceRoots,
|
||||
kotlinCompileTask.javaPackagePrefix,
|
||||
args,
|
||||
environment)
|
||||
throwGradleExceptionIfError(exitCode)
|
||||
}
|
||||
|
||||
|
||||
+14
-1
@@ -232,6 +232,13 @@ open class KotlinCompile : AbstractKotlinCompile<K2JVMCompilerArguments>(), Kotl
|
||||
|
||||
val kaptOptions = KaptOptions()
|
||||
|
||||
/** A package prefix that is used for locating Java sources in a directory structure with non-full-depth packages.
|
||||
*
|
||||
* Example: a Java source file with `package com.example.my.package` is located in directory `src/main/java/my/package`.
|
||||
* Then, for the Kotlin compilation to locate the source file, use package prefix `"com.example"` */
|
||||
@Input
|
||||
var javaPackagePrefix: String? = null
|
||||
|
||||
internal val pluginOptions = CompilerPluginOptions()
|
||||
internal var artifactDifferenceRegistryProvider: ArtifactDifferenceRegistryProvider? = null
|
||||
internal var artifactFile: File? = null
|
||||
@@ -302,7 +309,13 @@ open class KotlinCompile : AbstractKotlinCompile<K2JVMCompilerArguments>(), Kotl
|
||||
}
|
||||
|
||||
try {
|
||||
val exitCode = compilerRunner.runJvmCompiler(sourceRoots.kotlinSourceFiles, sourceRoots.javaSourceRoots, args, environment)
|
||||
val exitCode = compilerRunner.runJvmCompiler(
|
||||
sourceRoots.kotlinSourceFiles,
|
||||
sourceRoots.javaSourceRoots,
|
||||
javaPackagePrefix,
|
||||
args,
|
||||
environment)
|
||||
|
||||
processCompilerExitCode(exitCode)
|
||||
artifactDifferenceRegistryProvider?.withRegistry(reporter) {
|
||||
it.flush(true)
|
||||
|
||||
Reference in New Issue
Block a user