Created
January 14, 2016 13:41
-
-
Save ymauray/1981615c044e1538dd03 to your computer and use it in GitHub Desktop.
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
import com.mysema.query.codegen.GenericExporter | |
import com.mysema.query.codegen.Keywords | |
import javax.persistence.Embeddable | |
import javax.persistence.Embedded | |
import javax.persistence.Entity | |
import javax.persistence.MappedSuperclass | |
import javax.persistence.Transient | |
group 'yma' | |
version '1.0-SNAPSHOT' | |
buildscript { | |
repositories { | |
mavenCentral() | |
} | |
dependencies { | |
classpath group: 'org.springframework.boot', name: 'spring-boot-gradle-plugin', version: '1.3.0.RELEASE' | |
classpath group: 'com.mysema.querydsl', name: 'querydsl-codegen', version: '3.7.0' | |
classpath group: 'org.hibernate.javax.persistence', name: 'hibernate-jpa-2.1-api', version: '1.0.0.Final' | |
} | |
} | |
apply plugin: 'groovy' | |
apply plugin: 'spring-boot' | |
repositories { | |
mavenCentral() | |
} | |
configurations { | |
model | |
generated | |
} | |
bootRepackage { | |
mainClass = 'yma.demo.Application' | |
} | |
sourceSets { | |
model { | |
groovy { | |
srcDirs = ['src/main/groovy'] | |
include "yma/demo/model/**" | |
} | |
} | |
generated { | |
groovy { | |
srcDirs = ['src/main/generated'] | |
} | |
compileClasspath += sourceSets.model.output | |
} | |
main { | |
groovy { | |
exclude "yma/demo/model/**" | |
} | |
compileClasspath += sourceSets.model.output | |
compileClasspath += sourceSets.generated.output | |
} | |
} | |
jar { | |
exclude '**/application.properties' | |
from sourceSets.generated.output, sourceSets.model.output | |
} | |
task gen << { | |
def cl = new URLClassLoader([sourceSets.model.output.classesDir.toURI().toURL()] as URL[], project.buildscript.classLoader) | |
def targetFolder = new File("src/main/generated" as String) | |
def exporter = new GenericExporter(cl) | |
exporter.setKeywords(Keywords.JPA); | |
exporter.setTargetFolder(targetFolder) | |
exporter.setEntityAnnotation(Entity.class); | |
exporter.setEmbeddableAnnotation(Embeddable.class); | |
exporter.setEmbeddedAnnotation(Embedded.class); | |
exporter.setSupertypeAnnotation(MappedSuperclass.class); | |
exporter.setSkipAnnotation(Transient.class); | |
exporter.export("yma.demo.model" as String) | |
} | |
task cleanGenerated << { | |
sourceSets.generated.groovy.each { file -> | |
file.delete() | |
} | |
} | |
gen.dependsOn compileModelGroovy | |
compileGeneratedGroovy.dependsOn gen | |
clean.dependsOn cleanGenerated | |
dependencies { | |
compile group: 'org.springframework.boot', name: 'spring-boot-starter-data-jpa' | |
compile group: 'org.springframework.boot', name: 'spring-boot-configuration-processor' | |
compile group: 'org.codehaus.groovy', name: 'groovy-all', version: '2.4.5' | |
compile group: 'com.mysema.querydsl', name: 'querydsl-core', version: '3.7.0' | |
compile group: 'com.mysema.querydsl', name: 'querydsl-jpa', version: '3.7.0' | |
compile group: 'org.flywaydb', name: 'flyway-core', version: '3.2.1' | |
runtime group: 'mysql', name: 'mysql-connector-java', version: '5.1.38' | |
modelCompile configurations.compile | |
generatedCompile configurations.compile | |
} | |
bootRun { | |
def filesForClasspath = [] | |
filesForClasspath += sourceSets.main.runtimeClasspath | |
filesForClasspath += sourceSets.model.runtimeClasspath | |
filesForClasspath += sourceSets.generated.runtimeClasspath | |
classpath files(filesForClasspath) | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment