Skip to content

Instantly share code, notes, and snippets.

@u1aryz
Last active December 10, 2015 11:38
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save u1aryz/4428306 to your computer and use it in GitHub Desktop.
Save u1aryz/4428306 to your computer and use it in GitHub Desktop.
build.gradle for Slim3 + JPP
apply plugin: "java"
sourceCompatibility = 1.6
targetCompatibility = 1.6
buildDir = "target"
def slim3Version = "1.0.+"
def appengineVersion = "1.7.+"
def jppVersion = "1.5.+"
repositories {
mavenCentral()
maven {
url "https://www.seasar.org/maven/maven2"
}
}
configurations {
providedCompile // <scope>provided</scope>
aptCompile5 // 1.5
aptCompile6 // 1.6
}
sourceSets {
apt_generated
main.compileClasspath += configurations.providedCompile
test.compileClasspath += configurations.providedCompile
test.runtimeClasspath += configurations.providedCompile
}
dependencies {
compile("org.slim3:slim3:${slim3Version}") {
exclude group: "com.google.appengine", module: "appengine-api-1.0-sdk"
exclude group: "com.google.appengine", module: "appengine-api-labs"
}
compile "com.google.appengine:appengine-api-1.0-sdk:${appengineVersion}"
compile "com.google.appengine:appengine-api-labs:${appengineVersion}"
compile "net.vvakame:jsonpullparser-core:${jppVersion}"
providedCompile "javax.servlet:servlet-api:2.5"
aptCompile5("org.slim3:slim3-gen:${slim3Version}") {
exclude group: "org.apache.ant", module: "ant"
}
aptCompile6 "net.vvakame:jsonpullparser-apt:${jppVersion}"
testCompile "junit:junit:4.7"
testCompile "com.google.appengine:appengine-api-stubs:${appengineVersion}"
testCompile "com.google.appengine:appengine-testing:${appengineVersion}"
}
task clean(overwrite: true) {
ant.delete(dir: buildDir)
}
task compileAptJava(overwrite: true, dependsOn: clean) {
// 生成コードを出力するディレクトリを予め作成
// sourceSets.apt_generated.output.resourcesDir.mkdir() // なぜか出来ない
ant.mkdir(dir: sourceSets.apt_generated.output.resourcesDir)
// apt 1.5
ant.path(id: "aptFactoryPath", location: configurations.aptCompile5.asPath)
ant.apt(
compile: false,
includeAntRuntime: false,
srcdir: "src/main/java",
factorypathref: "aptFactoryPath",
classpath: configurations.compile.asPath,
preprocessdir: sourceSets.apt_generated.output.resourcesDir,
encoding: "UTF-8"
) {
sourceSets.main.java.srcDirs.each {
src(path: it)
}
}
// apt 1.6
ant.javac(
includeAntRuntime: false,
classpath: configurations.compile.asPath,
srcdir: "src/main/java",
encoding: "UTF-8"
) {
compilerarg(line: "-proc:only")
compilerarg(line: "-processorpath ${configurations.aptCompile6.asPath}")
compilerarg(line: "-s ${sourceSets.apt_generated.output.resourcesDir}")
}
// 自動生成コードが入ったディレクトリをソースディレクトリとして追加する
sourceSets.main.java.srcDirs += sourceSets.apt_generated.output.resourcesDir
}
// compileJavaタスクの前にcompileAptJavaタスクを実行させる
compileJava.dependsOn compileAptJava
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment