Slackbot
05/02/2023, 1:41 PMVampire
05/02/2023, 1:48 PMThe main point is declare really everything what can influence task result as input, ideally by provider.That is more for task up-to-dateness and task output cacheability. For configuration cache, you just are not allowed to do certain things at execution time like accessing the
project
or having things as properties that Gradle cannot serialize into the configuration cache.Vampire
05/02/2023, 1:50 PMI also basically don't understand why configuration cache require such strict requirements on tasks.The tasks state after configuration is serialized into the CC and the deserialized from there, so some things that cannot be serialized properly just are not allowed and some things like accessing
project
is also no allowed as it might not have the state you try to query as just the tasks state is serialized in CCVampire
05/02/2023, 1:50 PMAdam
05/02/2023, 1:51 PMIt is possible to create a POJO class and which will contain all required data?yeah, it should be, if it is either a Gradle managed type or it implements
java.io.Serializable
https://docs.gradle.org/current/userguide/configuration_cache.html#config_cache:not_yet_implemented:java_serialization
Just make sure to annotate the task properties in the POJO with the correct task input/output types, and use @Nested
when it’s a task property
To reduce the duplication if you have lots of different specific task types, then you could create some custom task type for all your tasks, and define the POJO as a property
abstract class MyBaseTaskType : DefaultTask() {
@get:Nested
abstract val myCommonData: Property<MyCommonData>
}
and then in the plugin you can configure all tasks by type, and add the data - then it’s just done in one place
project.tasks.withType<MyBaseTaskType>().configureEach {
myCommonData.convention( ... )
}
Vampire
05/02/2023, 1:51 PMI have for example many tasks which are run only sometimes and I doesn't need to cache their result.You could also make them as incompatible with CC, then CC is not used if they are to be executed, but that's by far not the preferable solution
Tomáš Procházka
05/02/2023, 1:55 PM@get:Nested
abstract val myCommonData: Property<MyCommonData>
But to have Properties inside of MyCommonData like
class MyCommonData {
val version : Property<String>
val versionCode : Property<Int>
val commitHash : Property<String>
}
And here I don't know how to create a instance of PropertyVampire
05/02/2023, 1:57 PMVampire
05/02/2023, 1:57 PMObjectFactory#newInstance
Vampire
05/02/2023, 1:57 PMVampire
05/02/2023, 1:58 PMinterface MyCommonData {
val version: Property<String>
val versionCode: Property<Int>
val commitHash: Property<String>
}
and then
objects.newInstance<MyCommonData>()
Vampire
05/02/2023, 1:59 PMVampire
05/02/2023, 1:59 PMExtensionAware
explicitlyVampire
05/02/2023, 1:59 PMinterface MyCommonData : ExtensionAware {
val version: Property<String>
val versionCode: Property<Int>
val commitHash: Property<String>
}
Vampire
05/02/2023, 1:59 PM@Nested
Tomáš Procházka
05/02/2023, 2:00 PMVampire
05/02/2023, 2:00 PMVampire
05/02/2023, 2:01 PMVampire
05/02/2023, 2:01 PMAdam
05/02/2023, 2:02 PMobjects.newInstance()
https://docs.gradle.org/current/userguide/custom_gradle_types.html#nested_objects
and here for getting an instance of ObjectFactory (because config-cache forbids using Project.getObjects()
!) as well as other servicesVampire
05/02/2023, 2:04 PMVampire
05/02/2023, 2:04 PMObjectFactory
is preferable of course.Adam
05/02/2023, 2:05 PMAt configuration time it should be ok to use it, shouldn’t it?🤷♀️ config-cache is always a mystery to me. One thing works, another spits out an indecipherable error. I just always inject and use build services, and never use
Project
Tomáš Procházka
05/02/2023, 2:06 PMVampire
05/02/2023, 2:06 PMTomáš Procházka
05/02/2023, 2:10 PMproject.tasks.register<RemoteSignApkTask>("${variant.name}ApkRemoteSign") {
setup(variant, gitClient, somethingElse)
}
And task will collect data that needs from theese objects.
Create this POJO class instance and fill @Input field with it.
I don't want to repeat setup of all inputs everytime I'm using it.
And change it on several place when input requirement will change.Tomáš Procházka
05/02/2023, 8:47 PMfun setup()
as setter for property up, interesting.Vampire
05/02/2023, 10:22 PMTomáš Procházka
05/03/2023, 11:10 PMVampire
05/03/2023, 11:12 PM