This page assumes you have created some goals. It shows how to:
- group goals
- set dependencies between goals
- choose which goals to execute on each push
- prevent the SDM from setting goals on a push
You can group goals into sets. Start creating a goal set with the
goals method; give it a name. Add goals to the set
const BaseGoals = goals("checks") .plan(codeInspection) .plan(autofix);
plan method accepts one or more goals. The code below is equivalent to the code above:
const BaseGoals = goals("checks") .plan(codeInspection, autofix);
By default, all goals execute in parallel. If some goals should wait for others to succeed, you can give them preconditions as you add them to a plan. To do this, call the
after method immediately after
The following example constructs a goal set called “build” with three goals:
mavenBuild goal will execute only after
autofix completes successfully.
const BuildGoals = goals("build") .plan(autofix, codeInspection) .plan(mavenBuild) .after(autofix);
Note that the
after method affects only the goals in the last call to
plan. Here, the
mavenBuild goal gets
a precondition that the
autofix goal must complete successfully.
The goals listed in
after can be part of this goal set, but they don’t have to be. They could be in another
goal set that is also added to the push. If the goal in
after is not attached to a particular push at all, then the
precondition is ignored. See the next section for how to attach goal sets to a push.
Set goals on push with “push rules”
Finally, you can tell the SDM which goals to run on each push. Here, we set the
BaseGoals (inspection and autofix) on every push. Then if this is a Maven project (identified by having a
pom.xml), we do the build as well.
sdm.withPushRules( onAnyPush().setGoals(BaseGoals), whenPushSatisfies(IsMaven).setGoals(BuildGoals), );
The rules are evaluated in order. The resulting goals are combined and de-duplicated to determine the goals that will be set on the push.
The rules themselves are written in a simple internal DSL that aims to be human readable.
onAnyPush() function will return true on all pushes.
whenPushSatisfies function is used to combine other rules. For example, we could limit building to Java projects,
rather than all Maven projects, as follows:
The DSL includes support for logical operations. For example, this will build all Maven projects except Kotlin projects:
Each argument to
is a PushRule, contributing goals on a commit if a condition is met. That condition is a PushTest.
Push tests are functions that look at the content of a push and decide whether this goal applies.
Here’s a quick example of a push test:
export const IsMaven: PredicatePushTest = predicatePushTest( "Is Maven", p => p.hasFile("pom.xml"));
To establish a PushTest for whether a project uses Maven as a build tool,
calls a constructor function
with a name for the PushTest and a function from a Project to a
The example spring-sdm uses this PushTest to create a PushRule, which sets build goals only on Maven projects:
Stop setting goals
Sometimes we want to stop setting goals after a particular rule evaluates to true.
For example, we can modify the earlier example to do nothing at all if the project has a
leaveMeAlone file in the root directory:
sdm.withPushRules( whenPushSatisfies(async pu => pu.project.hasFile("leaveMeAlone")).setGoals(goals("none").andLock()), onAnyPush().setGoals(BaseGoals), whenPushSatisfies(IsMaven).setGoals(BuildGoals), );
andLock method on the
Goals class causes further goal evaluation to be ignored.