Create a gist now

Instantly share code, notes, and snippets.

@taichi /build.gradle
Last active Dec 20, 2015

What would you like to do?
doma-tutorial-1.31.0.zipに含まれるbuild.gradleをより改善したビルドスクリプト。
apply plugin: 'java'
sourceCompatibility = targetCompatibility = 1.6
tasks.withType(AbstractCompile) each { it.options.encoding = 'UTF-8' }
repositories {
mavenCentral()
maven {url 'http://maven.seasar.org/maven2'}
}
dependencies {
compile 'org.seasar.doma:doma:1.+'
compile 'com.h2database:h2:1.+'
testCompile 'junit:junit:3.8.+'
}
/* Doma Configurations */
sourceSets {
doma {
resources.srcDir main.resources
output.resourcesDir = main.output.classesDir
}
}
compileJava.dependsOn processDomaResources
jar.exclude '**/*.java'
/* Doma-Gen */
apply from:'doma-gen.gradle'
/* Doma for eclipse */
apply from:'eclipse.gradle'
configurations { domagen }
dependencies {
domagen 'com.h2database:h2:1.+'
domagen 'org.seasar.doma:doma-gen:1.31.0'
}
def javaDestDir='src/main/java'
def sqlDestDir= 'src/main/resources'
def dialectName= 'h2'
def driverClassName= 'org.h2.Driver'
def url= 'jdbc:h2:file:~/data/sample'
def user= 'sa'
def password= ''
def entityPackageName= 'example.entity'
def daoPackageName='example.dao'
def configClassName= 'example.AppConfig'
def sqlTestClassName= 'example.SqlTest'
def sqlFilePattern= 'META-INF/**/*.sql'
task gen << {
ant {
taskdef(
name:'genTask',
classname: "org.seasar.doma.extension.gen.task.Gen",
classpath: configurations.domagen.asPath)
genTask(
dialectName:"${dialectName}",
driverClassName:"${driverClassName}",
url:"${url}",
user:"${user}",
password:"${password}") {
entityConfig(
destdir:"${javaDestDir}",
packageName:"${entityPackageName}")
daoConfig(
destdir:"${javaDestDir}",
packageName:"${daoPackageName}",
configClassName:"${configClassName}")
sqlConfig(destdir:"${sqlDestDir}")
}
}
}
task genTest << {
ant {
taskdef(
name:'getTestTask',
classname: "org.seasar.doma.extension.gen.task.GenTest",
classpath: configurations.domagen.asPath)
getTestTask(
dialectName:"${dialectName}",
driverClassName:"${driverClassName}",
url:"${url}",
user:"${user}",
password:"${password}") {
sqlTestConfig(destdir:"src/test/java",testClassName:"${sqlTestClassName}") {
fileset(dir:"${sqlDestDir}", includes:"${sqlFilePattern}")
}
}
}
}
apply plugin: 'eclipse'
ext { aptDir='.apt_generated' }
eclipse {
jdt.file.withProperties { it['org.eclipse.jdt.core.compiler.processAnnotations'] = 'enabled' }
classpath {
containers = [
'org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6'
]
}
}
eclipseJdt {
def clos = []
def fp = file('.factorypath')
outputs.file fp
clos += {
fp.withWriter {
def domaJar = configurations.compile.find {
it.name.contains('doma-')
}
new groovy.xml.MarkupBuilder(it).factorypath() {
factorypathentry(kind:'EXTJAR', id:domaJar, enabled:true, runInBatchMode:false)
}
}
}
def prefs = { name, contents ->
def f = file(".settings/$name")
clos += {
f.text = contents.stripMargin()
}
outputs.file f
}
prefs 'org.eclipse.jdt.apt.core.prefs', """\
|eclipse.preferences.version=1
|org.eclipse.jdt.apt.aptEnabled=true
|org.eclipse.jdt.apt.genSrcDir=${aptDir}
|org.eclipse.jdt.apt.reconcileEnabled=true
|"""
doLast { clos*.run() }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment