Skip to content

Commit

Permalink
Fix exposing provided by Gradle Kotlin dependencies.
Browse files Browse the repository at this point in the history
Ensure that Gradle plugin dependencies do not include kotlin-stdlib,
kotlin-reflect and other dependencies that are provided by Gradle
runtime.

^KT-41142 Fixed
  • Loading branch information
Tapchicoma authored and Space committed May 19, 2021
1 parent f0f2b92 commit 0505d58
Show file tree
Hide file tree
Showing 32 changed files with 496 additions and 282 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

plugins {
kotlin("jvm")
}

publish()
standardPublicJars()

extensions.extraProperties["kotlin.stdlib.default.dependency"] = "false"

dependencies {
compileOnly(kotlinStdlib())
compileOnly(gradleApi())
}

// These dependencies will be provided by Gradle and we should prevent version conflict
fun Configuration.excludeGradleCommonDependencies() {
exclude(group = "org.jetbrains.kotlin", module = "kotlin-stdlib")
exclude(group = "org.jetbrains.kotlin", module = "kotlin-stdlib-jdk7")
exclude(group = "org.jetbrains.kotlin", module = "kotlin-stdlib-jdk8")
exclude(group = "org.jetbrains.kotlin", module = "kotlin-stdlib-common")
exclude(group = "org.jetbrains.kotlin", module = "kotlin-reflect")
exclude(group = "org.jetbrains.kotlin", module = "kotlin-script-runtime")
}
configurations {
"implementation" {
excludeGradleCommonDependencies()
}
"api" {
excludeGradleCommonDependencies()
}
}

tasks.withType<KotlinCompile> {
kotlinOptions.languageVersion = "1.3"
kotlinOptions.apiVersion = "1.3"
kotlinOptions.freeCompilerArgs += listOf(
"-Xskip-prerelease-check"
)
}

tasks.named<Jar>("jar") {
callGroovy("manifestAttributes", manifest, project)
}
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ class CodeConformanceTest : TestCase() {
File("."),
listOf(
"build",
"buildSrc/build/generated-sources",
"buildSrc/prepare-deps/build",
"compiler/ir/serialization.js/build/fullRuntime",
"compiler/ir/serialization.js/build/reducedRuntime/src/libraries/stdlib/js-ir/runtime/longjs.kt",
Expand All @@ -93,6 +94,7 @@ class CodeConformanceTest : TestCase() {
"libraries/stdlib/js-v1/node_modules",
"libraries/stdlib/wasm/build",
"libraries/tools/kotlin-gradle-plugin-integration-tests/build",
"libraries/tools/kotlin-gradle-plugin-integration-tests/.testKitDir",
"libraries/tools/kotlin-maven-plugin-test/target",
"libraries/tools/kotlin-test-js-runner/.gradle",
"libraries/tools/kotlin-test-js-runner/lib",
Expand Down
2 changes: 1 addition & 1 deletion compiler/util-io/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ plugins {
description = "Kotlin/Native utils"

dependencies {
compile(kotlinStdlib())
implementation(kotlinStdlib())
testImplementation(commonDep("junit:junit"))
}

Expand Down
9 changes: 1 addition & 8 deletions libraries/tools/kotlin-gradle-build-metrics/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
description = "kotlin-gradle-statistics"

plugins {
kotlin("jvm")
id("gradle-plugin-common-configuration")
id("jps-compatible")
}

dependencies {
compileOnly(kotlinStdlib())

testImplementation(project(":kotlin-test:kotlin-test-junit"))
testImplementation("junit:junit:4.12")
}
Expand All @@ -20,8 +18,3 @@ sourceSets {
projectTest {
workingDir = rootDir
}

publish()

sourcesJar()
javadocJar()
22 changes: 1 addition & 21 deletions libraries/tools/kotlin-gradle-plugin-api/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,34 +1,14 @@
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
import org.jetbrains.kotlin.pill.PillExtension

plugins {
kotlin("jvm")
id("gradle-plugin-common-configuration")
id("jps-compatible")
}

publish()

standardPublicJars()

dependencies {
compile(kotlinStdlib())

compileOnly(gradleApi())
compileOnly("com.android.tools.build:gradle:3.4.0")
}

pill {
variant = PillExtension.Variant.FULL
}

tasks {
withType<KotlinCompile> {
kotlinOptions.languageVersion = "1.3"
kotlinOptions.apiVersion = "1.3"
kotlinOptions.freeCompilerArgs += listOf("-Xskip-prerelease-check")
}

named<Jar>("jar") {
callGroovy("manifestAttributes", manifest, project)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -151,4 +151,31 @@ class SimpleKotlinGradleIT : BaseGradleIT() {
assertSuccessful()
}
}

// Should not produce kotlin-stdlib version conflict on Kotlin files compilation in 'buildSrc' module"
@Test
internal fun testKotlinDslStdlibVersionConflict() {
val project = Project(projectName = "buildSrcUsingKotlinCompilationAndKotlinPlugin")
listOf(
"compileClasspath",
"compileOnly",
"runtimeClasspath"
).forEach { configuration ->
project.build("-p", "buildSrc", "dependencies", "--configuration", configuration) {
assertSuccessful()
listOf(
"org.jetbrains.kotlin:kotlin-stdlib:${defaultBuildOptions().kotlinVersion}",
"org.jetbrains.kotlin:kotlin-stdlib-jdk7:${defaultBuildOptions().kotlinVersion}",
"org.jetbrains.kotlin:kotlin-stdlib-jdk8:${defaultBuildOptions().kotlinVersion}",
"org.jetbrains.kotlin:kotlin-stdlib-common:${defaultBuildOptions().kotlinVersion}",
"org.jetbrains.kotlin:kotlin-reflect:${defaultBuildOptions().kotlinVersion}",
"org.jetbrains.kotlin:kotlin-script-runtime:${defaultBuildOptions().kotlinVersion}"
).forEach {
assertNotContains(it)
}
}
}

project.build("assemble") { assertSuccessful() }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
plugins {
kotlin("jvm")
}

repositories {
mavenLocal()
mavenCentral()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
plugins {
`kotlin-dsl`
}

repositories {
mavenLocal()
mavenCentral()
}

dependencies {
implementation("org.jetbrains.kotlin:kotlin-gradle-plugin:${property("kotlin_version")}")
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import org.gradle.api.Project

fun Project.nameLength() = name.length
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/*
* Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/

fun main() {
println("Hello World!")
}
23 changes: 1 addition & 22 deletions libraries/tools/kotlin-gradle-plugin-model/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,31 +1,10 @@
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
import org.jetbrains.kotlin.pill.PillExtension

plugins {
kotlin("jvm")
id("gradle-plugin-common-configuration")
id("jps-compatible")
}

publish()

standardPublicJars()

dependencies {
compile(kotlinStdlib())
}

pill {
variant = PillExtension.Variant.FULL
}

tasks {
withType<KotlinCompile> {
kotlinOptions.languageVersion = "1.3"
kotlinOptions.apiVersion = "1.3"
kotlinOptions.freeCompilerArgs += listOf("-Xskip-prerelease-check")
}

named<Jar>("jar") {
callGroovy("manifestAttributes", manifest, project)
}
}
25 changes: 2 additions & 23 deletions libraries/tools/kotlin-gradle-plugin/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import org.jetbrains.dokka.gradle.DokkaTask
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
import org.jetbrains.kotlin.pill.PillExtension

plugins {
java
kotlin("jvm")
`java-gradle-plugin`
id("gradle-plugin-common-configuration")
id("org.jetbrains.dokka")
id("jps-compatible")
}
Expand All @@ -17,13 +16,8 @@ configure<GradlePluginDevelopmentExtension> {
isAutomatedPublishing = false
}

publish()

val jarContents by configurations.creating

sourcesJar()
javadocJar()

repositories {
google()
maven("https://plugins.gradle.org/m2/")
Expand All @@ -40,7 +34,6 @@ dependencies {
compileOnly(project(":compiler:incremental-compilation-impl"))
compileOnly(project(":daemon-common"))

implementation(kotlinStdlib())
implementation(project(":kotlin-util-klib"))
compileOnly(project(":native:kotlin-native-utils"))
compileOnly(project(":kotlin-reflect-api"))
Expand All @@ -66,8 +59,7 @@ dependencies {
compileOnly("com.android.tools.build:builder:3.4.0")
compileOnly("com.android.tools.build:builder-model:3.4.0")
compileOnly("org.codehaus.groovy:groovy-all:2.4.12")
compileOnly(gradleApi())

compileOnly(project(":kotlin-reflect"))
compileOnly(intellijCoreDep()) { includeJars("intellij-core") }

runtimeOnly(projectRuntimeJar(":kotlin-compiler-embeddable"))
Expand All @@ -76,7 +68,6 @@ dependencies {
runtimeOnly(projectRuntimeJar(":kotlin-compiler-runner"))
runtimeOnly(projectRuntimeJar(":kotlin-scripting-compiler-embeddable"))
runtimeOnly(projectRuntimeJar(":kotlin-scripting-compiler-impl-embeddable"))
runtimeOnly(project(":kotlin-reflect"))

jarContents(compileOnly(intellijDep()) {
includeJars("asm-all", "gson", "serviceMessages", rootProject = rootProject)
Expand All @@ -96,7 +87,6 @@ dependencies {
testImplementation(projectTests(":kotlin-build-common"))
testImplementation(project(":kotlin-android-extensions"))
testImplementation(project(":kotlin-compiler-runner"))
testImplementation(project(":kotlin-test::kotlin-test-junit"))
testImplementation("junit:junit:4.12")
testImplementation(project(":kotlin-gradle-statistics"))
testCompileOnly(project(":kotlin-reflect-api"))
Expand All @@ -120,13 +110,6 @@ runtimeJar(rewriteDefaultJarDepsToShadedCompiler()).configure {
}

tasks {
withType<KotlinCompile> {
kotlinOptions.jdkHome = rootProject.extra["JDK_18"] as String
kotlinOptions.languageVersion = "1.3"
kotlinOptions.apiVersion = "1.3"
kotlinOptions.freeCompilerArgs += listOf("-Xskip-prerelease-check")
}

named<ProcessResources>("processResources") {
val propertiesToExpand = mapOf(
"projectVersion" to project.version,
Expand All @@ -140,10 +123,6 @@ tasks {
}
}

named<Jar>("jar") {
callGroovy("manifestAttributes", manifest, project)
}

withType<ValidatePlugins>().configureEach {
failOnWarning.set(true)
enableStricterValidation.set(true)
Expand Down
Loading

0 comments on commit 0505d58

Please sign in to comment.