Matthew Inger
02/11/2025, 2:42 PMabstract class StringGeneratorSegment @Inject constructor(
project: Project,
objects: ObjectFactory
) {
abstract val name: String
val inputDirectory =
objects.directoryProperty().convention(project.layout.projectDirectory.dir("src/${name}"))
val outputDirectory =
objects.directoryProperty().convention(project.layout.buildDirectory.dir("strings/${name}"))
override fun toString(): String {
return "StringGeneratorSegment(name=${name}, inputDirectory=${inputDirectory.get()}, outputDirectory=${outputDirectory.get()}"
}
}
val segments: NamedDomainObjectContainer<StringGeneratorSegment> =
project.container(StringGeneratorSegment::class)
I'd like to use the "name" property in the convention for the input and output directories, but those seem to be "null" when the convention is set. Is there any good way to do something like this?Vampire
02/11/2025, 2:51 PMabstract class StringGeneratorSegment @Inject constructor(
layout: ProjectLayout,
providers: ProviderFactory
) : Named {
abstract val inputDirectory: DirectoryProperty
abstract val outputDirectory: DirectoryProperty
init {
inputDirectory.convention(layout.projectDirectory.dir(providers.provider { "src/${name}" }))
outputDirectory.convention(layout.buildDirectory.dir(providers.provider { "strings/${name}" }))
}
override fun toString(): String {
return "StringGeneratorSegment(name=${name}, inputDirectory=${inputDirectory.get()}, outputDirectory=${outputDirectory.get()}"
}
}
Matthew Inger
02/11/2025, 3:07 PMval segments: NamedDomainObjectContainer<StringGeneratorSegment> =
project.container(StringGeneratorSegment::class) { name ->
objects.newInstance(StringGeneratorSegment::class.java, project, objects, name)
}
Matthew Inger
02/11/2025, 3:07 PMMatthew Inger
02/11/2025, 3:09 PMMatthew Inger
02/11/2025, 3:16 PMabstract class StringGeneratorSegment @Inject constructor(
project: Project,
objects: ObjectFactory,
providers: ProviderFactory
): Named {
val inputDirectory =
objects.directoryProperty().convention(project.layout.projectDirectory.dir(providers.provider { "src/${name}" }))
val outputDirectory =
objects.directoryProperty().convention(project.layout.buildDirectory.dir(providers.provider { "strings/${name}" }))
override fun toString(): String {
return "StringGeneratorSegment(name=${name}, inputDirectory=${inputDirectory.get()}, outputDirectory=${outputDirectory.get()}"
}
}
Vampire
02/11/2025, 3:26 PM