Main Content

matlab.buildtool.Plan class

Package: matlab.buildtool

Fundamental interface for defining a build

Since R2022b


The matlab.buildtool.Plan class is the fundamental interface used to group a set of tasks and define a build.

A 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 Task object t, use the plan("taskName") = t syntax. "taskName" must be a valid MATLAB® identifier and must not be used by any of the existing tasks in the plan.

  • To modify a Task object, use the plan("taskName").TaskProp = value syntax. TaskProp can be any publicly writable property of a Task object.

  • To return a copy of a Task object, use the t = plan("taskName") syntax. Modifying the returned task does not affect the original task in the plan.

Class Attributes


For information on class attributes, see Class Attributes.


To create a Plan object, use the buildplan function.


expand all

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.

Example: "compile"

Example: ["compile" "test"]



Tasks in the plan, returned as a row vector of matlab.buildtool.Task objects.



Absolute 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 absolute path to the current folder when the plan was created.

Example: "C:\work\buildfile.m"




expand all


collapse all

Create tasks and add them to a build plan. Then, run the build.

Import the classes used in this example.

import matlab.buildtool.Task
import matlab.buildtool.tasks.CodeIssuesTask
import matlab.buildtool.tasks.TestTask

Create a plan with no tasks.

plan = buildplan;

Create a task named "check" that identifies code issues in the current folder and its subfolders and fails the build if any errors are found. To create the task, use the CodeIssuesTask built-in class.

plan("check") = CodeIssuesTask;

Create a task named "test" that runs the tests in the current folder and its subfolders and fails the build if any of the tests fail. To create the task, use the TestTask built-in class.

plan("test") = TestTask;

Add another task to the plan that creates an archive of the current folder. Make the task dependent on the "check" and "test" tasks.

plan("archive") = Task( ...
    Description="Create ZIP file", ...
    Dependencies=["check" "test"], ...

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
Analysis Summary:
    Total Files: 3
         Errors: 0 (Threshold: 0)
       Warnings: 0 (Threshold: Inf)
** Finished check

** Starting test

Test Summary:
    Total Tests: 3
         Passed: 3
         Failed: 0
     Incomplete: 0
       Duration: 0.24699 seconds testing time.
** Finished test

** Starting archive
** Finished archive

Local Function

This code shows the local function used in this example.

function archive(~)
filename = "source_" + ...

Version History

Introduced in R2022b

expand all