Last active
August 21, 2017 02:48
-
-
Save lizhangqu/364229c0994998684a11bad9a11bb123 to your computer and use it in GitHub Desktop.
java assemble filter for java source, java resources
This file contains 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
apply plugin: JavaFilterPlugin | |
class JavaFilterPlugin implements Plugin<Project> { | |
void apply(Project project) { | |
project.afterEvaluate { | |
if (project.file('filter.properties').exists()) { | |
def processResources = project.tasks.findByName("processResources") | |
processResources.configure { | |
from(processResources.source) { | |
filesMatching('*') { | |
Properties properties = new Properties() | |
properties.load(new FileInputStream(project.file('filter.properties'))) | |
filter(ReplaceTokens, tokens: properties, beginToken: '${', endToken: '}') | |
} | |
} | |
} | |
def compileJava = project.tasks.findByName("compileJava") | |
def filterJavaSources = project.tasks.create("filterJavaSources", Copy) { | |
from(compileJava.source) { | |
filesMatching('**/*.java') { | |
Properties properties = new Properties() | |
properties.load(new FileInputStream(project.file('filter.properties'))) | |
filter(ReplaceTokens, tokens: properties, beginToken: '${', endToken: '}') | |
} | |
} | |
into "$project.buildDir/generated-java-src" | |
} | |
compileJava.configure { | |
dependsOn filterJavaSources | |
setSource(filterJavaSources.outputs.files) | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment