46 lines
1.1 KiB
Groovy
46 lines
1.1 KiB
Groovy
class TestPlugin implements Plugin<Project> {
|
|
void apply(Project project) {
|
|
project.task('runPlugin') {
|
|
group = 'application'
|
|
def p = new SortedProperties()
|
|
p.put("apple", "one")
|
|
p.put("beta", "two")
|
|
p.put("coffee", "three")
|
|
def f = new File("test.properties")
|
|
f.withOutputStream { stream -> p.store(stream, "Generated by the plugin.") }
|
|
doLast {
|
|
println "> cat ${f.name}"
|
|
f.eachLine {
|
|
println it
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
class SortedProperties extends Properties {
|
|
@Override
|
|
Enumeration<Object> keys() {
|
|
def keys = Collections.list(super.keys())
|
|
keys.sort { a, b -> (a.toString() <=> b.toString()) }
|
|
return Collections.enumeration(keys)
|
|
}
|
|
}
|
|
|
|
apply plugin: TestPlugin
|
|
apply plugin: 'groovy'
|
|
apply plugin: 'application'
|
|
|
|
mainClassName = 'com.example.App'
|
|
|
|
dependencies {
|
|
compile 'org.codehaus.groovy:groovy-all:2.4.14'
|
|
}
|
|
|
|
repositories {
|
|
jcenter()
|
|
}
|
|
|
|
clean {
|
|
delete fileTree(dir: "$projectDir", include: "*.properties")
|
|
}
|