Creating Your Project with Maven

Java extension can use information contained on Maven build artifacts to extract information such as the location of source files, dependencies and compiler preferences. Most convenient way to start developing a Java project using VS Code and Maven is to create a project using maven archetypes.

Maven is a Java tool, so you must have Java installed in order to proceed.
  1. First, download Maven and follow the installation instructions and verify your installation

        mvn --version
  2. Invoke the maven quickstart archetype to generate your new project.

        mvn archetype:generate
  3. Start VS Code with the new project

        code ./my-app
  4. At this point your project can be edited with VS Code and you should be getting Java language features such as code assist.

java maven.png
Figure 1. Maven quickstart on VS Code

Running tests

The maven quickstart archetype also generates an example test, let’s setup your VS Code to run these tests.

  1. In the Command Palette, filter on 'task' and select the Tasks: Configure Task Runner command. You will see a list of task runner templates, select maven to create maven based test task.

    maven task.png
    Figure 2. Maven task template
  2. You should now have a tasks.json file with following content.

        "version": "0.1.0",
        "command": "mvn",
        "isShellCommand": true,
        "showOutput": "always",
        "suppressTaskName": true,
        "tasks": [
                "taskName": "verify",
                "args": ["-B", "verify"],
                "isBuildCommand": true
                "taskName": "test",
                "args": ["-B", "test"],
                "isTestCommand": true
  3. Using Command Palette, filter on 'task' and select the Tasks: Run Test Task command. The OUTPUT panel will open and you’ll see the results of test execution.

Building your project

Create a tasks.json file by following steps 1 and 2. Invoke the build task by Tasks: Run Build Task or its shortcut.


Default template for maven invokes verify target for build tasks, which includes running of your tests.

results matching ""

    No results matching ""