mgrzechocinski
10/09/2018, 2:41 PMapply from:
directive.
Simplifying, when my build.gradle.kts
file looks like this:
plugins {
id("kotlin-android-extensions")
}
androidExtensions {
isExperimental = true
}
it’s works fine. However, when I try to extract plugin definition to a separated file and apply it from my `build.gradle.kts`:
apply{
from("$rootDir/kotlin_shared.gradle.kts") //contains plugins { id("kotlin-android-extensions") }
}
androidExtensions {
isExperimental = true
}
it fails on "Unresolved reference: androidExtensions"
. In Groovy version I had apply from:
directive on top of my build.gradle
file and it worked pretty well. Seems like kotlin’s apply { from () }
doesn’t work like Gradle’s apply from:
version, or am I missing sth?ribesg
10/09/2018, 2:57 PMplugins
block, and you should use it for it to work bettermkobit
10/09/2018, 3:03 PMandroidExtensions
in this case) are only generated when they are applied in the plugins {}
block
gradle does like a 2 phase compilation, and since the apply(from = "...")
is executed and not handled in the same way, gradle doesnt know about it
so you either use plugins {}
block to get accessors or need to know the type and do something like configure<org.android.AndroidExtension> {}
you can use the ./gradlew kotlinDslAccessorsReport
to see what is generated by the kotlin-dal
mgrzechocinski
10/09/2018, 3:10 PMmgrzechocinski
10/09/2018, 3:11 PM.kts
file which I can include in my Android Gradle modulesmgrzechocinski
10/09/2018, 3:11 PMScript compilation errors:
Line 7: androidExtensions {
^ Unresolved reference: androidExtensions
Line 8: isExperimental = true
^ Unresolved reference: isExperimental
2 errors
mkobit
10/09/2018, 3:12 PMmkobit
10/09/2018, 3:13 PMapply(from = "...")
there is ... something (cant find it ATM) for how you can do it using buildSrc
mkobit
10/09/2018, 3:13 PMmgrzechocinski
10/09/2018, 3:18 PMmkobit
10/09/2018, 3:37 PMbuildSrc
for example, https://github.com/gradle/kotlin-dsl/blob/master/buildSrc/build.gradle.kts#L21
and using https://github.com/gradle/kotlin-dsl/tree/master/buildSrc/src/main/kotlin/plugins
then the plugin ids can be consumed from the main build in a multi-project buildmgrzechocinski
10/09/2018, 3:47 PMbuildSrc
for my dependencies catalog which I refer to from different modulesmgrzechocinski
10/09/2018, 3:50 PMmgrzechocinski
10/09/2018, 3:51 PMgildor
10/09/2018, 4:51 PMgildor
10/09/2018, 4:52 PMgildor
10/09/2018, 4:56 PMplugins.withId("kotlin-android-extensions") { /* your config */ }
functiongildor
10/09/2018, 5:00 PMconfigure<YourPluginExtension>
function insteadgildor
10/09/2018, 5:05 PMallprojects {
plugins.withId("kotlin-android-extensions") {
configure<AndroidExtensionsExtension> {
isExperimental = true
}
}
}
mgrzechocinski
10/09/2018, 5:59 PMJavier
07/23/2019, 12:34 PMgildor
07/23/2019, 12:35 PMJavier
07/23/2019, 12:35 PMJavier
07/23/2019, 12:35 PMJavier
07/23/2019, 12:35 PMJavier
07/23/2019, 12:36 PMgildor
07/23/2019, 12:37 PMgildor
07/23/2019, 12:37 PMJavier
07/23/2019, 12:38 PMgildor
07/23/2019, 12:38 PMJavier
07/23/2019, 12:38 PMgildor
07/23/2019, 12:38 PM"implementation"(Dependencies.kotlin)
gildor
07/23/2019, 12:39 PMJavier
07/23/2019, 12:40 PMConfiguration with name 'implementation' not found.
gildor
07/23/2019, 12:41 PMJavier
07/23/2019, 12:42 PMgildor
07/23/2019, 12:43 PMimplementation
is a configuration that provided by java plugin (also implicitly used by java), check that this project where you apply this dependency have itgildor
07/23/2019, 12:44 PMJavier
07/23/2019, 12:46 PMJavier
07/23/2019, 12:46 PMJavier
07/23/2019, 12:47 PMgildor
07/23/2019, 12:48 PMJavier
07/23/2019, 12:50 PMJavier
07/23/2019, 12:50 PMJavier
07/23/2019, 12:51 PMgildor
07/23/2019, 12:52 PMJavier
07/23/2019, 12:58 PMJavier
07/23/2019, 1:10 PMScript compilation errors:
Line 09: android {
^ Unresolved reference: android
Javier
07/23/2019, 1:11 PMgildor
07/23/2019, 1:17 PMgildor
07/23/2019, 1:20 PMJavier
07/23/2019, 1:21 PMgildor
07/23/2019, 1:22 PMgildor
07/23/2019, 1:22 PMJavier
07/23/2019, 1:23 PMJavier
07/23/2019, 1:23 PMJavier
07/23/2019, 1:24 PM