diff --git a/libraries/examples/kotlin-gradle-subplugin-example/pom.xml b/libraries/examples/kotlin-gradle-subplugin-example/pom.xml
new file mode 100644
index 00000000000..41243f1caf8
--- /dev/null
+++ b/libraries/examples/kotlin-gradle-subplugin-example/pom.xml
@@ -0,0 +1,106 @@
+
+
+
+ 4.0.0
+
+ 1.4.1
+ 3.0.4
+
+
+
+ org.jetbrains.kotlin
+ kotlin-project
+ 0.1-SNAPSHOT
+ ../../pom.xml
+
+
+ kotlin-gradle-subplugin-example
+ jar
+
+ Sample Kotlin Gradle subplugin
+
+
+
+ org.jetbrains.kotlin
+ kotlin-stdlib
+ ${project.version}
+ provided
+
+
+ org.jetbrains.kotlin
+ kotlin-gradle-plugin-api
+ ${project.version}
+
+
+ org.jetbrains.kotlin
+ gradle-api
+ 1.6
+
+
+ org.jetbrains.kotlin
+ kotlin-compiler
+ ${project.version}
+ provided
+
+
+
+
+ src/main/kotlin
+ src/test/kotlin
+
+
+
+ src/main/resources
+ true
+
+
+
+
+
+ kotlin-maven-plugin
+ org.jetbrains.kotlin
+ ${project.version}
+
+
+ ${basedir}/kotlinAnnotation
+
+
+
+
+
+ compile
+ compile
+ compile
+
+
+ ${project.basedir}/src/main/kotlin
+
+
+
+
+
+ test-compile
+ test-compile
+ test-compile
+
+
+
+
+
+ maven-deploy-plugin
+
+ true
+
+
+
+
+
+
+
+ jetbrains-utils
+ http://repository.jetbrains.com/utils
+
+
+
diff --git a/libraries/examples/kotlin-gradle-subplugin-example/src/main/kotlin/example/CompilerPlugin.kt b/libraries/examples/kotlin-gradle-subplugin-example/src/main/kotlin/example/CompilerPlugin.kt
new file mode 100644
index 00000000000..864203051c8
--- /dev/null
+++ b/libraries/examples/kotlin-gradle-subplugin-example/src/main/kotlin/example/CompilerPlugin.kt
@@ -0,0 +1,56 @@
+/*
+ * Copyright 2010-2015 JetBrains s.r.o.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package example
+
+import org.jetbrains.kotlin.config.CompilerConfigurationKey
+import org.jetbrains.kotlin.compiler.plugin.CommandLineProcessor
+import org.jetbrains.kotlin.compiler.plugin.CliOption
+import org.jetbrains.kotlin.config.CompilerConfiguration
+import org.jetbrains.kotlin.compiler.plugin.CliOptionProcessingException
+import org.jetbrains.kotlin.compiler.plugin.ComponentRegistrar
+import com.intellij.mock.MockProject
+import org.jetbrains.kotlin.extensions.ExternalDeclarationsProvider
+import org.jetbrains.kotlin.codegen.extensions.ExpressionCodegenExtension
+
+public object ExampleConfigurationKeys {
+ public val EXAMPLE_KEY: CompilerConfigurationKey = CompilerConfigurationKey.create("example argument")
+}
+
+public class ExampleCommandLineProcessor : CommandLineProcessor {
+ class object {
+ public val EXAMPLE_PLUGIN_ID: String = "example.plugin"
+ public val EXAMPLE_OPTION: CliOption = CliOption("exampleKey", "", "")
+ }
+
+ override val pluginId: String = EXAMPLE_PLUGIN_ID
+ override val pluginOptions: Collection = listOf(EXAMPLE_OPTION)
+
+ override fun processOption(option: CliOption, value: String, configuration: CompilerConfiguration) {
+ when (option) {
+ EXAMPLE_OPTION -> configuration.put(ExampleConfigurationKeys.EXAMPLE_KEY, value)
+ else -> throw CliOptionProcessingException("Unknown option: ${option.name}")
+ }
+ }
+}
+
+public class ExampleComponentRegistrar : ComponentRegistrar {
+
+ public override fun registerProjectComponents(project: MockProject, configuration: CompilerConfiguration) {
+ val exampleValue = configuration.get(ExampleConfigurationKeys.EXAMPLE_KEY)
+ println("Project component registration: $exampleValue")
+ }
+}
\ No newline at end of file
diff --git a/libraries/examples/kotlin-gradle-subplugin-example/src/main/kotlin/example/ExampleSubplugin.kt b/libraries/examples/kotlin-gradle-subplugin-example/src/main/kotlin/example/ExampleSubplugin.kt
new file mode 100644
index 00000000000..9515b0604ce
--- /dev/null
+++ b/libraries/examples/kotlin-gradle-subplugin-example/src/main/kotlin/example/ExampleSubplugin.kt
@@ -0,0 +1,42 @@
+/*
+ * Copyright 2010-2015 JetBrains s.r.o.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package example
+
+import org.jetbrains.kotlin.gradle.plugin.KotlinGradleSubplugin
+import org.gradle.api.Project
+import org.gradle.api.tasks.compile.AbstractCompile
+import org.jetbrains.kotlin.gradle.plugin.SubpluginOption
+
+public class ExampleSubplugin : KotlinGradleSubplugin {
+
+ override fun getExtraArguments(project: Project, task: AbstractCompile): List? {
+ println("ExampleSubplugin loaded")
+ return listOf(SubpluginOption("exampleKey", "exampleValue"))
+ }
+
+ override fun getPluginName(): String {
+ return "example.plugin"
+ }
+
+ override fun getGroupName(): String {
+ return "org.jetbrains.kotlin"
+ }
+
+ override fun getArtifactName(): String {
+ return "kotlin-gradle-subplugin-example"
+ }
+}
\ No newline at end of file
diff --git a/libraries/examples/kotlin-gradle-subplugin-example/src/main/resources/META-INF/services/org.jetbrains.kotlin.compiler.plugin.CommandLineProcessor b/libraries/examples/kotlin-gradle-subplugin-example/src/main/resources/META-INF/services/org.jetbrains.kotlin.compiler.plugin.CommandLineProcessor
new file mode 100644
index 00000000000..9e679ab36f5
--- /dev/null
+++ b/libraries/examples/kotlin-gradle-subplugin-example/src/main/resources/META-INF/services/org.jetbrains.kotlin.compiler.plugin.CommandLineProcessor
@@ -0,0 +1 @@
+example.ExampleCommandLineProcessor
\ No newline at end of file
diff --git a/libraries/examples/kotlin-gradle-subplugin-example/src/main/resources/META-INF/services/org.jetbrains.kotlin.compiler.plugin.ComponentRegistrar b/libraries/examples/kotlin-gradle-subplugin-example/src/main/resources/META-INF/services/org.jetbrains.kotlin.compiler.plugin.ComponentRegistrar
new file mode 100644
index 00000000000..f6c0447785d
--- /dev/null
+++ b/libraries/examples/kotlin-gradle-subplugin-example/src/main/resources/META-INF/services/org.jetbrains.kotlin.compiler.plugin.ComponentRegistrar
@@ -0,0 +1 @@
+example.ExampleComponentRegistrar
\ No newline at end of file
diff --git a/libraries/examples/kotlin-gradle-subplugin-example/src/main/resources/META-INF/services/org.jetbrains.kotlin.gradle.plugin.KotlinGradleSubplugin b/libraries/examples/kotlin-gradle-subplugin-example/src/main/resources/META-INF/services/org.jetbrains.kotlin.gradle.plugin.KotlinGradleSubplugin
new file mode 100644
index 00000000000..68d0867ca30
--- /dev/null
+++ b/libraries/examples/kotlin-gradle-subplugin-example/src/main/resources/META-INF/services/org.jetbrains.kotlin.gradle.plugin.KotlinGradleSubplugin
@@ -0,0 +1 @@
+example.ExampleSubplugin
\ No newline at end of file
diff --git a/libraries/pom.xml b/libraries/pom.xml
index 3325e2c8a15..0ccfdd0801b 100644
--- a/libraries/pom.xml
+++ b/libraries/pom.xml
@@ -111,6 +111,7 @@
examples/kotlin-js-library-example
examples/browser-example
examples/browser-example-with-library
+ examples/kotlin-gradle-subplugin-example
diff --git a/libraries/tools/kotlin-gradle-plugin/pom.xml b/libraries/tools/kotlin-gradle-plugin/pom.xml
index 836f7855f00..797b85b5222 100644
--- a/libraries/tools/kotlin-gradle-plugin/pom.xml
+++ b/libraries/tools/kotlin-gradle-plugin/pom.xml
@@ -54,6 +54,12 @@
kotlin-gradle-plugin-api
${project.version}
+
+ org.jetbrains.kotlin
+ kotlin-gradle-subplugin-example
+ ${project.version}
+ test
+
diff --git a/libraries/tools/kotlin-gradle-plugin/src/test/kotlin/org/jetbrains/kotlin/gradle/BasicKotlinGradlePluginIT.kt b/libraries/tools/kotlin-gradle-plugin/src/test/kotlin/org/jetbrains/kotlin/gradle/BasicKotlinGradlePluginIT.kt
index 42d92fd10c5..55a7aeaf93b 100644
--- a/libraries/tools/kotlin-gradle-plugin/src/test/kotlin/org/jetbrains/kotlin/gradle/BasicKotlinGradlePluginIT.kt
+++ b/libraries/tools/kotlin-gradle-plugin/src/test/kotlin/org/jetbrains/kotlin/gradle/BasicKotlinGradlePluginIT.kt
@@ -79,4 +79,23 @@ class SimpleKotlinGradleIT : BaseGradleIT() {
assertSuccessful()
}
}
+
+ Test fun testGradleSubplugin() {
+ val project = Project("kotlinGradleSubplugin", "1.6")
+
+ project.build("compileKotlin", "build") {
+ assertSuccessful()
+ assertContains("/src/main/kotlin/helloWorld.kt")
+ assertContains("ExampleSubplugin loaded")
+ assertContains("Project component registration: exampleValue")
+ assertContains(":compileKotlin")
+ }
+
+ project.build("compileKotlin", "build") {
+ assertSuccessful()
+ assertContains("ExampleSubplugin loaded")
+ assertNotContains("Project component registration: exampleValue")
+ assertContains(":compileKotlin UP-TO-DATE")
+ }
+ }
}
\ No newline at end of file
diff --git a/libraries/tools/kotlin-gradle-plugin/src/test/resources/testProject/kotlinGradleSubplugin/build.gradle b/libraries/tools/kotlin-gradle-plugin/src/test/resources/testProject/kotlinGradleSubplugin/build.gradle
new file mode 100644
index 00000000000..528972d1c7e
--- /dev/null
+++ b/libraries/tools/kotlin-gradle-plugin/src/test/resources/testProject/kotlinGradleSubplugin/build.gradle
@@ -0,0 +1,39 @@
+buildscript {
+ repositories {
+ mavenCentral()
+ maven {
+ url 'file://' + pathToKotlinPlugin
+ }
+ }
+ dependencies {
+ classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:0.1-SNAPSHOT"
+ classpath "org.jetbrains.kotlin:kotlin-gradle-subplugin-example:0.1-SNAPSHOT"
+ }
+}
+
+apply plugin: "kotlin"
+
+repositories {
+ maven {
+ url 'file://' + pathToKotlinPlugin
+ }
+ mavenCentral()
+}
+
+dependencies {
+ compile "org.jetbrains.kotlin:kotlin-stdlib:0.1-SNAPSHOT"
+}
+
+task show << {
+ buildscript.configurations.classpath.each { println it }
+}
+
+
+compileKotlin {
+ kotlinOptions.annotations = "externalAnnotations"
+}
+
+
+task wrapper(type: Wrapper) {
+ gradleVersion="1.4"
+}
\ No newline at end of file
diff --git a/libraries/tools/kotlin-gradle-plugin/src/test/resources/testProject/kotlinGradleSubplugin/src/main/kotlin/helloWorld.kt b/libraries/tools/kotlin-gradle-plugin/src/test/resources/testProject/kotlinGradleSubplugin/src/main/kotlin/helloWorld.kt
new file mode 100644
index 00000000000..1dc7c8d5163
--- /dev/null
+++ b/libraries/tools/kotlin-gradle-plugin/src/test/resources/testProject/kotlinGradleSubplugin/src/main/kotlin/helloWorld.kt
@@ -0,0 +1,9 @@
+package demo
+
+class HelloWorld {
+
+ fun hello() {
+ println("Hello, world!")
+ }
+
+}
\ No newline at end of file