Link the 'api' configuration to 'apiElements' (KT-28355)
As we introduced the 'api' configurations for Kotlin source sets, the Java plugin did not link these configurations to its 'apiElements', and those dependencies would only get published with the 'runtime' scope through the 'implementation' configuration. To fix this, manually specify that 'apiElements' extendsFrom 'api'. Issue #KT-28355 Fixed
This commit is contained in:
+33
@@ -876,6 +876,39 @@ class KotlinGradleIT : BaseGradleIT() {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testKotlinJvmProjectPublishesKotlinApiDependenciesAsCompile() =
|
||||
with(Project("simpleProject", GradleVersionRequired.AtLeast("4.4"))) {
|
||||
setupWorkingDir()
|
||||
gradleBuildScript().appendText(
|
||||
"\n" + """
|
||||
dependencies {
|
||||
api 'org.jetbrains.kotlin:kotlin-reflect'
|
||||
}
|
||||
apply plugin: 'maven-publish'
|
||||
group "com.example"
|
||||
version "1.0"
|
||||
publishing {
|
||||
repositories { maven { url file("${'$'}buildDir/repo").toURI() } }
|
||||
publications { maven(MavenPublication) { from components.java } }
|
||||
}
|
||||
""".trimIndent()
|
||||
)
|
||||
build("publish") {
|
||||
assertSuccessful()
|
||||
val pomText = projectDir.resolve("build/repo/com/example/simpleProject/1.0/simpleProject-1.0.pom").readText()
|
||||
.replace("\\s+|\\n".toRegex(), "")
|
||||
assertTrue {
|
||||
pomText.contains(
|
||||
"<groupId>org.jetbrains.kotlin</groupId>" +
|
||||
"<artifactId>kotlin-reflect</artifactId>" +
|
||||
"<version>${defaultBuildOptions().kotlinVersion}</version>" +
|
||||
"<scope>compile</scope>"
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testNoTaskConfigurationForcing() {
|
||||
val gradleVersionRequirement = GradleVersionRequired.AtLeast("4.9")
|
||||
|
||||
+12
@@ -454,6 +454,18 @@ internal abstract class AbstractKotlinPlugin(
|
||||
val kotlinSourceSet = project.kotlinExtension.sourceSets.maybeCreate(kotlinCompilation.defaultSourceSetName)
|
||||
kotlinCompilation.source(kotlinSourceSet)
|
||||
}
|
||||
|
||||
// Since the 'java' plugin (as opposed to 'java-library') doesn't known anything about the 'api' configurations,
|
||||
// add the API dependencies of the main compilation directly to the 'apiElements' configuration, so that the 'api' dependencies
|
||||
// are properly published with the 'compile' scope (KT-28355):
|
||||
project.whenEvaluated {
|
||||
project.configurations.apply {
|
||||
val apiElementsConfiguration = getByName(kotlinTarget.apiElementsConfigurationName)
|
||||
val mainCompilation = kotlinTarget.compilations.getByName(KotlinCompilation.MAIN_COMPILATION_NAME)
|
||||
val compilationApiConfiguration = getByName(mainCompilation.apiConfigurationName)
|
||||
apiElementsConfiguration.extendsFrom(compilationApiConfiguration)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun configureAttributes(
|
||||
|
||||
Reference in New Issue
Block a user