Builds Gradle applications.
The gradle build by default caches the downloaded version of the gradle wrapper and dependencies in the cache location of
the PVC by setting the environment variable GRADLE_USER_HOME
to /workspace/source/.ods-cache/deps/gradle
.
The following steps are executed:
-
build gradle application, using
gradlew clean build
, which includes tests execution and coverage report generation
Notes:
-
tests exclude the vendor directory.
-
test results are converted into xUnit format.
Available environment variables:
-
ODS_OUTPUT_DIR
: this environment variable points to the folder that this build expects generated application artifacts to be copied to. The gradle script should read it and copy there the generated artifacts. -
NEXUS_*
env vars:NEXUS_URL
,NEXUS_USERNAME
andNEXUS_PASSWORD
are available and should be read by the gradle script. To enable the gradle script to copy the generated application artifacts script follow these steps: -
read the environment variable
ODS_OUTPUT_DIR
in the buildscript section of the gradle script:
buildscript {
ext {
outputDir = System.getenv('ODS_OUTPUT_DIR')
}
}
-
customize the jar tasks to set the destination directory
jar {
println("Set application jar name to 'app'")
archiveBaseName = 'app'
if (outputDir != null) {
println("Set destinationDirectory to '${projectDir}/${outputDir}'")
destinationDirectory = file("${projectDir}/${outputDir}")
}
}
To create a coverage report be sure that you add to gradle.properties
the required
configuration. For example to enable Jacoco coverage repot you will need to:
-
add
jacoco
plugin:
plugins {
id 'application'
id 'jacoco'
}
-
add task
jacocoTestReport
:
jacocoTestReport {
reports {
xml.required = true
}
}
-
add
finalizedBy jacocoTestReport
to the tasktest
:
tasks.named('test') {
useJUnitPlatform()
finalizedBy jacocoTestReport
}
The exact build recipe can be found at build/package/scripts/build-gradle.sh.
The following artifacts are generated by the build task and placed into .ods/artifacts/
-
code-coverage/
-
coverage.xml
-
-
xunit-reports/
-
report.xml
Instead of the built-in script, one can also specify a build script located in the Git repository using thebuild-script
task parameter. This allows full control of building and testing, including any generation of artifacts. Note that some other task parameters have no effect when a custom build script is used, unless they are handled properly in the script. At a minimum, the custom script should place its outputs in the directory identified byoutput-dir
.
-
Parameter | Default | Description |
---|---|---|
working-dir |
. |
Working directory. The path must be relative to the root of the repository,
without leading |
gradle-additional-tasks |
Additional gradle tasks to be passed to the gradle build. (default tasks called are |
|
gradle-options |
--no-daemon --stacktrace |
Options to be passed to the gradle build. (See ref: https://docs.gradle.org/7.4.2/userguide/command_line_interface.html#sec:command_line_debugging) |
gradle-opts-env |
-Dorg.gradle.jvmargs=-Xmx512M |
Will be exposed to the build via |
output-dir |
docker |
Path to the directory into which the resulting Java application jar should be copied, relative to |
cache-build |
true |
If enabled tasks uses or populates cache with the output dir contents (and artifacts) so that a build can be skipped if the |
build-extra-inputs |
List of build source directories (as colon separated string) which in addition working-dir influence the build. These directories are relative to the repository root. If the contents in these directories change the cache is invalidated so that the build task will rebuild from scratch. |
|
cached-outputs |
docker |
List of build output directories (as colon separated string) to be cached. These directories are relative to |
build-script |
/usr/local/bin/build-gradle |
Build script to execute. The default script is located in the container image. If you specify a relative path instead, it will be resolved from the workspace. See the task definition for details how the build script is invoked. |
gradle-build-dir |
build |
Path to the directory into which Gradle publishes its build. |