Fundamental interface for defining a build
matlab.buildtool.Plan class is the fundamental interface used to group
a set of tasks and define a build.
Plan object behaves like a dictionary of tasks, where keys are task names
and values are
Task objects. To add
a task to the plan, modify a task in the plan, or return a copy of a specific task in the
plan, index into the
Plan object by using the task name.
To add a
t, use the
taskName") = t
"must be a valid MATLAB® identifier and must not be used by any of the existing tasks in the plan.
To modify a
Taskobject, use the
can be any publicly writable property of a
To return a copy of a
Taskobject, use the
t = plan("syntax. Modifying the returned task does not affect the original task in the plan.
For information on class attributes, see Class Attributes.
To create a
Plan object, use the
DefaultTasks — Names of default tasks
string vector | character vector | cell vector of character vectors
Names of the default tasks, specified as a string vector, character vector, or cell vector of character vectors, and returned as a string row vector. When no tasks are specified for a build run, the build runner runs these default tasks.
Tasks — Tasks in plan
row vector of
Tasks in the plan, returned as a row vector of
RootFolder — Full path to folder containing the build file
Full path to the folder containing the build file that created the plan, returned as a string scalar. If the plan was created in the Command Window, the property includes the full path to the current folder when the plan was created.
Add Tasks to Plan
Create tasks and add them to a build plan. Then, run the build.
Create a plan with no tasks.
plan = buildplan;
Add a task named
"check" to the plan. This code adds a task that has no description, dependencies, or actions.
plan("check") = Task;
Specify the description and actions of the
"check" task by setting its properties. The task identifies code issues in the current folder and its subfolders and fails the build if any issues are found.
plan("check").Description = "Identify code issues"; plan("check").Actions = @check;
Add a task to the plan that runs the tests in the current folder and its subfolders and fails the build if any of the tests fail. Specify the task description and actions during creation of the task.
plan("test") = Task( ... Description="Run unit tests", ... Actions=@test);
Add another task that creates an archive of the current folder for sharing. Make the task dependent on the
plan("archive") = Task( ... Description="Create archive for sharing", ... Dependencies=["check" "test"], ... Actions=@archive);
Now, make the
"archive" task the default task in the plan.
plan.DefaultTasks = "archive";
Run the default task. The build tool runs the
"archive" task as well as both the tasks on which it depends. In this example, the tasks run successfully.
result = run(plan);
** Starting check ** Finished check ** Starting test ... ** Finished test ** Starting archive ** Finished archive
This section contains the local functions used to define different task actions.
function check(~) issues = codeIssues; assert(isempty(issues.Issues),formattedDisplayText(issues.Issues)) end function test(~) results = runtests(IncludeSubfolders=true,OutputDetail="terse"); assertSuccess(results); end function archive(~) zipFileName = "source_" + ... string(datetime("now",Format="yyyyMMdd'T'HHmmss")); zip(zipFileName,"*") end
Introduced in R2022b