add kotlinOptions to tasks with type kotlinCompile. Allows to set kotlin compiler options directly
This commit is contained in:
@@ -26,6 +26,11 @@
|
||||
<version>4.11</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>commons-lang</groupId>
|
||||
<artifactId>commons-lang</artifactId>
|
||||
<version>2.3</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.google.guava</groupId>
|
||||
<artifactId>guava</artifactId>
|
||||
|
||||
+21
-15
@@ -30,6 +30,7 @@ import org.gradle.api.logging.Logger
|
||||
import org.gradle.api.logging.Logging
|
||||
import org.apache.commons.io.FileUtils
|
||||
import java.io.IOException
|
||||
import org.apache.commons.lang.StringUtils
|
||||
|
||||
public open class KotlinCompile(): AbstractCompile() {
|
||||
|
||||
@@ -37,6 +38,9 @@ public open class KotlinCompile(): AbstractCompile() {
|
||||
val compiler = K2JVMCompiler()
|
||||
val logger = getLogger()
|
||||
|
||||
public val kotlinOptions: K2JVMCompilerArguments = K2JVMCompilerArguments()
|
||||
|
||||
|
||||
// override setSource to track source directory sets
|
||||
override fun setSource(source: Any?) {
|
||||
srcDirsRoots.clear()
|
||||
@@ -70,7 +74,7 @@ public open class KotlinCompile(): AbstractCompile() {
|
||||
|
||||
override fun compile() {
|
||||
|
||||
val args = K2JVMCompilerArguments()
|
||||
val args = kotlinOptions
|
||||
|
||||
val javaSrcRoots = HashSet<File>()
|
||||
val sources = ArrayList<File>()
|
||||
@@ -92,19 +96,21 @@ public open class KotlinCompile(): AbstractCompile() {
|
||||
return
|
||||
}
|
||||
|
||||
args.setSourceDirs(sources.map { it.getAbsolutePath() })
|
||||
val customSources = args.getSourceDirs();
|
||||
if (customSources == null || customSources.isEmpty()) {
|
||||
args.setSourceDirs(sources.map { it.getAbsolutePath() })
|
||||
}
|
||||
|
||||
val gradleClasspath = getClasspath()
|
||||
val effectiveClassPath = (javaSrcRoots + gradleClasspath).makeString(File.pathSeparator)
|
||||
|
||||
args.setClasspath(effectiveClassPath)
|
||||
if (StringUtils.isEmpty(kotlinOptions.classpath)) {
|
||||
val gradleClasspath = getClasspath()
|
||||
val effectiveClassPath = (javaSrcRoots + gradleClasspath).makeString(File.pathSeparator)
|
||||
args.setClasspath(effectiveClassPath)
|
||||
}
|
||||
|
||||
val embeddedAnnotations = getAnnotations()
|
||||
|
||||
args.outputDir = getDestinationDir()?.getPath()
|
||||
args.noJdkAnnotations = true
|
||||
args.annotations = embeddedAnnotations.getPath()
|
||||
args.noStdlib = true
|
||||
args.outputDir =if (StringUtils.isEmpty(kotlinOptions.outputDir)) { getDestinationDir()?.getPath() } else { kotlinOptions.outputDir }
|
||||
args.annotations = if (StringUtils.isEmpty(kotlinOptions.annotations)) { embeddedAnnotations.getPath() } else { kotlinOptions.annotations }
|
||||
|
||||
val logger = Logging.getLogger(getClass())
|
||||
val messageCollector = GradleMessageCollector(logger)
|
||||
@@ -127,7 +133,7 @@ public open class KotlinCompile(): AbstractCompile() {
|
||||
fun getAnnotations(): File {
|
||||
val jdkAnnotations: String = "kotlin-jdk-annotations.jar"
|
||||
val jdkAnnotationsResource = Resources.getResource(jdkAnnotations) ?:
|
||||
throw GradleException(jdkAnnotations + " not found in Kotlin gradle plugin classpath")
|
||||
throw GradleException(jdkAnnotations + " not found in Kotlin gradle plugin classpath")
|
||||
|
||||
val jdkAnnotationsTempDir = Files.createTempDir()
|
||||
val jdkAnnotationsFile = File(jdkAnnotationsTempDir, jdkAnnotations)
|
||||
@@ -231,10 +237,10 @@ class GradleMessageCollector(val logger : Logger): MessageCollector {
|
||||
val text = position + message
|
||||
|
||||
when (severity) {
|
||||
in CompilerMessageSeverity.VERBOSE -> logger.debug(text)
|
||||
in CompilerMessageSeverity.ERRORS -> logger.error(text)
|
||||
CompilerMessageSeverity.INFO -> logger.info(text)
|
||||
else -> logger.warn(text)
|
||||
in CompilerMessageSeverity.VERBOSE -> logger.debug(text)
|
||||
in CompilerMessageSeverity.ERRORS -> logger.error(text)
|
||||
CompilerMessageSeverity.INFO -> logger.info(text)
|
||||
else -> logger.warn(text)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,6 +32,12 @@ task show << {
|
||||
buildscript.configurations.classpath.each { println it }
|
||||
}
|
||||
|
||||
|
||||
compileKotlin {
|
||||
kotlinOptions.annotations = "externalAnnotations"
|
||||
}
|
||||
|
||||
|
||||
task wrapper(type: Wrapper) {
|
||||
gradleVersion="1.4"
|
||||
}
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
<root>
|
||||
<item name='com.google.common.base.Joiner com.google.common.base.Joiner on(java.lang.String)'>
|
||||
<annotation name='jet.runtime.typeinfo.KotlinSignature'>
|
||||
<val name="value" val=""fun on(separator : String?) : Joiner""/>
|
||||
</annotation>
|
||||
</item>
|
||||
<item name='com.google.common.base.Joiner com.google.common.base.Joiner.MapJoiner withKeyValueSeparator(java.lang.String)'>
|
||||
<annotation name='jet.runtime.typeinfo.KotlinSignature'>
|
||||
<val name="value"
|
||||
val=""fun withKeyValueSeparator(keyValueSeparator : String?) : Joiner.MapJoiner?""/>
|
||||
</annotation>
|
||||
</item>
|
||||
<item name='com.google.common.base.Joiner com.google.common.base.Joiner skipNulls()'>
|
||||
<annotation name='jet.runtime.typeinfo.KotlinSignature'>
|
||||
<val name="value" val=""fun skipNulls() : Joiner""/>
|
||||
</annotation>
|
||||
</item>
|
||||
</root>
|
||||
+2
-2
@@ -13,8 +13,8 @@ class KotlinGreetingJoiner(val greeter : Greeter) {
|
||||
}
|
||||
|
||||
fun getJoinedGreeting() : String? {
|
||||
val joiner = Joiner.on(" and ")?.skipNulls();
|
||||
return "${greeter.getGreeting()} ${joiner?.join(names)}"
|
||||
val joiner = Joiner.on(" and ").skipNulls();
|
||||
return "${greeter.getGreeting()} ${joiner.join(names)}"
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user