Fix flaky TARGET_JVM_VERSION_ATTRIBUTE presence in gradle plugins
For some reason TARGET_JVM_VERSION_ATTRIBUTE was not always set in the resulting artifacts for runtimeElementsConfigurationName and apiElementsConfigurationName variants It could be reproduced locally with by executing `gradle kotlin-allopen:publishToMavenLocal` The fix can be checked via `gradle kotlin-allopen:outgoingVariants` ^KTI-920 Fixed
This commit is contained in:
committed by
Space Team
parent
d7fff3ca01
commit
e7074e8a92
@@ -8,8 +8,7 @@ import org.gradle.api.Project
|
|||||||
import org.gradle.api.artifacts.Configuration
|
import org.gradle.api.artifacts.Configuration
|
||||||
import org.gradle.api.artifacts.ModuleDependency
|
import org.gradle.api.artifacts.ModuleDependency
|
||||||
import org.gradle.api.artifacts.type.ArtifactTypeDefinition
|
import org.gradle.api.artifacts.type.ArtifactTypeDefinition
|
||||||
import org.gradle.api.attributes.Attribute
|
import org.gradle.api.attributes.*
|
||||||
import org.gradle.api.attributes.LibraryElements
|
|
||||||
import org.gradle.api.attributes.java.TargetJvmEnvironment
|
import org.gradle.api.attributes.java.TargetJvmEnvironment
|
||||||
import org.gradle.api.attributes.java.TargetJvmVersion
|
import org.gradle.api.attributes.java.TargetJvmVersion
|
||||||
import org.gradle.api.attributes.plugin.GradlePluginApiVersion
|
import org.gradle.api.attributes.plugin.GradlePluginApiVersion
|
||||||
@@ -319,9 +318,8 @@ fun Project.reconfigureMainSourcesSetForGradlePlugin(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
val javaComponent = project.components["java"] as AdhocComponentWithVariants
|
|
||||||
|
|
||||||
// Workaround for https://youtrack.jetbrains.com/issue/KT-52987
|
// Workaround for https://youtrack.jetbrains.com/issue/KT-52987
|
||||||
|
val javaComponent = project.components["java"] as AdhocComponentWithVariants
|
||||||
listOf(
|
listOf(
|
||||||
runtimeElementsConfigurationName,
|
runtimeElementsConfigurationName,
|
||||||
apiElementsConfigurationName
|
apiElementsConfigurationName
|
||||||
@@ -354,7 +352,7 @@ fun Project.reconfigureMainSourcesSetForGradlePlugin(
|
|||||||
}
|
}
|
||||||
|
|
||||||
plugins.withType<JavaPlugin> {
|
plugins.withType<JavaPlugin> {
|
||||||
tasks.named<JavaCompile>(compileJavaTaskName) {
|
tasks.named<JavaCompile>(compileJavaTaskName).get().apply {
|
||||||
attribute(
|
attribute(
|
||||||
TargetJvmVersion.TARGET_JVM_VERSION_ATTRIBUTE,
|
TargetJvmVersion.TARGET_JVM_VERSION_ATTRIBUTE,
|
||||||
targetCompatibility.toInt()
|
targetCompatibility.toInt()
|
||||||
@@ -363,12 +361,28 @@ fun Project.reconfigureMainSourcesSetForGradlePlugin(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val expectedAttributes = setOf(
|
||||||
|
Category.CATEGORY_ATTRIBUTE,
|
||||||
|
Bundling.BUNDLING_ATTRIBUTE,
|
||||||
|
Usage.USAGE_ATTRIBUTE,
|
||||||
|
LibraryElements.LIBRARY_ELEMENTS_ATTRIBUTE,
|
||||||
|
TargetJvmEnvironment.TARGET_JVM_ENVIRONMENT_ATTRIBUTE,
|
||||||
|
TargetJvmVersion.TARGET_JVM_VERSION_ATTRIBUTE
|
||||||
|
)
|
||||||
|
if (attributes.keySet() != expectedAttributes) {
|
||||||
|
error("Wrong set of attributes:\n" +
|
||||||
|
" Expected: ${expectedAttributes.joinToString(", ")}\n" +
|
||||||
|
" Actual: ${attributes.keySet().joinToString(", ") { "${it.name}=${attributes.getAttribute(it)}" }}")
|
||||||
|
}
|
||||||
|
|
||||||
javaComponent.addVariantsFromConfiguration(this) {
|
javaComponent.addVariantsFromConfiguration(this) {
|
||||||
if (originalConfiguration.name.startsWith("api")) {
|
mapToMavenScope(
|
||||||
mapToMavenScope("compile")
|
when (originalConfiguration.name) {
|
||||||
} else {
|
runtimeElementsConfigurationName -> "runtime"
|
||||||
mapToMavenScope("runtime")
|
apiElementsConfigurationName -> "compile"
|
||||||
}
|
else -> error("Unsupported configuration name")
|
||||||
|
}
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Make original configuration unpublishable and not visible
|
// Make original configuration unpublishable and not visible
|
||||||
|
|||||||
Reference in New Issue
Block a user