Skip to content

Instantly share code, notes, and snippets.

@ghale
Created April 17, 2020 15:57
Show Gist options
  • Save ghale/e38c7c953db5da8e2e0288068f41c632 to your computer and use it in GitHub Desktop.
Save ghale/e38c7c953db5da8e2e0288068f41c632 to your computer and use it in GitHub Desktop.
Compiler argument provider example
plugins {
id 'java'
}
tasks.withType(JavaCompile).configureEach {
def resourcesDir = project.file("${projectDir}/resources")
options.compilerArgumentProviders.add(MyAnnotationArgumentProvider.from(resourcesDir))
// This captures the argument provider as a custom value in the build scan for troubleshooting purposes only
doFirst {
buildScan.value "${path} compiler args", options.allCompilerArgs.join("\n")
}
}
class MyAnnotationArgumentProvider implements CommandLineArgumentProvider {
@InputDirectory
@PathSensitive(PathSensitivity.RELATIVE)
File inputDir
MyAnnotationArgumentProvider(File inputDir) {
this.inputDir = inputDir
}
static MyAnnotationArgumentProvider from(File inputDir) {
return new MyAnnotationArgumentProvider(inputDir)
}
Iterable<String> asArguments() {
return ["-Aresources.dir=${inputDir}"]
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment