Properly setup localToProject attribute in jvmWithJava (KT-29035)
A dependency on a multiplatform module with a jvmWithJava target failed to resolve because the 'apiElements' and 'runtimeElements' configurations didn't have the attribute 'localToProject' set to 'public'. Those configurations need to have have the attribute set as per the fix of KT-28795, but it doesn't happen. Issue #KT-29035 Fixed
This commit is contained in:
+6
@@ -229,6 +229,12 @@ class VariantAwareDependenciesIT : BaseGradleIT() {
|
||||
testResolveAllConfigurations("sample-lib")
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testJvmWithJavaProjectCanBeResolvedInAllConfigurations() =
|
||||
with(Project("new-mpp-jvm-with-java-multi-module", GradleVersionRequired.AtLeast("4.7"))) {
|
||||
testResolveAllConfigurations("app")
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testConfigurationsWithNoExplicitUsageResolveRuntime() =
|
||||
// Starting with Gradle 5.0, plain Maven dependencies are represented as two variants, and resolving them to the API one leads
|
||||
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
apply plugin: 'kotlin-multiplatform'
|
||||
|
||||
kotlin {
|
||||
sourceSets {
|
||||
commonMain.dependencies {
|
||||
api project(':lib')
|
||||
api kotlin('stdlib-common')
|
||||
}
|
||||
}
|
||||
targetFromPreset(presets.jvmWithJava, 'jvm') {
|
||||
compilations.main.defaultSourceSet.dependencies {
|
||||
api kotlin('stdlib')
|
||||
}
|
||||
}
|
||||
}
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
package com.exmaple.app
|
||||
|
||||
import com.example.lib.*
|
||||
|
||||
fun main() {
|
||||
println(A())
|
||||
println(hello())
|
||||
}
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
buildscript {
|
||||
repositories {
|
||||
mavenLocal()
|
||||
jcenter()
|
||||
}
|
||||
dependencies {
|
||||
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
|
||||
}
|
||||
}
|
||||
|
||||
allprojects {
|
||||
repositories {
|
||||
mavenLocal()
|
||||
jcenter()
|
||||
}
|
||||
}
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
apply plugin: 'kotlin-multiplatform'
|
||||
|
||||
kotlin {
|
||||
sourceSets {
|
||||
commonMain.dependencies {
|
||||
api kotlin('stdlib-common')
|
||||
}
|
||||
}
|
||||
targetFromPreset(presets.jvmWithJava, 'jvm') {
|
||||
compilations.main.defaultSourceSet.dependencies {
|
||||
api kotlin('stdlib')
|
||||
}
|
||||
}
|
||||
}
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
package com.example.lib
|
||||
|
||||
expect fun hello(): String
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
package com.example.lib;
|
||||
|
||||
public class A {
|
||||
String hello = AKt.hello();
|
||||
}
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
package com.example.lib
|
||||
|
||||
actual fun hello(): String = "Hello, JVM!"
|
||||
+1
@@ -0,0 +1 @@
|
||||
include 'lib', 'app'
|
||||
+1
-1
@@ -125,7 +125,7 @@ class Android25ProjectHandler(kotlinConfigurationTools: KotlinConfigurationTools
|
||||
override fun setUpDependencyResolution(variant: BaseVariant, compilation: KotlinJvmAndroidCompilation) {
|
||||
val project = compilation.target.project
|
||||
|
||||
AbstractKotlinTargetConfigurator.defineConfigurationsForCompilation(compilation, compilation.target, project.configurations)
|
||||
AbstractKotlinTargetConfigurator.defineConfigurationsForCompilation(compilation)
|
||||
|
||||
compilation.compileDependencyFiles = variant.compileConfiguration.apply {
|
||||
usesPlatformOf(compilation.target)
|
||||
|
||||
+2
-2
@@ -382,7 +382,6 @@ internal abstract class AbstractKotlinPlugin(
|
||||
{ compilation -> buildSourceSetProcessor(project, compilation, kotlinPluginVersion) }
|
||||
)
|
||||
|
||||
configureAttributes(target)
|
||||
configureProjectGlobalSettings(project, kotlinPluginVersion)
|
||||
registry.register(KotlinModelBuilder(kotlinPluginVersion, null))
|
||||
}
|
||||
@@ -399,6 +398,7 @@ internal abstract class AbstractKotlinPlugin(
|
||||
) {
|
||||
setUpJavaSourceSets(target)
|
||||
configureSourceSetDefaults(target, buildSourceSetProcessor)
|
||||
configureAttributes(target)
|
||||
}
|
||||
|
||||
private fun configureClassInspectionForIC(project: Project) {
|
||||
@@ -476,7 +476,7 @@ internal abstract class AbstractKotlinPlugin(
|
||||
// Setup the consuming configurations:
|
||||
project.dependencies.attributesSchema.attribute(KotlinPlatformType.attribute)
|
||||
kotlinTarget.compilations.all { compilation ->
|
||||
AbstractKotlinTargetConfigurator.defineConfigurationsForCompilation(compilation, kotlinTarget, project.configurations)
|
||||
AbstractKotlinTargetConfigurator.defineConfigurationsForCompilation(compilation)
|
||||
}
|
||||
|
||||
project.configurations.getByName("default").apply {
|
||||
|
||||
+5
-4
@@ -99,7 +99,7 @@ abstract class AbstractKotlinTargetConfigurator<KotlinTargetType : KotlinTarget>
|
||||
val project = target.project
|
||||
|
||||
target.compilations.all { compilation ->
|
||||
defineConfigurationsForCompilation(compilation, target, project.configurations)
|
||||
defineConfigurationsForCompilation(compilation)
|
||||
|
||||
if (createDefaultSourceSets) {
|
||||
project.kotlinExtension.sourceSets.maybeCreate(compilation.defaultSourceSetName).also { sourceSet ->
|
||||
@@ -233,10 +233,11 @@ abstract class AbstractKotlinTargetConfigurator<KotlinTargetType : KotlinTarget>
|
||||
const val testTaskNameSuffix = "test"
|
||||
|
||||
fun defineConfigurationsForCompilation(
|
||||
compilation: KotlinCompilation<*>,
|
||||
target: KotlinTarget,
|
||||
configurations: ConfigurationContainer
|
||||
compilation: KotlinCompilation<*>
|
||||
) {
|
||||
val target = compilation.target
|
||||
val configurations = target.project.configurations
|
||||
|
||||
val compileConfiguration = configurations.maybeCreate(compilation.deprecatedCompileConfigurationName).apply {
|
||||
setupAsLocalTargetSpecificConfigurationIfSupported(target)
|
||||
isVisible = false
|
||||
|
||||
-5
@@ -215,11 +215,6 @@ class KotlinJvmWithJavaTargetPreset(
|
||||
Kotlin2JvmSourceSetProcessor(project, KotlinTasksProvider(name), compilation, kotlinPluginVersion)
|
||||
}
|
||||
|
||||
target.compilations.all { compilation ->
|
||||
// Set up dependency resolution using platforms:
|
||||
AbstractKotlinTargetConfigurator.defineConfigurationsForCompilation(compilation, target, project.configurations)
|
||||
}
|
||||
|
||||
target.compilations.getByName("test").run {
|
||||
val main = target.compilations.getByName(KotlinCompilation.MAIN_COMPILATION_NAME)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user