Add a function attributes { } to KotlinTarget and KotlinCompilation
Gradle has a function `attributes { ... }` for `Configuration`, so we
can introduce one, too, for uniformity of the DSLs. This will configure
the `val attributes: AttributeContainer` of the `KotlinTarget` and
`KotlinCompilation`.
Issue #KT-27682 Fixed
This commit is contained in:
+4
@@ -7,6 +7,7 @@ package org.jetbrains.kotlin.gradle.plugin
|
|||||||
|
|
||||||
import groovy.lang.Closure
|
import groovy.lang.Closure
|
||||||
import org.gradle.api.Named
|
import org.gradle.api.Named
|
||||||
|
import org.gradle.api.attributes.AttributeContainer
|
||||||
import org.gradle.api.attributes.HasAttributes
|
import org.gradle.api.attributes.HasAttributes
|
||||||
import org.gradle.api.file.ConfigurableFileCollection
|
import org.gradle.api.file.ConfigurableFileCollection
|
||||||
import org.gradle.api.file.FileCollection
|
import org.gradle.api.file.FileCollection
|
||||||
@@ -52,6 +53,9 @@ interface KotlinCompilation<out T : KotlinCommonOptions> : Named, HasAttributes,
|
|||||||
fun kotlinOptions(configure: T.() -> Unit)
|
fun kotlinOptions(configure: T.() -> Unit)
|
||||||
fun kotlinOptions(configure: Closure<*>) = kotlinOptions { ConfigureUtil.configure(configure, this) }
|
fun kotlinOptions(configure: Closure<*>) = kotlinOptions { ConfigureUtil.configure(configure, this) }
|
||||||
|
|
||||||
|
fun attributes(configure: AttributeContainer.() -> Unit) = configure(attributes)
|
||||||
|
fun attributes(configure: Closure<*>) = attributes { ConfigureUtil.configure(configure, this) }
|
||||||
|
|
||||||
val compileAllTaskName: String
|
val compileAllTaskName: String
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
|||||||
+4
@@ -10,6 +10,7 @@ import org.gradle.api.Action
|
|||||||
import org.gradle.api.Named
|
import org.gradle.api.Named
|
||||||
import org.gradle.api.NamedDomainObjectContainer
|
import org.gradle.api.NamedDomainObjectContainer
|
||||||
import org.gradle.api.Project
|
import org.gradle.api.Project
|
||||||
|
import org.gradle.api.attributes.AttributeContainer
|
||||||
import org.gradle.api.attributes.HasAttributes
|
import org.gradle.api.attributes.HasAttributes
|
||||||
import org.gradle.api.component.SoftwareComponent
|
import org.gradle.api.component.SoftwareComponent
|
||||||
import org.gradle.api.internal.component.UsageContext
|
import org.gradle.api.internal.component.UsageContext
|
||||||
@@ -47,6 +48,9 @@ interface KotlinTarget : Named, HasAttributes {
|
|||||||
fun mavenPublication(action: Closure<Unit>)
|
fun mavenPublication(action: Closure<Unit>)
|
||||||
fun mavenPublication(action: Action<MavenPublication>)
|
fun mavenPublication(action: Action<MavenPublication>)
|
||||||
|
|
||||||
|
fun attributes(configure: AttributeContainer.() -> Unit) = configure(attributes)
|
||||||
|
fun attributes(configure: Closure<*>) = attributes { ConfigureUtil.configure(configure, this) }
|
||||||
|
|
||||||
val preset: KotlinTargetPreset<out KotlinTarget>?
|
val preset: KotlinTargetPreset<out KotlinTarget>?
|
||||||
|
|
||||||
override fun getName(): String = targetName
|
override fun getName(): String = targetName
|
||||||
|
|||||||
+17
@@ -1202,6 +1202,23 @@ class NewMultiplatformIT : BaseGradleIT() {
|
|||||||
testDependencies()
|
testDependencies()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun testMultipleTargetsSamePlatform() = with(Project("newMppMultipleTargetsSamePlatform", gradleVersion)) {
|
||||||
|
testResolveAllConfigurations("app") {
|
||||||
|
assertContains(">> :app:junitCompileClasspath --> lib-junit.jar")
|
||||||
|
assertContains(">> :app:junitCompileClasspath --> junit-4.12.jar")
|
||||||
|
|
||||||
|
assertContains(">> :app:mixedJunitCompileClasspath --> lib-junit.jar")
|
||||||
|
assertContains(">> :app:mixedJunitCompileClasspath --> junit-4.12.jar")
|
||||||
|
|
||||||
|
assertContains(">> :app:testngCompileClasspath --> lib-testng.jar")
|
||||||
|
assertContains(">> :app:testngCompileClasspath --> testng-6.14.3.jar")
|
||||||
|
|
||||||
|
assertContains(">> :app:mixedTestngCompileClasspath --> lib-testng.jar")
|
||||||
|
assertContains(">> :app:mixedTestngCompileClasspath --> testng-6.14.3.jar")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun testUnusedSourceSetsReport() = with(Project("sample-lib", gradleVersion, "new-mpp-lib-and-app")) {
|
fun testUnusedSourceSetsReport() = with(Project("sample-lib", gradleVersion, "new-mpp-lib-and-app")) {
|
||||||
setupWorkingDir()
|
setupWorkingDir()
|
||||||
|
|||||||
+26
@@ -0,0 +1,26 @@
|
|||||||
|
plugins {
|
||||||
|
id("org.jetbrains.kotlin.multiplatform")
|
||||||
|
}
|
||||||
|
|
||||||
|
val testFrameworkAttribute = Attribute.of("com.example.testFramework", String::class.java)
|
||||||
|
|
||||||
|
kotlin {
|
||||||
|
configure(listOf(jvm("junit"), jvm("testng"))) {
|
||||||
|
attributes {
|
||||||
|
attribute(testFrameworkAttribute, targetName)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
jvm("mixed") {
|
||||||
|
configure(listOf(compilations.create("junit"), compilations.create("testng"))) {
|
||||||
|
defaultSourceSet.dependsOn(sourceSets["commonMain"])
|
||||||
|
attributes {
|
||||||
|
attribute(testFrameworkAttribute, compilationName)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
sourceSets["commonMain"].dependencies {
|
||||||
|
implementation(project(":lib"))
|
||||||
|
}
|
||||||
|
}
|
||||||
+16
@@ -0,0 +1,16 @@
|
|||||||
|
buildscript {
|
||||||
|
repositories {
|
||||||
|
mavenLocal()
|
||||||
|
jcenter()
|
||||||
|
}
|
||||||
|
dependencies {
|
||||||
|
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
allprojects {
|
||||||
|
repositories {
|
||||||
|
mavenLocal()
|
||||||
|
jcenter()
|
||||||
|
}
|
||||||
|
}
|
||||||
+21
@@ -0,0 +1,21 @@
|
|||||||
|
plugins {
|
||||||
|
id("org.jetbrains.kotlin.multiplatform")
|
||||||
|
}
|
||||||
|
|
||||||
|
val testFrameworkAttribute = Attribute.of("com.example.testFramework", String::class.java)
|
||||||
|
|
||||||
|
kotlin {
|
||||||
|
configure(listOf(jvm("junit"), jvm("testng"))) {
|
||||||
|
attributes {
|
||||||
|
attribute(testFrameworkAttribute, targetName)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
jvm("junit").compilations["main"].defaultSourceSet.dependencies {
|
||||||
|
api("junit:junit:4.12")
|
||||||
|
}
|
||||||
|
|
||||||
|
jvm("testng").compilations["main"].defaultSourceSet.dependencies {
|
||||||
|
api("org.testng:testng:6.14.3")
|
||||||
|
}
|
||||||
|
}
|
||||||
+3
@@ -0,0 +1,3 @@
|
|||||||
|
package com.example
|
||||||
|
|
||||||
|
expect annotation class Test()
|
||||||
+3
@@ -0,0 +1,3 @@
|
|||||||
|
package com.example
|
||||||
|
|
||||||
|
actual typealias Test = org.junit.Test
|
||||||
+3
@@ -0,0 +1,3 @@
|
|||||||
|
package com.example
|
||||||
|
|
||||||
|
actual typealias Test = org.testng.annotations.Test
|
||||||
+1
@@ -0,0 +1 @@
|
|||||||
|
include ':lib', ':app'
|
||||||
Reference in New Issue
Block a user