Build Maven project
build-maven.yml builds and tests any Maven project on one or more Java versions, stages JaCoCo coverage for
Upload coverage, and deploys SNAPSHOT artifacts after a push to a release branch. It makes no
assumptions about OpenMRS modules; for a module with an omod, use Build backend module.
Usage
name: Build with Maven
on:
push:
branches: [main]
pull_request:
jobs:
build:
uses: openmrs/openmrs-contrib-gha-workflows/.github/workflows/build-maven.yml@main
secrets:
MAVEN_REPO_USERNAME: ${{ secrets.MAVEN_REPO_USERNAME }}
MAVEN_REPO_API_KEY: ${{ secrets.MAVEN_REPO_API_KEY }}What it does
- Prepare: runs
mvn help:effective-pomand infers the Java versions, the SNAPSHOT server ID and repository URL, and the project version. Decides whether a SNAPSHOT deploy is allowed (see SNAPSHOT deploys). - Build: runs
mvn --batch-mode <maven_args> -Dmaven.deploy.skiponce per Java version, in parallel. On the main Java version, anyjacoco.xmlreports are staged as acoverage-reportsartifact unlessupload_coverageis"false". - Deploy: after every build passes, runs
mvn deploy -DskipTestson the main Java version, if the deploy rules allow it.
Java versions
| Setting | Inferred from | Fallback |
|---|---|---|
java_versions | The OpenMRS platform version, if the project depends on openmrs-api or openmrs-web (see Build backend module) | [main_java_version] |
main_java_version | The lowest of the inferred java_versions; without a platform version, the Maven compiler settings (maven.compiler.release, maven.compiler.target, or the compiler plugin’s release / target) | none; the build fails |
main_java_version is the version that stages coverage and deploys. It must be one of java_versions. Pass
java_versions as a JSON array, e.g. '[11, 17]', to build on more than one version.
SNAPSHOT deploys
The deploy job runs only when all of these hold:
deploy_snapshotsistrue(the default in theopenmrsorg; elsewhere it defaults tofalse).- The POM version ends in
-SNAPSHOT. - The run is a push, not a pull request.
- The branch is a deploy branch:
main,master, the repository’s default branch, or a version branch such as3.xor2.8.xwhose prefix matches the POM version. Setdeploy_branchto a branch name or JSON array to override.
The target is maven_snapshot_repository_url if set, otherwise <distributionManagement><snapshotRepository> from the
effective POM or, as in Maven, its <repository> when there is no snapshotRepository. The server ID, which selects
the credentials, is maven_server_id if set, otherwise the ID of that repository, otherwise openmrs-repo-snapshots.
A deploy fails with an explanation when there is no target repository, when the target is reserved for OpenMRS (see
Outside OpenMRS), or when MAVEN_REPO_USERNAME or MAVEN_REPO_API_KEY is missing. central-publishing-maven-plugin in the POM’s build counts as a target; in a profile
it does not, because the deploy activates no profiles. Set deploy_snapshots: false to build without deploying.
OpenMRS defaults
OpenMRS repositories pass the MAVEN_REPO_USERNAME and MAVEN_REPO_API_KEY org secrets and inherit their deploy
repositories from the OpenMRS parent POM, so no inputs are usually needed. Name the calling workflow Build with Maven
if you use Upload coverage, whose stub refers to it by name.
Outside OpenMRS
Outside the openmrs GitHub org, deploy_snapshots defaults to false, so a fork that inherits a caller workflow
builds without deploying. Turn it on from the repository owner, so that forks of your repository do not deploy either:
with:
deploy_snapshots: ${{ github.repository_owner == 'my-org' }}Once it is on, deploys to repositories OpenMRS owns fail:
- any URL on
mavenrepo.openmrs.org; openmrs.jfrog.io/artifactory/undermodules,snapshotsorreleases(other repositories on that host, such asmodules-pih, are allowed);- Maven Central (any
maven.org,maven.apache.org,sonatype.comorsonatype.orghost, or a build usingcentral-publishing-maven-pluginoutside an inactive profile), when a module’s groupId isorg.openmrsor starts withorg.openmrs..
This usually means a fork inherited those repositories from the OpenMRS parent POM. Point
<distributionManagement> or maven_snapshot_repository_url at your own repository, or set
deploy_snapshots: false.
If your secrets have different names, map them in the caller. secrets: inherit passes secrets through under their
own names and does not rename them:
secrets:
MAVEN_REPO_USERNAME: ${{ secrets.MY_MAVEN_USER }}
MAVEN_REPO_API_KEY: ${{ secrets.MY_MAVEN_TOKEN }}Permissions
The build and deploy jobs request contents: read only.
Inputs
| Name | Type | Default | Description |
|---|---|---|---|
java_versions | string | Java versions to build against (e.g. [8, 11, 17]). If omitted, defaults to the Java version inferred from the Maven compiler settings in pom.xml. | |
main_java_version | string | Java version for publishing artifacts (must be in java_versions). If omitted, inferred from Maven compiler settings. | |
java_distribution | string | temurin | Java distribution |
maven_args | string | clean install | Maven Arguments |
upload_coverage | string | Stage JaCoCo reports as a coverage-reports artifact for the upload-coverage workflow to send to Codecov. Set "false" to skip; otherwise staged when JaCoCo reports are found. | |
deploy_snapshots | boolean | ${{ github.repository_owner == 'openmrs' }} | Whether to deploy SNAPSHOT artifacts to the Maven repository. Defaults to true in the openmrs org and false elsewhere, so forks that inherit a caller workflow do not deploy; outside the openmrs org, set it from an expression such as github.repository_owner == 'my-org'. When true, a deploy without MAVEN_REPO_USERNAME and MAVEN_REPO_API_KEY fails, as does a deploy to a repository only the openmrs org may use. |
deploy_branch | string | Branch name or JSON array of branch names that trigger SNAPSHOT deployment. If omitted, deploys from main, master, the default branch, and version branches (e.g. 3.x, 2.8.x). | |
maven_server_id | string | Maven server ID to use for SNAPSHOT deployment. If omitted, inferred from <distributionManagement><snapshotRepository><id> in pom.xml. | |
maven_snapshot_repository_url | string | Repository URL to deploy SNAPSHOTs to instead of <distributionManagement><snapshotRepository>. |
Secrets
| Name | Description |
|---|---|
MAVEN_REPO_USERNAME | Maven repository username |
MAVEN_REPO_API_KEY | Maven repository API key / password |