Fix applying subplugin from script
#KT-24497 fixed
This commit is contained in:
+9
@@ -131,4 +131,13 @@ class SubpluginsIT : BaseGradleIT() {
|
||||
assertFileExists("${kotlinClassesDir(subproject = "a/b", sourceSet = "test")}MyTestClass.class")
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testAllopenFromScript() {
|
||||
Project("allOpenFromScript").build("build") {
|
||||
assertSuccessful()
|
||||
assertFileExists("${kotlinClassesDir(sourceSet = "main")}MyClass.class")
|
||||
assertFileExists("${kotlinClassesDir(sourceSet = "test")}MyTestClass.class")
|
||||
}
|
||||
}
|
||||
}
|
||||
+1
@@ -0,0 +1 @@
|
||||
apply from: './kotlin.gradle'
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
buildscript {
|
||||
repositories {
|
||||
mavenLocal()
|
||||
mavenCentral()
|
||||
}
|
||||
dependencies {
|
||||
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
|
||||
classpath "org.jetbrains.kotlin:kotlin-allopen:$kotlin_version"
|
||||
}
|
||||
}
|
||||
|
||||
apply plugin: org.jetbrains.kotlin.gradle.plugin.KotlinPluginWrapper
|
||||
apply plugin: org.jetbrains.kotlin.allopen.gradle.AllOpenGradleSubplugin
|
||||
|
||||
repositories {
|
||||
mavenLocal()
|
||||
mavenCentral()
|
||||
}
|
||||
|
||||
allOpen {
|
||||
annotation("AllOpen")
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
|
||||
}
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
/*
|
||||
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
@AllOpen
|
||||
class MyClass {
|
||||
fun f() = 0
|
||||
}
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
/*
|
||||
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
annotation class AllOpen
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
/*
|
||||
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
class MyTestClass : MyClass() {
|
||||
override fun f() = 1
|
||||
}
|
||||
+15
-1
@@ -666,7 +666,21 @@ private fun SourceSet.clearJavaSrcDirs() {
|
||||
|
||||
private fun loadSubplugins(project: Project, kotlinPluginVersion: String): SubpluginEnvironment =
|
||||
try {
|
||||
val subplugins = ServiceLoader.load(KotlinGradleSubplugin::class.java, project.buildscript.classLoader)
|
||||
val klass = KotlinGradleSubplugin::class.java
|
||||
val buildscriptClassloader = project.buildscript.classLoader
|
||||
val klassFromBuildscript = try {
|
||||
buildscriptClassloader.loadClass(klass.canonicalName)
|
||||
} catch (e: ClassNotFoundException) {
|
||||
null
|
||||
}
|
||||
|
||||
val classloader = if (klass == klassFromBuildscript) {
|
||||
buildscriptClassloader
|
||||
} else {
|
||||
klass.classLoader
|
||||
}
|
||||
|
||||
val subplugins = ServiceLoader.load(KotlinGradleSubplugin::class.java, classloader)
|
||||
.map { @Suppress("UNCHECKED_CAST") (it as KotlinGradleSubplugin<AbstractCompile>) }
|
||||
|
||||
SubpluginEnvironment(subplugins, kotlinPluginVersion)
|
||||
|
||||
Reference in New Issue
Block a user