Skip to content

Latest commit

 

History

History
161 lines (117 loc) · 5.65 KB

build.adoc

File metadata and controls

161 lines (117 loc) · 5.65 KB

ods-pipeline-gradle-build

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 and NEXUS_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 task test:

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 the build-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 by output-dir.

Parameters

Parameter Default Description

working-dir

.

Working directory. The path must be relative to the root of the repository, without leading ./ and trailing /.

gradle-additional-tasks

Additional gradle tasks to be passed to the gradle build. (default tasks called are clean and build).

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 GRADLE_OPTS environment variable. Specifies JVM arguments to use when starting the Gradle client VM. The client VM only handles command line input/output, so it is rare that one would need to change its VM options. You can still use this to change the settings for the Gradle daemon which runs the actual build by setting the according Gradle properties by -D. If you want to set the JVM arguments for the actual build you would do this via -Dorg.gradle.jvmargs=-Xmx1024M (See ref: https://docs.gradle.org/7.4.2/userguide/build_environment.html#sec:gradle_configuration_properties).

output-dir

docker

Path to the directory into which the resulting Java application jar should be copied, relative to working-dir. This directory may then later be used as Docker context for example.

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 working-dir contents did not change. You must set this to "false" if the build can be affected by files outside working-dir. See ADR caching-build-tasks for more details and workarounds.

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 working-dir.

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.

Results

Name Description

build-reused-from-location

The cache location that the build task used. If caching is not enabled this will be an empty string.