nuhkoca
06/22/2019, 5:11 PMGroovy
we had a chance to create common.gradle
script in order to avoid boilerplate and use it within other mutual gradle files. However, I am unable to do have the same behaviour with DSL. Anyone know how to do that?louiscad
06/22/2019, 5:13 PMbuildscript
classpath
dependencies to buildSrc as implementation
.nuhkoca
06/22/2019, 5:15 PMapply from : "$rootDir/common.gradle.kts"
This seems not to work in Kotlin DSLlouiscad
06/22/2019, 5:17 PMnuhkoca
06/22/2019, 5:22 PMlouiscad
06/22/2019, 7:05 PMsomething.gradle.kts
file like you would write a build.gradle.kts
file produces an implicit plugin named something
that you can apply using the plugins
DSL, or the apply
function. You can try and tell if it worksnuhkoca
06/22/2019, 7:11 PM.kts
file inside src/main/kotlin
and added it to my child .kts
However, I am getting below error;
The 'java' plugin has been applied, but it is not compatible with the Android plugins.
Actually I know the reason but I don’t understand why things don’t work like in Groovy.
This is my plugin - common-library.gradle.kts
plugins {
`java-library`
}
val javaVersion: JavaVersion by extra { JavaVersion.VERSION_1_8 }
java {
sourceCompatibility = javaVersion
targetCompatibility = javaVersion
}
dependencies {}
And this is the child
plugins {
`common-library`
id(Plugins.androidApplication)
kotlin(Plugins.kotlinAndroid)
kotlin(Plugins.kotlinAndroidExtension)
kotlin(Plugins.kotlinKapt)
}
louiscad
06/22/2019, 8:46 PMjava-library
applies the java
plugin, that's why. You need to stop applying common-library
for android modulesnuhkoca
06/23/2019, 12:09 AMgildor
06/23/2019, 4:05 PMefemoney
06/27/2019, 3:00 AMdependencies { ... }
in buildSrc/build.gradle(.kts)
. Then the classes are available in your buildscript classpath and you can use them in any build.gradle(.kts)
. Its still going to be dynamic however so not entirely convenientgildor
06/27/2019, 3:03 AMIts still going to be dynamic however so not entirely convenientprecompiled script plugins solve this problem