Visual Studio Code Maven



  1. Visual Studio Code Maven Build
  2. Visual Studio Code Maven Settings
  3. Visual Studio Code Maven Java
  4. Visual Studio Code Maven Settings.xml
  5. Visual Studio Code Maven Setup

Install Visual Studio Code. Install visual studio code is very easy, just go to the visual studio code. Apache Maven and Visual Studio Code are primarily classified as 'Java Build'and 'Text Editor'tools respectively.

Creating a Java Project Maven Visual Studio Code for Java 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. Visual Studio Code for Java; Introduction Getting Started Creating a Java Project Maven Importing Maven Projects Importing Eclipse Projects Linked Mode Powered by GitBook. Importing Maven Projects. Results matching ' No results matching '.

Home / Maven Package Management with Visual Studio Team Services

In this exercise, you are going to set up package management with Maven in VSTS. This repo contains a class library (MyShuttleCalc) that is used by the MyShuttle2 application. You will configure a VSTS build to publish the MyShuttleCalc package to a VSTS Maven Package feed so that it can be consumed by MyShuttle2 and any other applications that require the calculation code.

Vs code extensionsVisual studio code maven pluginMaven

This exercise assumes you have completed the exercises to create a Team Project, have set up the Docker private VSTS agent, and imported the MyShuttleCalc and MyShuttle2 GitHub repos into your VSTS team project. This exercise also assumes that you have cloned the repos in either IntelliJ or Eclipse. This exercise uses a team project named jdev-labs, though your team project name may differ.

Note: This exercise shows how to do a Maven build using VSTS. To see how to perform a Maven build using Jenkins that still integrates into the VSTS Package Feed, please refer to the Maven Package Management with Jenkins lab

Create a Maven Package Feed

In this task you will create a Maven package feed. You will publish packages to this feed as well as consume packages from this feed.

  1. In VSTS, click on Build & Release and then Packages to navigate to the Package Hub. Click + New Feed to create a new feed.

  2. Enter Maven for the feed name and click Create.

    You now have a feed that you can publish package to.

Create a Maven Settings File with the Feed Credentials

In this task you will create credentials for the Maven feed. You will then create a settings.xml file containing the credentials.

  1. In the Packages Hub, make sure you have selected the Maven feed and click Connect to Feed.

  2. In the left menu, click on Maven.

    Note: At the time of writing, Maven package feeds was a preview feature. You will need to enable the Maven package feed feature in order to connect to Package Management to/from Maven.
  3. Click Generate Maven Credentials.

  4. VSTS creates a credentials snippet. Click Copy to Clipboard to copy the snippet to the clipboard.

  5. In your editor, open the MyShuttleCalcmavensettings.xml.

  6. Delete the comment <!-- paste maven package feed credentials section here !--> and replace it with the snippet text between the tags <servers> and </servers> so that the final result looks like this:

  7. Press Ctrl-S (or File -> Save) to save the file.

  8. In VSTS, go back to the Connect to Feed dialog on your Maven feed. Click copy in the section labeled Add this feed to your project pom.xml inside the <repositories> tag.

  9. In your editor, open the pom.xml file. Update the <repositories> tag as well as the <distributionManagement> tag so that they now point to your feed.

  10. Commit your changes to the repo.

    Note: If this is your first commit to VSTS, you will be prompted to update your display name and email address for the repo. These are only for display purposes but are usually matched to your VSTS profile.

IntelliJ

  1. Click VCS -> Commit Changes to commit your changes to the repo.
  • Enter Adding maven credentials for the commit message.

  • Click the drop-down next to Commit and select Commit and Push.

Code

Eclipse

Note: Use the personal access token (PAT)generated from the Set up a Docker Build lab that should be located at: home/vmadmin/pat.txt. Otherwise, follow the instructions from that lab again to generate a new PAT.
  • In Eclipse, right click on the project or the pom.xml file and select Team -> Commit.

  • Enter Adding maven credentials for the commit message and click Commit and Push.

  • Verify that the remote location is accurate and click Next.

  • If a window prompts for credentials, use the following values:

    NameValue
    User_VSTS_Code_Access_Token
    Password{PAT that you copied earlier}
  1. Important: Copy the maven settings file to the .m2 directory so that local Maven operations will succeed by running the following command in a terminal:

  2. Important: If you have the MyShuttle2 project already open in IntelliJ or Eclipse, close the instance of the IDE and reopen it.

Creating a VSTS Build for Publishing a Maven Package

In this task you will create a build that will publish the MyShuttleCalc library to the Maven feed.

  1. Open VSTS and connect to your team project. Click on the Build & Release Hub and then click Builds. Click on +New to create a new build definition.

  2. In the templates window, type maven into the search box. Click apply on the Maven template.

  3. In the Process page, change the name of the build to MyShuttleCalc.

  4. Click on Options.

  5. Update the Build number format to 0.0$(rev:.r) and update the build queue to default (this is the queue that the VSTS agent in the container is joined to).

  6. Click on Tasks. Click on the Maven task. Edit the following settings:

    FieldValueNotes
    Options--settings ./maven/settings.xmlRequired to authenticate when pushing the Maven package to the feed.
    Goal(s)deploy -Dbuildversion=$(Build.BuildNumber)Tell Maven to publish the package, passing in the build number
    Code Coverage ToolJaCoCoChange the code coverage format
    Source Files Directorysrc/mainThese files must be included in the coverage results
  7. Click Save and Queue. Accept the defaults to queue the build.

  8. A green status bar indicates that the build has been queued. Click on the build number to view the logs in real time.

  9. When the build completes successfully, you can click on the build number to view the summary. Note the test results and code coverage.

    Note: Each time you run the build, the patch number (the last of the 3-digit version numbers) will increment. In the image above, the build has run 6 times so the latest build number is 0.0.6. The package version matches the build number because we supplied the build version number to Maven in the Maven task.
  10. Navigate back to the Maven package feed. There you will see the MyShuttleCalc package.

The installation of Apache Maven is a simple process of extracting the archive and adding the `bin` folder with the `mvn` command to the `PATH`.

Visual Studio Code Maven Build

Detailed steps are:

Visual Studio Code Maven Settings

  • Ensure JAVA_HOME environment variable is set and points to your JDK installation

  • Extract distribution archive in any directory

or

Visual Studio Code Maven Java

Alternatively use your preferred archive extraction tool.

  • Add the bin directory of the created directory apache-maven-3.8.1 to the PATH environment variable

  • Confirm with mvn -v in a new shell. The result should look similar to

Windows Tips

  • Check environment variable value e.g.
  • Adding to PATH: Add the unpacked distribution’s bin directory to your user PATH environment variable by opening up the system properties (WinKey + Pause), selecting the “Advanced” tab, and the “Environment Variables” button, then adding or selecting the PATH variable in the user variables with the value C:Program Filesapache-maven-3.8.1bin. The same dialog can be used to set JAVA_HOME to the location of your JDK, e.g. C:Program FilesJavajdk1.7.0_51

  • Open a new command prompt (Winkey + R then type cmd) and run mvn -v to verify the installation.

Unix-based Operating System (Linux, Solaris and Mac OS X) Tips

Visual Studio Code Maven Settings.xml

  • Check environment variable value

Visual Studio Code Maven Setup

  • Adding to PATH