asciidoctor-gradle-plugin
asciidoctor-gradle-plugin copied to clipboard
argumentProviders should be marked as `@Nested`
AsciidoctorArgumentProviders are a way to completely ignore attributes from task inputs snapshotting. However sometimes one wants an attribute value to be included in task inputs snapshotting but with some normalization applied in order to get build caching right. An example for this is having an attribute to points to some directory. In this case in order to get cross host cache hits when using a remote cache, one currently needs to setup an AsciidoctorArgumentProviders and also add the directory as an input:
tasks {
asciidoctor {
val snippetsDir = file("src/snippets")
attributeProviders += AsciidoctorAttributeProvider { mapOf("some-dir", snippetsDir) }
inputs.dir(snippetsDir)
.withPathSensitivity(RELATIVE_PATH)
}
}
This could be solved by marking the attributeProviders field with @Nested instead of @Internal. This would then work the same way as jvmArgumentProviders on JavaForkOptions: https://github.com/gradle/gradle/blob/b5c9a6a9be663bf6a3560d9959b03d98cfc099fd/subprojects/core-api/src/main/java/org/gradle/process/JavaForkOptions.java#L165-L166. Ignoring some input from up-to-date checking and cache key calculation would still be possible:
tasks {
asciidoctor {
// ignoring some input, because this provider does not declare any properties
attributeProviders += AsciidoctorAttributeProvider { mapOf("some-ignored-input", file("path/to/dir")) }
// src/snippets is included in task inputs snapshotting with relative path normalization
attributeProviders += SnippetsProvider(file("src/snippets"))
}
class SnippetsProvider(@InputFiles @PathSensitive(PathSensitivity.RELATIVE) val snippetDir: dir)
: AsciidoctorAttributeProvider {
override fun getAttributes() = mapOf("snippets-dir", dir)
}
}