Skip to content

Instantly share code, notes, and snippets.

@yaboong
Forked from arcezd/build.gradle
Created June 5, 2019 01:47
Show Gist options
  • Save yaboong/881297300d89efaf446b8960e668c90c to your computer and use it in GitHub Desktop.
Save yaboong/881297300d89efaf446b8960e668c90c to your computer and use it in GitHub Desktop.
Build Gradle to read yaml properties [Gradle 2.13]
import org.yaml.snakeyaml.DumperOptions
import org.yaml.snakeyaml.Yaml
buildscript{
ext{
springBootVersion = '1.5.7.RELEASE'
}
repositories{
mavenCentral()
}
dependencies{
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
classpath("org.yaml:snakeyaml:1.17")
}
}
apply plugin: 'java'
apply plugin: 'groovy'
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'org.springframework.boot'
apply plugin: 'war'
task config{
InputStream input = new FileInputStream(new File("$projectDir/src/main/resources/application.yml"));
Yaml yaml = new Yaml();
for (Object data: yaml.loadAll(input)){
Map<String, Object> map = (Map<String, Object>) data;
project.ext."baseName" = (String) map.get("info").get("name");
project.ext."buildVer" = (String) map.get("info").get("build").get("version");
}
}
repositories{
mavenCentral()
}
sourceCompatibility =1.8
targetCompatibility =1.8
configurations{
all*.exclude module: 'spring-boot-starter-logging'
jaxb
providedRuntime
}
task genJaxb{
ext.sourcesDir ="${buildDir}/generated-sources/jaxb"
ext.classesDir ="${buildDir}/classes/jaxb"
ext.schema ="src/main/resources/schemas/sms.xsd"
outputs.dir classesDir
doLast(){
project.ant{
taskdef name: "xjc", classname: "com.sun.tools.xjc.XJCTask",
classpath: configurations.jaxb.asPath
mkdir(dir: sourcesDir)
mkdir(dir: classesDir)
xjc(destdir: sourcesDir, schema: schema){
arg(value: "-wsdl")
produces(dir: sourcesDir, includes: "**/*.java")
}
javac(destdir: classesDir, source: 1.6, target: 1.6, debug: true,
debugLevel: "lines,vars,source",
classpath: configurations.jaxb.asPath){
src(path: sourcesDir)
include(name: "**/*.java")
include(name: "*.java")
}
copy(todir: classesDir){
fileset(dir: sourcesDir, erroronmissingdir: false){
exclude(name: "**/*.java")
}
}
}
}
}
task afterEclipseImport{
dependsOn"genJaxb"
}
war{
baseName = project.property('baseName')
version = project.property('buildVer')
from genJaxb.classesDir
}
dependencies{
compile('org.springframework.boot:spring-boot-starter-web-services')
compile('org.springframework.boot:spring-boot-starter-thymeleaf')
compile('org.springframework.boot:spring-boot-starter-data-jpa')
compile('org.springframework.boot:spring-boot-starter-log4j2')
compile('wsdl4j:wsdl4j: 1.6.3')
compile('javax.xml.bind:jaxb-api: 2.3.0')
jaxb('org.glassfish.jaxb:jaxb-xjc: 2.3.0')
compile(files(genJaxb.classesDir).builtBy(genJaxb))
compile files('libs/com/oracle/ojdbc7/ojdbc7.jar')
testCompile('org.springframework.boot:spring-boot-starter-test')
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment