Created
April 17, 2020 15:57
-
-
Save ghale/e38c7c953db5da8e2e0288068f41c632 to your computer and use it in GitHub Desktop.
Compiler argument provider example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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