Last active
December 29, 2020 14:59
-
-
Save ghale/a7ed09ae122b4dd2e0aef61b49136438 to your computer and use it in GitHub Desktop.
Annotation processor with output arguments
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 { | |
// Set up the localization values | |
def localizationMethod = "foo" | |
def localizationOutputDir = file("${buildDir}/localizationTool") | |
// Add the argument provider to the compiler arguments | |
options.compilerArgumentProviders.add(new LocalizationArgumentProvider(localizationMethod, "clientbase", localizationOutputDir)) | |
// This captures the argument provider as a custom value in the build scan for troubleshooting purposes only | |
doFirst { | |
buildScan.value "${path}.compilerArgs", options.allCompilerArgs.join("\n") | |
} | |
} | |
class LocalizationArgumentProvider implements CommandLineArgumentProvider { | |
@Input | |
String localizationMethod | |
@Input | |
String bundleName | |
// Specifies this directory is actually an output of the compile task | |
@OutputDirectory | |
File outputDir | |
LocalizationArgumentProvider(String localizationMethod, String bundleName, File outputDir) { | |
this.localizationMethod = localizationMethod | |
this.bundleName = bundleName | |
this.outputDir = outputDir | |
} | |
// Provide the actual arguments that should be added to the compiler command line | |
Iterable<String> asArguments() { | |
return ["-Acom.devexperts.uilocalizer.localizationMethod=${localizationMethod}", | |
"-Acom.devexperts.uilocalizer.outputFolder=${outputDir}", | |
"-Acom.devexperts.uilocalizer.requiredBundleName=${bundleName}"] | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment