In the past, I have not been faced with gradle so far. I mainly used maven as this is still much more widely used in projects. Still, I wanted to get to know Gradle better and therefore I set-up a multi-module project based on Spring Boot and Ionic. In the following I will briefly explain the steps.
The project consists of the parent-project that inlcudes one module for the backend and the other for the frontend. Bascially, it looks as follows:
parent_project
build.gradle
settings.gradle
backend
--> backend.gradle
frontend
--> frontend.gradle
The settings.gradle file in the parent-project basically defines the two modules frontend and backend. Since the gradle files in the two modules do not use the default name (build.gradle), but are named after the module name, the build file names need to be configured.
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
include 'backend' | |
include 'frontend' | |
rootProject.children.each { | |
it.buildFileName = it.name + '.gradle' | |
} |
The build.gradle defines configrations which are valid for all projects or subprojects. It looks as follows:
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
allprojects { | |
buildscript { | |
repositories { | |
mavenCentral() | |
} | |
} | |
repositories { | |
mavenCentral() | |
} | |
} |
The frontend.gradle file defines a plugin that allows to execute npm builds. This plugin is needed as the Ionic build is based on npm.
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
plugins { | |
id "com.moowork.node" version "1.2.0" | |
} | |
//node { | |
// version = '6.9.4' | |
// download = true | |
//} | |
task clean(dependsOn: 'npm_run_clean') { | |
} | |
task build(dependsOn: 'npm_run_build') { | |
} |
The backend.gradle defines the jar task that copies the distribution artifacts in the www folder of the frontend module to the public folder in the build resources of the backend module.
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
plugins { | |
id 'org.springframework.boot' version '1.5.8.RELEASE' | |
} | |
bootRepackage { | |
mainClass = 'ch.renewinkler.mobile_track.MobileTrackApplication' | |
} | |
apply plugin: 'java' | |
group = 'ch.renewinkler' | |
version = '0.0.1-SNAPSHOT' | |
sourceCompatibility = 1.8 | |
jar { | |
dependsOn(':frontend:build') | |
into('public') { | |
from "${project(':frontend').projectDir}/www" | |
} | |
} | |
dependencies { | |
compile('org.springframework.boot:spring-boot-starter-web') | |
testCompile('org.springframework.boot:spring-boot-starter-test') | |
} | |