-
-
Save mike-neck/5761815 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 groovy.xml.MarkupBuilder | |
apply plugin: "java" | |
apply plugin: "war" | |
apply plugin: "eclipse" | |
// maven-publish, maven2Gradle, build-dashboard | |
// checkstyle, findbugs, jdepend, pmd | |
sourceCompatibility = 1.7 | |
targetCompatibility = 1.7 | |
task wrapper(type: Wrapper) { gradleVersion = '1.4' } | |
repositories { | |
mavenCentral() | |
maven { url "https://www.seasar.org/maven/maven2" } | |
} | |
configurations { | |
providedCompile // <scope>provided</scope> | |
aptCompile5 // 1.5 | |
aptCompile6 // 1.6 | |
} | |
sourceSets { | |
main { | |
java { srcDirs generatedSrc } | |
output.resourcesDir = "${generatedWar}/WEB-INF/classes" | |
output.classesDir = "${generatedWar}/WEB-INF/classes" | |
} | |
main.compileClasspath += configurations.providedCompile | |
test.compileClasspath += configurations.providedCompile | |
test.runtimeClasspath += configurations.providedCompile | |
} | |
dependencies { | |
compile("org.slim3:slim3:${slim3Version}") { | |
exclude module: "appengine-api-1.0-sdk" | |
exclude module: "appengine-api-labs" | |
} | |
['appengine-api-1.0-sdk', 'appengine-api-labs'].each {artifact -> | |
compile "${appeengine}:${artifact}:${appengineVersion}" | |
} | |
aptCompile5("org.slim3:slim3-gen:${slim3Version}") { | |
exclude group: "org.apache.ant", module: "ant" | |
} | |
providedCompile "javax.servlet:servlet-api:2.5" | |
testCompile "junit:junit:4.11" | |
testCompile "org.hamcrest:hamcrest-all:1.3" | |
['appengine-api-stubs', 'appengine-testing'].each {artifact -> | |
testCompile "${appeengine}:${artifact}:${appengineVersion}" | |
} | |
compile "net.vvakame:memvache:0.3.2" | |
compile "net.vvakame:jsonpullparser-core:${jppVersion}" | |
aptCompile6 "net.vvakame:jsonpullparser-apt:${jppVersion}" | |
compile "org.twitter4j:twitter4j-appengine:3.0.3" | |
} | |
task clean(overwrite: true) { | |
delete generatedSrc | |
delete testGeneratedDir | |
delete "${generatedWar}/WEB-INF/classes" | |
delete "build" | |
} | |
// ほいほい消えると開発時に困るので dependsOn は設定しない | |
task cleanAppEngine << { delete "${generatedWar}/WEB-INF/appengine-generated" } | |
task compileApt5Java(overwrite: true, dependsOn: clean) { | |
description = "Generate java code by AnnotationProcessor" | |
logging.level = LogLevel.QUIET | |
doLast { | |
file(generatedSrc).mkdir() | |
ant.path(id: "aptFactoryPath", location: configurations.aptCompile5.asPath) | |
ant.apt( | |
// srcdir: "", | |
// destdir: "", | |
classpath: configurations.compile.asPath, | |
// debug: "on", | |
compile: false, | |
// factory: "", | |
factorypathref: "aptFactoryPath", | |
preprocessdir: generatedSrc, | |
includeAntRuntime: false, | |
encoding: "UTF-8" | |
) { | |
sourceSets.main.java.srcDirs.each { src(path: it) } | |
// 何故か src/test/java でClassCastExceptionが出る | |
// sourceSets.test.java.srcDirs.each { src(path: it) } | |
} | |
// 自動生成コードが入ったディレクトリをソースディレクトリとして追加する | |
sourceSets.main.java.srcDirs += generatedSrc | |
} | |
compileJava.dependsOn compileApt5Java | |
} | |
// Pluggable Annotation ProcessorはcompileJavaで処理が可能 | |
compileJava.compileClasspath += configurations.aptCompile6 | |
compileJava.options.compilerArgs = ['-proc:only', '-processorpath', configurations.aptCompile6.asPathm, '-s', generatedSrc] | |
eclipse { | |
// sample from http://forums.gradle.org/gradle/topics/eclipse_plugin_adding_classpath_entries_remove_them | |
project { | |
name = 'gradle-sample' | |
natures 'com.google.appengine.eclipse.core.gaeNature', 'com.google.gdt.eclipse.core.webAppNature' | |
buildCommand 'com.google.gdt.eclipse.core.webAppProjectValidator' | |
buildCommand 'com.google.appengine.eclipse.core.enhancerbuilder' | |
buildCommand 'com.google.appengine.eclipse.core.projectValidator' | |
} | |
classpath { | |
defaultOutputDir = file("${generatedWar}/WEB-INF/classes") | |
containers 'org.eclipse.jdt.launching.JRE_CONTAINER', 'com.google.appengine.eclipse.core.GAE_CONTAINER' | |
downloadSources = true | |
downloadJavadoc = true | |
} | |
jdt { | |
file { | |
withProperties { | |
it['org.eclipse.jdt.core.compiler.processAnnotations'] = 'enabled' | |
} | |
} | |
} | |
} | |
task copyAptProcessorToEclipseLib(type: Copy) { | |
eclipseJdt.dependsOn copyAptProcessorToEclipseLib | |
into "eclipse.lib" | |
from configurations.aptCompile5 + configurations.aptCompile6 | |
} | |
eclipseJdt { | |
doFirst { | |
file(".factorypath").withWriter { w -> | |
def xml = new MarkupBuilder(w) | |
xml.setDoubleQuotes(true) | |
xml.factorypath { | |
[ | |
[kind: 'PLUGIN', id: 'org.eclipse.jst.ws.annotations.core' , enabled: true, runInBatchMode: false], | |
[kind: "WKSPJAR", id: "/${project.name}/eclipse.lib/slim3-gen-${slim3Version}.jar", enabled: true, runInBatchMode: false], | |
[kind: "WKSPJAR", id: "/${project.name}/eclipse.lib/jsonpullparser-apt-${jppVersion}.jar", enabled: true, runInBatchMode: false] | |
].each { | |
factorypathentry it | |
} | |
} | |
} | |
mkdir ('.settings') | |
file(".settings/org.eclipse.jdt.apt.core.prefs").text = """\ | |
|eclipse.preferences.version=1 | |
|org.eclipse.jdt.apt.aptEnabled=true | |
|org.eclipse.jdt.apt.genSrcDir=${generatedSrc} | |
|org.eclipse.jdt.apt.processorOptions/JsonPullParserClassPostfix=${jsonpullparserGenclassPostfix} | |
|org.eclipse.jdt.apt.processorOptions/JsonPullParserDebug=${jsonpullparserDebug} | |
|org.eclipse.jdt.apt.reconcileEnabled=false | |
|""".stripMargin() | |
file(".settings/com.google.gdt.eclipse.core.prefs").text = """\ | |
|eclipse.preferences.version=1 | |
|jarsExcludedFromWebInfLib= | |
|warSrcDir=${generatedWar} | |
|warSrcDirIsOutput=false | |
|""".stripMargin() | |
file(".settings/com.google.appengine.eclipse.core.prefs").text = """\ | |
|eclipse.preferences.version=1 | |
|ormEnhancementInclusions= | |
|""".stripMargin() | |
} | |
} | |
task cleanMiscEclipse { | |
cleanEclipse.dependsOn cleanMiscEclipse | |
doLast { | |
delete ".settings" | |
delete ".factorypath" | |
delete "eclipse.lib" | |
} | |
} |
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
slim3Version = "1.0.16" | |
appengineVersion = "1.7.5" | |
jppVersion = "1.6.1" | |
appeengine = "com.google.appengine" | |
generatedSrc = ".apt_generated" | |
testGeneratedDir = "www-test" | |
generatedWar = "src/main/webapp" | |
jsonpullparserGenclassPostfix = "Gen" | |
jsonpullparserDebug = true |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment