https://kotlinlang.org logo
Title
s

SrSouza

05/08/2018, 4:37 PM
hey guys, i have a question, how i can apply all plugins from root project on
allprojects
or
subprojects
block?
s

SrSouza

05/08/2018, 8:45 PM
the easy way i find is this
plugins {
    kotlin("jvm") version "1.2.41"
    id("maven-publish")
    id("com.github.johnrengelman.shadow") version "2.0.3"
}

val groupPrefix by extra { "br.com.devsrsouza.SERVIDOR" }

subprojects {
    plugins.apply("org.jetbrains.kotlin.jvm")
    plugins.apply("maven-publish")
    plugins.apply("com.github.johnrengelman.shadow")
}
but would be good the have someway to list all Plugins from root project and apply on subprojects
b

BorzdeG

05/09/2018, 4:40 AM
If you do not use BuildScanPlugin in the root project, you can remove the check
subprojects.onEach { subProject ->
  rootProject.plugins.onEach { rootPlugin ->
    if (rootPlugin !is BuildScanPlugin){
      subProject.plugins.apply(rootPlugin.javaClass)
    }
  }
}
but in general - from my example on the link to GitHub, you just need to replace the
subprojects
with
allprojects
.
The main idea is not to use the DSL-block
plugins
, but use the DSL-block
apply
. In my example, I use classes as Generic types for
plugins
- I like “static typing” in DSL. But you can remove the Generic-type and in parentheses write the names of plug-ins by strings