Rasmus Larsen
10/31/2024, 1:45 PMversionControl {
group {
groupName = "com.example.something"
exclude {
moduleName = "ui"
moduleVersion = "1.0.0"
}
exclude {
moduleName = "domain"
moduleVersion = "1.0.0"
}
}
group {
groupName = "com.example.somethingElse"
exclude {
moduleName = "foundation"
moduleVersion = "1.0.0"
}
}
}
If I do moduleName = "something" I get this error: Caused by: groovy.lang.MissingPropertyException: Could not set unknown property 'moduleName' for object of type com.example.versioncontrolplugin.DependencyGroup. But If I instead do this it.moduleName = "something" it seems to work.
How can I avoid the need for using it. ?
Code added in the comment :)Rasmus Larsen
10/31/2024, 1:47 PMopen class VersionControlExtension(
private val objectFactory: ObjectFactory
) {
var groups: ListProperty<DependencyGroup> = objectFactory.listProperty(DependencyGroup::class.java).convention(emptyList())
fun group(action: Action<in DependencyGroup>) {
val group = DependencyGroup(objectFactory)
action.execute(group)
groups.add(group)
}
}
DependencyGroup:
open class DependencyGroup(
private val objectFactory: ObjectFactory
) {
var groupName: Property<String> = objectFactory.property(String::class.java)
var moduleExclusions: ListProperty<ModuleExclusion> = objectFactory.listProperty(ModuleExclusion::class.java).convention(emptyList())
fun exclude(action: Action<in ModuleExclusion>): ModuleExclusion {
val moduleExclusion = ModuleExclusion(objectFactory)
action.execute(moduleExclusion)
moduleExclusions.add(moduleExclusion)
return moduleExclusion
}
fun setGroupName(groupName: String) {
this.groupName.set(groupName)
}
}
ModuleExclusion:
open class ModuleExclusion(
objects: ObjectFactory
) {
var moduleName: Property<String> = objects.property(String::class.java)
var moduleVersion: Property<String> = objects.property(String::class.java)
var isVersionIncluded: Property<Boolean> = objects.property(Boolean::class.java).convention(true)
fun setModuleName(value: String) { moduleName.set(value) }
fun setModuleVersion(value: String) { moduleVersion.set(value) }
fun setIsVersionIncluded(value: Boolean) { isVersionIncluded.set(value) }
}ephemient
10/31/2024, 2:35 PM.gradle.kts or a .kt file?
if it's a .kt file, is it in a project that applies `plugins { kotlin-dsl }`?Rasmus Larsen
10/31/2024, 4:11 PM.gradle in an Android project and no usage of kotlin-dsl.Vampire
10/31/2024, 6:09 PMRasmus Larsen
10/31/2024, 6:41 PMModuleExclusion an interface, how should I then do the fun exclude(action: Action<in ModuleExclusion>) that should add the ModuleExclusion to the ListProperty?Vampire
10/31/2024, 8:34 PMModuleExclusion an interface and keep DependencyGroup as class, but abstract with abstract val properties, then you at least save some of the boilerplate.
Alternatively, I think it should also work to add ModuleExclusion as extension to DependencyGroup.
Each thing you instantiate through Gradle is automatically decorated to be ExtensionAware, so you can just cast it.
Or you can also - that's what I do with all my Gradle-constructed types - explicitly declare them to implement ExtensionAware, Gradle will care for the implementation anyway.Rasmus Larsen
10/31/2024, 9:47 PMAlternatively, I think it should also work to add ModuleExclusion as extension to DependencyGroup
how do I do this?
Vampire
11/01/2024, 12:20 AMModuleExclusion an interface, but all the rest holds.Rasmus Larsen
11/01/2024, 2:02 PMephemient
11/01/2024, 11:59 PMephemient
11/02/2024, 12:02 AM