eekboom
12/10/2019, 12:31 PMThiago Nerys
12/10/2019, 12:32 PMimplementation
instead of compile
eekboom
12/10/2019, 12:32 PMThiago Nerys
12/10/2019, 12:42 PMeekboom
12/10/2019, 12:43 PMval compile by configurations
Thiago Nerys
12/10/2019, 12:45 PMimport org.jetbrains.kotlin.gradle.tasks.KotlinCompile
plugins {
kotlin("jvm") version Versions.kotlin
id("org.springframework.boot") version Versions.spring
id("org.jetbrains.kotlin.plugin.spring") version Versions.kotlin
id("io.spring.dependency-management") version Versions.springDependencyManagement
}
allprojects {
repositories {
mavenCentral()
}
tasks {
withType(KotlinCompile::class).all {
kotlinOptions {
jvmTarget = "11"
freeCompilerArgs = listOf("-Xjsr305=strict")
}
}
}
}
subprojects {
plugins.withType<JavaPlugin> {
dependencies {
compile("org.slf4j:sllf4j-api")
implementation("org.slf4j:sllf4j-api")
}
}
}
dependencies {
implementation(project(":integration"))
runtime(project(":implementation"))
implementation(kotlin("stdlib-jdk8", version = Versions.kotlin))
implementation(kotlin("reflect", version = Versions.kotlin))
implementation("org.springframework.boot:spring-boot-starter-web") {
/* Excluding Tomcat dependency */
exclude(module = "spring-boot-starter-tomcat")
}
implementation("org.springframework.boot:spring-boot-starter-undertow")
}
eekboom
12/10/2019, 12:49 PMplugins { id("java") …
it also works for me.Thiago Nerys
12/10/2019, 12:51 PMeekboom
12/10/2019, 12:52 PMError resolving plugin [id: ‘java’, apply: false]
> Plugin ‘java’ is a core Gradle plugin, which is already on the classpath. Requesting it with the ‘apply false’ option is a no-op.
eskatos
12/10/2019, 1:44 PMcompile
then there’s no static accessor in its build script. This is expected, see <https://docs.gradle.org/current/userguide/kotlin_dsl.html#type-safe-accessors>
In that case you should use string references instead:
subprojects {
plugins.withType<JavaPlugin> {
dependencies {
"compile"("org.slf4j:sllf4j-api")
"implementation"("org.slf4j:sllf4j-api")
}
}
}
Note the double quotes.eekboom
12/10/2019, 1:58 PMeskatos
12/10/2019, 2:03 PMplugins {}
block. That’s why withType<JavaPlugin> {}
or configure<JavaPluginConvention> {}
won’t help.
Those accessors are Kotlin extension functions, in that case on the DependencyHandler
type. They are static. That’s why they are usable on the DependencyHandler
of sub projects in a subprojects {}
block.
Tradeoffs 🤷♂️eekboom
12/10/2019, 2:15 PMeekboom
12/10/2019, 2:24 PMeskatos
12/10/2019, 2:28 PMeekboom
12/10/2019, 2:28 PMeskatos
12/10/2019, 2:29 PMdependencies {
compile("foo:foo:1.0.")
}
subprojects {
dependencies {
compile("foo:foo:1.0.")
}
}
it’s the same Kotlin function fun DependencyHandler.compile(dep: String)
(simplified version)
but applied to different DependencyHandler
instances. In the first case to the root project, in the second case to each subprojects.