Gradle - yibinericxia/documents GitHub Wiki
Gradle Project
The Gradle project created by the Groovy-based Domain Specific Language (DSL) is easy to be incorporated new functionality. The project and its tasks can be defined in its build configuration script file build.gradle with build properties in gradle.properties.
The file build.gradle normally contains the following:
- plugins
- task
- wrapper
- repositories
- dependencies
- configurations
- test
A sample build.gradle is given as follows:
plugins {
id "jacoco"
id "org.sonarqube" version "2.7"
...
}
apply plugin: 'war'
apply plugin: 'spring-boot'
...
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
task addFrontEnd (dependOn: 'front-end:npmBuild') {
doLast {
delete "front-end-webapp-folder"
copy {
from "front-end-dist-folder"
into "destination-folder"
}
}
}
war {
baseName = 'app'
dependsOn 'front-end'
}
...
wrapper {
gradleVersion = '5.3.1'
}
repositories {
mavenCentral()
maven {
url = "https://your-repo-host/repo-name/releases"
credentials {
username = "$yourUsername"
password = "$yourPassword"
}
}
}
dependencies {
compile 'abc'
testCompile 'xyz'
}
test {
useJUnit()
}
Gradle Node Plugin
To install the Gradle Node Plugin to run NodeJS script in your build, you can use the following plugins DSL in the file build.gradle to download and unpack the NodeJS package into .gradle folder:
plugins {
id "com.github.node-gradle.node" version "3.1.1"
}
with the tasks to run
task runTest (type: NpmTask, dependsOn: 'npmInstall') {
args = ['run', 'test:unit']
}
task cleanDist (type: NpmTask, dependsOn: 'npmInstall') {
delete 'dist'
}
You can also use the following to configure the node version, npm version, url to download, etc
node {
version = '16.14.0'
npmVersion = '6.12.0'
distBaseUrl = 'https://nodejs.org/dist'
download = true
workDir = file("your_work_directory")
...
}