include 'core','web'
build.gradle
allprojects {
apply plugin: 'java'
group = 'org.exam'
version = '1.0'
sourceCompatibility = 1.8
targetCompatibility = 1.8
}
subprojects {
ext {
slf4jVersion = '1.7.7'
springVersion = '4.2.1.RELEASE'
hibernateVersion = '4.3.1.Final'
}
[compileJava, compileTestJava, javadoc]*.options*.encoding = 'UTF-8'
repositories {
mavenCentral()
}
configurations {
//compile.exclude module: 'commons-logging'
all*.exclude module: 'commons-logging'
}
dependencies {
compile(
"org.slf4j:jcl-over-slf4j:${slf4jVersion}",
"org.slf4j:slf4j-log4j12:${slf4jVersion}",
"org.springframework:spring-context:$springVersion",
"org.springframework:spring-orm:$springVersion",
"org.springframework:spring-tx:$springVersion",
"org.springframework.data:spring-data-jpa:1.5.2.RELEASE",
"org.hibernate:hibernate-entitymanager:$hibernateVersion",
"c3p0:c3p0:0.9.1.2",
"mysql:mysql-connector-java:5.1.26",
"commons-fileupload:commons-fileupload:1.3.1",
"com.fasterxml.jackson.core:jackson-databind:2.3.1"
)
testCompile(
"org.springframework:spring-test:$springVersion",
"junit:junit:4.11"
)
}
}
project(':core') {
}
project(':web') {
apply plugin: "war"
dependencies {
compile project(":core")
compile(
"org.springframework:spring-webmvc:$springVersion",
"org.apache.taglibs:taglibs-standard-impl:1.2.1"
)
providedCompile(
"javax.servlet:javax.servlet-api:3.1.0",
"javax.servlet.jsp:jsp-api:2.2.1-b03",
"javax.servlet.jsp.jstl:javax.servlet.jsp.jstl-api:1.2.1"
)
}
processResources{
/* 从'$projectDir/src/main/product'目录下复制文件到'WEB-INF/classes'目录下覆盖原有同名文件*/
from("$projectDir/src/main/product")
}
/*自定义任务用于将当前子项目的java类打成jar包,此jar包不包含resources下的文件*/
def jarArchiveName="${project.name}-${version}.jar"
task jarWithoutResources(type: Jar) {
from sourceSets.main.output.classesDir
archiveName jarArchiveName
}
/*重写war任务:*/
war {
dependsOn jarWithoutResources
/* classpath排除sourceSets.main.output.classesDir目录,加入jarWithoutResources打出来的jar包 */
classpath = classpath.minus(files(sourceSets.main.output.classesDir)).plus(files("$buildDir/$libsDirName/$jarArchiveName"))
}
/*打印编译运行类路径*/
task jarPath << {
println configurations.compile.asPath
}
}
/*从子项目拷贝War任务生成的压缩包到根项目的build/explodedDist目录*/
task explodedDist(type: Copy) {
into "$buildDir/explodedDist"
subprojects {
from tasks.withType(War)
}
}