mvn --version
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.
Important
|
Maven is a Java tool, so you must have Java installed in order to proceed. |
-
First, download Maven and follow the installation instructions and verify your installation
-
Invoke the maven quickstart archetype to generate your new project.
mvn archetype:generate -DgroupId=com.mycompany.app -DartifactId=my-app -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false
-
Start VS Code with the new project
code ./my-app
-
At this point your project can be edited with VS Code and you should be getting Java language features such as code assist.
Running tests
The maven quickstart archetype also generates an example test, let’s setup your VS Code to run these tests.
-
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.
Figure 2. Maven task template -
You should now have a
tasks.json
file with following content.tasks.json{ "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 } ] }
-
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.
Note
|
Default template for maven invokes |