Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't use Project.getProperties as it leads to early evaluation of properties #286

Open
osipxd opened this issue Dec 26, 2024 · 0 comments · May be fixed by #287
Open

Don't use Project.getProperties as it leads to early evaluation of properties #286

osipxd opened this issue Dec 26, 2024 · 0 comments · May be fixed by #287

Comments

@osipxd
Copy link
Member

osipxd commented Dec 26, 2024

val prop = project.properties[BANNED_TARGETS_PROPERTY_NAME] as String?

Here is a fragment of stacktrace showing how applying BCV unexpectedly triggers evaluation of jvmToolchain in JavaPluginExtension.

        ...
	at org.gradle.api.internal.provider.AbstractMinimalProvider.calculatePresence(AbstractMinimalProvider.java:95)
	at org.gradle.api.internal.provider.MappingProvider.calculatePresence(MappingProvider.java:50)
	at org.gradle.api.internal.provider.AbstractProperty.calculatePresence(AbstractProperty.java:81)
	at org.gradle.api.internal.provider.AbstractMinimalProvider.isPresent(AbstractMinimalProvider.java:90)
	at org.gradle.jvm.toolchain.internal.DefaultToolchainSpec.isConfigured(DefaultToolchainSpec.java:82)
	at org.gradle.jvm.toolchain.internal.DefaultToolchainSpec_Decorated.isConfigured(Unknown Source)
	at org.gradle.api.plugins.internal.DefaultJavaPluginExtension.getSourceCompatibility(DefaultJavaPluginExtension.java:135)
	at org.gradle.api.plugins.internal.DefaultJavaPluginExtension_Decorated.getSourceCompatibility(Unknown Source)
	at org.gradle.api.plugins.internal.DefaultJavaPluginExtension.getTargetCompatibility(DefaultJavaPluginExtension.java:158)
	at org.gradle.api.plugins.internal.DefaultJavaPluginExtension_Decorated.getTargetCompatibility(Unknown Source)
	at org.gradle.api.plugins.internal.DefaultJavaPluginConvention.getTargetCompatibility(DefaultJavaPluginConvention.java:92)
	at org.gradle.api.plugins.internal.DefaultJavaPluginConvention_Decorated.getTargetCompatibility(Unknown Source)
	at org.gradle.api.plugins.internal.NaggingJavaPluginConvention.getTargetCompatibility(NaggingJavaPluginConvention.java:83)
	at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103)
	at java.base/java.lang.reflect.Method.invoke(Method.java:580)
	at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:107)
	at org.codehaus.groovy.runtime.metaclass.MultipleSetterProperty.getProperty(MultipleSetterProperty.java:49)
	at org.gradle.internal.metaobject.BeanDynamicObject$MetaClassAdapter.getProperties(BeanDynamicObject.java:500)
	at org.gradle.internal.metaobject.BeanDynamicObject.getProperties(BeanDynamicObject.java:208)
	at org.gradle.internal.extensibility.DefaultConvention$ExtensionsDynamicObject.getProperties(DefaultConvention.java:261)
	at org.gradle.internal.metaobject.CompositeDynamicObject.getProperties(CompositeDynamicObject.java:80)
	at org.gradle.internal.extensibility.ExtensibleDynamicObject$InheritedDynamicObject.getProperties(ExtensibleDynamicObject.java:238)
	at org.gradle.internal.metaobject.CompositeDynamicObject.getProperties(CompositeDynamicObject.java:80)
	at org.gradle.api.internal.project.DefaultDynamicLookupRoutine.lambda$getProperties$0(DefaultDynamicLookupRoutine.java:52)
	at org.gradle.internal.deprecation.DeprecationLogger.whileDisabled(DeprecationLogger.java:253)
	at org.gradle.api.internal.project.DefaultDynamicLookupRoutine.getProperties(DefaultDynamicLookupRoutine.java:52)
	at org.gradle.api.internal.project.DefaultProject.getProperties(DefaultProject.java:1228)
	at kotlinx.validation.KlibValidationPipelineBuilder.bannedTargets(BinaryCompatibilityValidatorPlugin.kt:467)
	at kotlinx.validation.KlibValidationPipelineBuilder.targetIsSupported(BinaryCompatibilityValidatorPlugin.kt:546)
	at kotlinx.validation.KlibValidationPipelineBuilder.access$targetIsSupported(BinaryCompatibilityValidatorPlugin.kt:352)
	at kotlinx.validation.KlibValidationPipelineBuilder$configureTargets$4.invoke(BinaryCompatibilityValidatorPlugin.kt:505)
	at kotlinx.validation.KlibValidationPipelineBuilder$configureTargets$4.invoke(BinaryCompatibilityValidatorPlugin.kt:497)
	at kotlinx.validation.BinaryCompatibilityValidatorPluginKt$sam$org_gradle_api_Action$0.execute(BinaryCompatibilityValidatorPlugin.kt)
	<17 internal lines>
	at org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtensionKt.configureOrCreate(KotlinMultiplatformExtension.kt:341)

The problem is in Project.getProperties call which gathers properties from the following sources (in a non-lazy way):

  • Project object properties
  • Project extensions
  • Project convention properties
  • Project extra properties
  • Project tasks
  • Searches up through this project's ancestor projects for convention properties or extra properties.

The solution is to replace this call with Project.findProperty which searches by name without triggering evaluation of all properties.

Related:

@osipxd osipxd linked a pull request Dec 26, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant