Suppose I have something like this:
abstract class MyService : BuildService<MyService.Parameters> {
interface Parameters {
// ...
}
private val objectMapping = ConcurrentHashMap<String, MyConfiguration>()
fun getConfiguration(name: String): MyConfiguration {
return objectMapping.computeIfAbsent("name") {
// populate using something from parameters
}
}
}
class MyConfiguration {
val classpath: ConfigurableFileCollection
}
abstract class MyTask @Inject constructor(execOps: ExecOperations) : DefaultTask() {
@get:Input
abstract val configurationName: Property<String>
@get:ServiceReference("...")
abstract val service: Property<MyService>
// convention is set to service.get().getConfigurationName(configurationName.get())
@get:Internal
abstract val configuration: Property<MyConfiguration>
@TaskAction
fun run() {
execOps.javaexec {
classpath = configuration.get().classpath
}
}
}
This somehow doesn’t feel right, owing to the fact that the classpath should be something that is cacheable - that is, a @Classpath
property seems to be missing. Would it suffice to define such a property, with a convention on it that is set to configuration.map { it.classpath }
? It seems weird to have a @InputFiles @Classpath
property derived from an @Internal
property.