'VScode tasks.json reuse tasks instead of copy/paste possible?

I find myself copy/pasting quite a bit in tasks.json. Is there a better way to deal with this? Googled for parameterizing tasks, but that doesn't seem possible.

In my tasks json I have a bunch of tasks to clean/build/rebuild one project

    //
    // bootloader tasks
    //

    {
        "label": "bootloader - clean",
        "type": "shell",
        "command": "rm -rf bootloader-imx-rt-1024/build",
        "windows":{
            "command": "cmd",
            "args": ["/C", "if exist bootloader-imx-rt-1024\\build rmdir bootloader-imx-rt-1024\\build /s /q"]
        },
        "group": {
            "kind": "build",
            "isDefault": true
        }
    },
    {
        "label": "bootloader - create folder",
        "type": "shell",
        "command": "mkdir bootloader-imx-rt-1024/build",
        "windows":{
            "command": "cmd",
            "args": ["/C", "if not exist .\\bootloader-imx-rt-1024\\build mkdir .\\bootloader-imx-rt-1024\\build"]
        },
        "dependsOrder": "sequence",
        "dependsOn": [
        ],
        "group": {
            "kind": "build",
            "isDefault": false
        }
    },
    {
        "label": "bootloader - cmake",
        "type": "shell",
        "command": "cd bootloader-imx-rt-1024/build; cmake -G 'Eclipse CDT4 - Unix Makefiles' -D_ECLIPSE_VERSION=4.2 ../source",
        "windows":{
            "command": "cd bootloader-imx-rt-1024/build; cmake -G 'Eclipse CDT4 - MinGW Makefiles' -D_ECLIPSE_VERSION=4.2 ../source"
        },
        "dependsOrder": "sequence",
        "dependsOn": [
            "bootloader - create folder",
        ],
        "group": {
            "kind": "build",
            "isDefault": true
        }
    },
    {
        "label": "bootloader - build",
        "type": "shell",
        "command": "cd bootloader-imx-rt-1024/build; cmake --build . -- -j12 -Oline --no-print-directory",
        "dependsOn": [
            "bootloader - create folder",
            "cmake"
        ],
        "group": {
            "kind": "build",
            "isDefault": true
        }
    }, 
    {
        "label": "bootloader - rebuild",
        "type": "shell",
        "command": "cd bootloader-imx-rt-1024/build; cmake --build . -- -j12 -Oline --no-print-directory",
        "dependsOn": [
            "bootloader - clean",
            "bootloader - cmake"
        ],
        "group": {
            "kind": "build",
            "isDefault": true
        }
    }, 

Then I have a couple of other projects, which do almost the exact same thing

    //
    // iobox tasks
    //

    {
        "label": "iobox - clean",
        "type": "shell",
        "command": "rm -rf iobox-imx-rt-1024/build",
        "windows":{
            "command": "cmd",
            "args": ["/C", "if exist iobox-imx-rt-1024\\build rmdir iobox-imx-rt-1024\\build /s /q"]
        },
        "group": {
            "kind": "build",
            "isDefault": true
        }
    },
    {
        "label": "iobox - create folder",
        "type": "shell",
        "command": "mkdir iobox-imx-rt-1024/build",
        "windows":{
            "command": "cmd",
            "args": ["/C", "if not exist .\\iobox-imx-rt-1024\\build mkdir .\\iobox-imx-rt-1024\\build"]
        },
        "dependsOrder": "sequence",
        "dependsOn": [
        ],
        "group": {
            "kind": "build",
            "isDefault": false
        }
    },
    {
        "label": "iobox - cmake",
        "type": "shell",
        "command": "cd iobox-imx-rt-1024/build; cmake -G 'Eclipse CDT4 - Unix Makefiles' -D_ECLIPSE_VERSION=4.2 ../source",
        "windows":{
            "command": "cd iobox-imx-rt-1024/build; cmake -G 'Eclipse CDT4 - MinGW Makefiles' -D_ECLIPSE_VERSION=4.2 ../source"
        },
        "dependsOrder": "sequence",
        "dependsOn": [
            "iobox - create folder",
        ],
        "group": {
            "kind": "build",
            "isDefault": true
        }
    },
    {
        "label": "iobox - build",
        "type": "shell",
        "command": "cd iobox-imx-rt-1024/build; cmake --build . -- -j12 -Oline --no-print-directory",
        "dependsOn": [
            "iobox - create folder",
            "cmake"
        ],
        "group": {
            "kind": "build",
            "isDefault": true
        }
    }, 
    {
        "label": "iobox - rebuild",
        "type": "shell",
        "command": "cd iobox-imx-rt-1024/build; cmake --build . -- -j12 -Oline --no-print-directory",
        "dependsOn": [
            "iobox - clean",
            "iobox - cmake"
        ],
        "group": {
            "kind": "build",
            "isDefault": true
        }
    },   

Is there a way to "parameterize" / "template" tasks so that I can get rid of the duplication?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source