- Visual Studio Code Maven Build
- Visual Studio Code Maven Settings
- Visual Studio Code Maven Java
- Visual Studio Code Maven Settings.xml
- 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 '.
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.
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.
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.
In VSTS, click on Build & Release and then Packages to navigate to the Package Hub. Click + New Feed to create a new feed.
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.
In the Packages Hub, make sure you have selected the Maven feed and click Connect to Feed.
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.Click Generate Maven Credentials.
VSTS creates a credentials snippet. Click Copy to Clipboard to copy the snippet to the clipboard.
In your editor, open the
MyShuttleCalcmavensettings.xml
.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:Press Ctrl-S (or File -> Save) to save the file.
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
.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.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
- 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.
Eclipse
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:
Name Value User _VSTS_Code_Access_Token
Password {PAT that you copied earlier}
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:
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.
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.
In the templates window, type maven into the search box. Click apply on the Maven template.
In the Process page, change the name of the build to MyShuttleCalc.
Click on Options.
Update the Build number format to
0.0$(rev:.r)
and update the build queue todefault
(this is the queue that the VSTS agent in the container is joined to).Click on Tasks. Click on the Maven task. Edit the following settings:
Field Value Notes Options --settings ./maven/settings.xml
Required 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 Tool JaCoCo
Change the code coverage format Source Files Directory src/main
These files must be included in the coverage results Click Save and Queue. Accept the defaults to queue the build.
A green status bar indicates that the build has been queued. Click on the build number to view the logs in real time.
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.Navigate back to the Maven package feed. There you will see the MyShuttleCalc package.
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 installationExtract 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 directoryapache-maven-3.8.1
to thePATH
environment variableConfirm 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 valueC:Program Filesapache-maven-3.8.1bin
. The same dialog can be used to setJAVA_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 runmvn -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