Multi module Projects - bahkified/Notes GitHub Wiki
Take the following project with two modules:
project
| -- server
\ -- persistence
|
| build.gradle
| settings.gradle
This project contains a single build script at the project root directory. The file settings.gradle
defines the modules to include in the project and the file build.gradle
defines the build script, which contains settings for the whole project, as well as settings for the individual modules.
##Files settings.gradle
include 'persistence', 'server'
build.gradle
def springVersion = '4.0.4.RELEASE'
defaultTasks 'clean', ':server:war'
subprojects {
apply plugin: 'java'
sourceCompatibility = 1.8
repositories {
mavenCentral()
}
dependencies {
compile group: 'org.projectlombok', name: 'lombok', version: '1.12.6'
// Spring dependencies
compile group: 'org.springframework', name: 'spring-core', version: springVersion
compile group: 'org.springframework', name: 'spring-context', version: springVersion
compile group: 'org.springframework', name: 'spring-context-support', version: springVersion
// Logging dependencies
compile group: 'org.slf4j', name: 'slf4j-api', version: '1.7.7'
compile group: 'ch.qos.logback', name: 'logback-classic', version: '1.1.2'
// Testing dependecies
testCompile group: 'org.springframework', name: 'spring-test', version: springVersion
testCompile group: 'org.mockito', name: 'mockito-all', version: '1.9.5'
testCompile group: 'junit', name: 'junit', version: '4.11'
}
}
project(':persistence') {
version = '0.1.0-SNAPSHOT'
dependencies {
// DB dependencies
compile group: 'org.springframework.data', name: 'spring-data-jpa', version: '1.6.0.RELEASE'
compile group: 'org.hibernate.javax.persistence', name: 'hibernate-jpa-2.0-api', version: '1.0.1.Final'
compile group: 'org.hibernate', name: 'hibernate-entitymanager', version: '4.3.5.Final'
testCompile group: 'com.h2database', name: 'h2', version: '1.4.178'
}
}
project(':server') {
apply plugin: 'war'
version = '0.1.0-SNAPSHOT'
dependencies {
compile project(':persistence')
providedCompile group: 'javax.servlet', name:'servlet-api', version: '2.5'
compile group: 'javax.servlet', name: 'jstl', version: '1.2'
// JSON-LD java integration dependencies
compile group: 'com.github.jsonld-java', name: 'jsonld-java', version: '0.4.1'
compile group: 'org.springframework', name: 'spring-webmvc', version: springVersion
}
}
This build script contains settings shared by both modules, such as shared external dependencies and the code repositories. It also contains settings specific to each module, including a dependency of the server
module on the persistence
module.
##Resources