Giter VIP home page Giter VIP logo

vscode-maven's Introduction

Maven for Java

Marketplace Version Installs Rating Build status

Features

Maven extension for VS Code. It provides a project explorer and shortcuts to execute Maven commands, improving user experience for Java developers who use Maven.

  • Support to generate projects from Maven Archetype.
  • Support to generate effective POM.
  • Provide shortcuts to common goals, plugin goals and customized commands.
  • Preserve command history to fast re-run.

Requirements

  • Java
  • Maven / Maven Wrapper

For troubleshooting, please refer to the page HERE.

Basic Usage

Maven Explorer

The extension scans pom.xml in your workspace, and displays all Maven projects and their modules in the sidebar.

Screenshot

Run Plugin Goals

The extension parse effective-pom of Maven projects, and displays all plugins and plugin goals hierarchically.

Screenshot

POM File Editing

The extension provides Maven specific completion suggestions when editing POM files, including snippets and artifact hints.

Screenshot

Re-Run Historical Commands

It preserves history of goals for each project, so you can fast re-run previous long commands, e.g. mvn <goals> -Dparam1=value1 -Dparam2=value2 -Dparam3=value3 ... There are 2 entries for it:

  • Command Palette -> select Maven: History ... -> Select a project -> Select command from the history
  • Right-click on a project -> Click History ... -> Select command from the history

Screenshot

Archetype Related

Generate from Maven Archetype

The extension loads archetypes listed in local/remote catalog. After selection, the extension sends mvn archetype:generate -D... to terminal. There are 2 entries for it:

  • Command Palette -> select Maven: Generate from Maven Archetype
  • Right-click on a folder -> Click Generate from Maven Archetype

Screenshot

Update Maven Archetype Catalog

With following steps, you can update the local cache of Maven remote catalog. It takes some time to download meta data from Maven central repository.

Command Palette -> select Maven: Update Maven Archetype Catalog.

Additional Configurations

JAVA_HOME and Other Environment Variables

This extension executes Maven by opening a terminal session and then calling Maven in that session. Maven requires the JAVA_HOME environment variable to be set. Maven will also look for other variables such as MAVEN_OPTS. If you prefer not to set those variables permanently you can configure them, or any other environment variable, in settings:

{
    "maven.terminal.customEnv": [
        {
            "environmentVariable": "MAVEN_OPTS",               // variable name
            "value": "-Xms1024m -Xmx4096m"                     // value
        },
        {
            "environmentVariable": "JAVA_HOME",                // variable name
            "value": "C:\\Program Files\\Java\\jdk-9.0.4"      // value
        }
    ]
}
Special Handling for JAVA_HOME

If you have Red Hat's Java Language Support extension installed, then you can specify JAVA_HOME in settings for that extension:

{
    "java.home": "C:\\Program Files\\Java\\jdk-9.0.4"      // Red Hat Java Language Support Setting
}

This extension (Maven for Java) can reuse that setting if you desire:

{
    "maven.terminal.useJavaHome": true      // Use the Red Hat Java Language Support Setting for JAVA_HOME
}

With this support, you can specify JAVA_HOME in one place and you do not need to use the maven.terminal.customEnv setting unless you have other environment variables to set.

If you have JAVA_HOME configured through the maven.terminal.customEnv setting, and also specify to reuse the Red Hat setting, then the value from maven.terminal.customEnv will take precedence.

Default Options for Maven Command The usage of Maven executable is:

usage: mvn [options] [<goal(s)>] [<phase(s)>]

You can use maven.executable.options to specify default options for all your Maven commands executed in current project.

{
    "maven.executable.options": "-o -s ./settings.xml"      // work offline, and use an alternative settings file
}
Folder Exclusion for Searching POM Files

To speed up the searching of Maven projects, you can exclude folders in settings:

{
    "maven.excludedFolders": [
        "**/.*",                // exclude hidden folders
        "**/node_modules",      // exclude node modules to speed up
        "**/target"             // exclude duplicated pom file in target folder
    ]
}
Customize Favorite Maven Commands

Specify a favorite command in settings:

{
    "maven.terminal.favorites": [
        {
            "alias": "full-build without tests",
            "command": "clean package -DskipTests"
        }
    ]
}

Now right-click on an project item, and then click Favorite .... The option full-build without tests should show up.

Settings

Name Description Default Value
maven.dependency.enableConflictDiagnostics Specify whether to show diagnostics for conflict dependencies. true
maven.excludedFolders Specifies file path pattern of folders to exclude while searching for Maven projects. [ "**/.*", "**/node_modules", "**/target", "**/bin", "**/archetype-resources" ]
maven.executable.preferMavenWrapper Specifies whether you prefer to use Maven wrapper. If true, it tries using 'mvnw' by walking up the parent folders. If false, or 'mvnw' is not found, it tries 'mvn' in PATH instead. true
maven.executable.path Specifies absolute path of your 'mvn' executable. When this value is empty, it tries using 'mvn' or 'mvnw' according to the value of 'maven.executable.preferMavenWrapper'. E.g. /usr/local/apache-maven-3.6.0/bin/mvn
maven.executable.options Specifies default options for all mvn commands. E.g. -o -DskipTests
maven.explorer.projectName Format of project node name shown in Maven explorer. ${project.name}
maven.projectOpenBehavior "Default method of opening newly created project. "Interactive"
maven.pomfile.autoUpdateEffectivePOM Specifies whether to update effective-pom automatically whenever changes detected. false
maven.pomfile.globPattern Specifies the glob pattern used to look for pom.xml files. **/pom.xml
maven.pomfile.prefetchEffectivePom Specifies whether to prefetch effective pom on startup. false
maven.terminal.useJavaHome If this value is true, and if the setting java.home has a value, then the environment variable JAVA_HOME will be set to the value of java.home when a new terminal window is created. false
maven.terminal.customEnv Specifies an array of environment variable names and values. These environment variable values will be added before Maven is executed.
environmentVariable: Name of the environment variable to set.
value: Value of the environment variable to set.
[]
maven.terminal.favorites Specify pre-defined favorite commands to execute.
alias: A short name for the command.
command: Content of the favorite command.
[]
maven.view Specifies the way of viewing Maven projects. Possible values: flat, hierarchical. flat
maven.settingsFile Specifies the absolute path of Maven settings.xml file. If not specified, ~/.m2/settings.xml is used. null
maven.showInExplorerContextMenu If this value is true, add a command to create Maven Projects in the Explorer context menu for folders. true

Data/Telemetry

VS Code collects usage data and sends it to Microsoft to help improve our products and services. Read our privacy statement to learn more. If you don’t wish to send usage data to Microsoft, you can set the telemetry.enableTelemetry setting to false. Learn more in our FAQ.

Contributing

This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact [email protected] with any additional questions or comments.

Release Notes

Refer to CHANGELOG

vscode-maven's People

Contributors

943297456 avatar andxu avatar apupier avatar balloonio avatar cscherryy avatar darrenparkinson avatar dependabot[bot] avatar doggy8088 avatar duncankwilliams avatar emliunix avatar eskibear avatar gustavosimon avatar jdneo avatar jeffgbutler avatar johanhammar avatar jridgewell avatar mannixsuo avatar microsoft-github-policy-service[bot] avatar or-geva avatar owenconti avatar robertderose avatar runxinxu avatar shihanmeng618 avatar si9ma avatar testforstephen avatar thccorni avatar tonjohn avatar trek-boldly-go avatar xqzlgy2 avatar zhengjun003 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

vscode-maven's Issues

0.6.0 Endgame

Dev

  • Update tree view when pom.xml is created/modified/deleted. (for #13 )
  • Add telemetry to know popular archetype. (for #20 )

Test

Release

  • 3/16 Update Readme.md, changelog.md
  • 3/16 Merge to master branch
  • 3/16 Trigger CI job
  • 3/16 Add tag

Searching for Maven Projects throws "No whitespace between attributes Line: 0 Column: 105 Char: x"

Hi,

I've opened a folder which have previously successfully built with Maven and run through Eclipse.

When scanning the folder for Maven projects I get:
"No whitespace between attributes Line: 0 Column: 105 Char: x"

I've tried a fresh clone so the workspace is clean and I get the same result. I've also tried setting the Maven path in my VS Code User settings.

I'm using Windows 10.

Help please.

Hide Maven view by default

Maven Projects view should hide if the project isn't Maven-enabled. I added when to the package.json :

		"views": {
			"explorer": [
				{
					"id": "mavenProjects",
					"name": "Maven Projects",
					"when": "workspaceContains:pom.xml"
				}

which succeeds in hiding when I don't have a Maven project, but doesn't show in the view contributions list when I load my Java project containing a pom.xml.

Improve pom.xml editing experience

  1. Better auto-completion
    • a. Show dependency candidate list as users type
    • b. Show version candidate list as users type
  2. Code snippet
    • a. Code snippet for dependency
    • b. Code snippet for properties
  3. Syntax highlighting - color logical nodes differently
  4. Error check
    • a. Check compatibility errors between dependencies

windows 10 use bash terminal

I use bash (windows subsystem) as default terminal, compile maven project will be error:

mvn -f "d:\workspace\lts-core\pom.xml" compile
wsh@WSH-T303UA:/mnt/d/workspace$ mvn -f "d:\workspace\lts-core\pom.xml" compile
[INFO] Scanning for projects...
[ERROR] [ERROR] Some problems were encountered while processing the POMs:
[FATAL] Non-readable POM /mnt/d/workspace/d:\workspace\lts-core\pom.xml: /mnt/d/workspace/d:\workspace\lts-core\pom.xml (No such file or directory) @
@

use this command will be correct:
mvn -f "/mnt/d/workspace/lts-core/pom.xml" compile

Please be compatible with bash.

Custom settings.xml

I can't find where should I set my custom settings.xml per project. This is the usage of mvn -s option.

Could this be implemented project-wide?

Better experience of generating projects

When generating projects from archetypes, users have to know exactly what archetype to use. But Maven central does not have a good mechanism for users to discover what's best for their needs. Download numbers are hidden so we cannot tell how popular one package is. The whole experience is frustrating.

Suggest improving the experience by providing a better recommendation mechanism for users to find archetypes. We actually can maintain a list of download numbers initiated from our extension and do recommendation based on that. This is only one way to consider.

The recommendation can also apply to all the scenarios when users look for dependencies.

Error Couldn't find a compatible version of Maven for Java

When trying to install the plugin, the following message always appears

Couldn't find a compatible version of Maven for Java with this version of Code.

I downgraded my maven from version 3.5.3 to 3.5.2 but didn't help.

Has anyone having the same issue?

maven.archetype.generate command issue

I am new to maven but have been having issues with version 3.5.3, when I was on 3.5.2 the plugin worked perfectly but every-since I upgraded with brew to 3.5.3 the maven plugin in vscode shows me this: command 'maven.archetype.generate' not found. I know that if i use man archetype:generate it will work with the terminal, but its the plugin that wont work. I made sure to route where my maven path is in settings in vs studio just in case.. path: /usr/local/Cellar/maven/3.5.3/libexec. its where i had it with version 3.5.2, I just changed it to 3.5.3: anyway, let me know if you can help with this issue. would be glad to have the plugin working rather than keep getting command 'maven.archetype.generate' not found

Error occurred in generating effective pom file

Build: 145

  1. Specify java.home in user settings:
    "java.home": "C:\\Program Files\\Java\\jdk1.8.0_161"
  2. Add following entry in user settings:
    "maven.terminal.useJavaHome": true
  3. Generate Effective POM file

RESULT:
image

Existing terminals don't apply new nvironment variables.

Steps:

  1. Open a maven project
  2. Execute a maven goal, e.g. clean, it launches an integrated terminal.
  3. Update maven.terminal.customEnv in settings.
    "maven.terminal.customEnv": [
        {
            "environmentVariable": "testName",
            "value": "testValue"
        }
    ] 
    
  4. In the terminal, verify the env, it's not set.

Show/Add/Remove dependencies

Inside the explorer view, list the dependencies and allow add/upgrade/remove operations.
This is requested by the users while @yaohaizh already had some changes made at language server side. Please check where the best place for such feature is.

Save Custom Goals

My default workflow is to run "clean install". To do this I have to do the following things

  1. Open the command prompt and navigate to "Maven: Run Goal"

  2. Select Project

  3. Either a) Select the custom goal from history OR b) select custom goal and write it again

It would benefit me to have a way to save off custom goals in a way that they are treated as "first class citizens" IE accessed in a way similar or identical to the standard goals ("install, deploy") are

v0.10.0 Plan

  • Hide Maven view by default #51 ( completed in PR #80 )
  • ~~~Improve user experience for editing pom.xml #47~~~ (Moved to next version)
  • Create separate terminals for each root folder #68 ( completed with PR #83 )
  • Force to use mvnw if found. #84 ( PR #88 ) add a config to turn on/off (#105 )
  • Refactor maven projects explorer ( completed with PR #83 )
  • Improve performance of searching for pom.xml #77 ( completed with PR #83 )
  • Includes archetypes in local catalog when generating projects. #82 (completed with PR #86 )
  • Refactor maven command history. (completed with PR #87 )

FAQ Guidance error pop-up when set maven.executable.path to mvnw.cmd

Describe the bug
Set value of maven.executable.path to mvnw/mvnw.cmd path and save, get below error.
But in fact, for the maven wrapper, we can succefully execute maven command .

To Reproduce

  1. Open project todo-app-java-on-azure in vscode
  2. set "maven.executable.path" to mvnw/mvnw.cmd path and save

Expected behavior
No error.

Environments :

  • OS: Windows 10/Linux/OS X
  • VS Code version: 1.24.1
  • Extension version 0.9.0 (build #234)

Screenshots
image

image

Current working directory is wrong when pom.xml is in subdirectory of root

Describe the bug
The current working directory is wrong when pom.xml is in subdirectory of root. This causes path issues when executing a spring-boot:run command. Can you cd over to the directory of the pom.xml as default behavior?

As a comparison, when you execute a maven goal in Intellij it defaults the working directory to the same directory as the pom.xml file.

Maven goal from context menu gets executed in other projects terminal

Describe the bug
I have a workspace with multiple maven projects. When I have a terminal open in project A, and I wish to run a maven goal in project B, I use the context menu over the "Maven projects" side window and click the desired goal. A new maven terminal windows open in the root of project A to run maven in project B.

adrian@MY-LAPTOP:~/projects/my-project-A$ "./mvnw" clean -f "/home/adrian/projects/my-project-B/pom.xml"
While the thing work, it's confusing that the terminal ends up open in the other project's directory.

To Reproduce
Steps to reproduce the behavior:

  1. Add two maven projects to a workspace.
  2. Open an integrated terminal in project A.
  3. Right click on project B in the maven projects list and run clean goal.
  4. You end up with the clean goal for project B ran from the root directory of project A.

Expected behavior
I expected the maven terminal to be open in the root of the actual project I'm running the goal for.

Environments (please complete the following information as much as possible):

  • OS: Linux Ubuntu 16.04
  • VS Code version: 1.25.0
  • Extension version: 0.9.0

Allow to append default options for mvn commands

Originally raised at Eskibear/vscode-maven#41 by @blassmegod .

Would be nice to have a flag to enable or disable the online use of maven, so that it can cut down on network usage (mvn -o).

Current workaround:

For the moment you have a workaround by running custom goals, adding -o manually for your commonly used commands.


usage: mvn [options] [<goal(s)>] [<phase(s)>]

Possible solution to specify default options in settings.

e.g.

{
    "maven.defaultOptions": "-O -q"
}

Command clean will finally trigger:

mvn -f <pom.xml path> -O -q clean

Maven projects don't open correctly using "File -> Open Workspace..."

If I open a folder containing a multi-module Maven project (well ... all my projects are multi-module), VS Code correctly parses the POM files and sets up the classpath. If I then save the environment as a workspace I should, in theory, be able to load that environment using "Open Workspace...". Instead VS Code seems to be missing some part of the previous workspace's configuration. It's pretty common for the classpath to be incomplete - clicking on some files results in a notification indicating that my Java file isn't on the classpath so only syntax checking will be performed. I originally noticed this because if the classpath doesn't include a test class, running the tests from the test explorer results in an error pop-up that says "Reduce of empty array with no initial value"

The saved workspace doesn't have anything surprising in it - though I'll admit I don't know what it should look like. Since it's very small, here is the contents of that file:

{
	"folders": [
		{
			"path": "/home/smoyer1/git/selesy/hibp-client"
		}
	],
	"settings": {
		"java.configuration.updateBuildConfiguration": "automatic"
	}
}

I'm using:

  • VS Code version 1.21.1
  • Maven for Java version v0.6.0
  • mvn -version returns:
Apache Maven 3.3.9
Maven home: /usr/share/maven
Java version: 1.8.0_151, vendor: Oracle Corporation
Java home: /usr/lib/jvm/java-8-openjdk-amd64/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "4.4.0-116-generic", arch: "amd64", family: "unix"

根据pom.xml创建.classpath&.project文件需要多次重启VSCode

我因错误修改了.classpath,导致项目无法运行。
接下来,我把.classpath以及.project删除了。
然后重启。vscode会根据pom.xml生成.classpath跟.project文件
但是重启,仅仅生成了.project文件。
第二次打开的时候。生成了.vscode\launch.test.json。并没有生成.classpath文件。
第三次打开会生成.classpath但是无法运行我的单元测试.
第四打开就完全可以了。

Error:Illegal argument null

Build: 251

Repro steps:

  1. F1, execute command "Generate from maven archetype"
  2. Select destination folder
  3. Select an archetype

Results:
Error in toggle developer tools:
image

0.7.0 Plan

New features

  • Support to set JAVA_HOME from java.home in extension redhat.java, and add extra environment variables before execute maven commands in terminal. @jeffgbutler

  • Support to put popular archetypes ahead according to collected anonymous data. @Eskibear

  • Allow to append default options for mvn commands #14 @Eskibear

Setting maven command to "./mvnw" works, but it shows an error on startup

Describe the bug
I have my settings like this, to use the maven wrapper that comes from start.spring.io projects:
"maven.executable.path": "./mvnw",

This works smoothly, but after upgrading to last release, because of the new validation, I get:

Unable to execute Maven commands.
Error:
Command failed: "./mvnw" --version
/bin/sh: 1: ./mvnw: not found

To Reproduce
Steps to reproduce the behavior:

  1. Set the maven executable path to "./mvnw"
  2. Close and Open vscode.

Expected behavior
I know the goal for the plugin is to support maven and not the maven wrapper, but I think it's commonly used, so I would like to see if there is a valid workaround or if maybe the command for validation "./mvnw" --version could be run in the project's root.

Thoughts?

0.5.1 Endgame

Dev

  • 2/7 Code change #6
  • CRLF issue in commandHistory.txt #10

Test

Release

  • 2/9 Update Readme.md, changelog.md
  • 2/9 Merge to master branch
  • 2/9 Trigger CI job
  • 2/9 Add tag

When opening vscode Maven Projects take about 11 seconds to appear

Describe the bug
When opening vscode Maven Projects take about 11 seconds to appear.

To Reproduce

  • Root directory has 16 directories.
  • 8 subdirectories have pom.xml files.
  1. Restart vscode.
  2. Expand Maven Projects.
  3. Start timer until projects appear.

Expected behavior
Would a second or two be acceptable?

Environments (please complete the following information as much as possible):

  • OS: OS X
  • VS Code version: Version 1.26.0-insider (1.26.0-insider)
  • Extension version vscjava.vscode-maven-0.9.2

Screenshots
If applicable, add screenshots to help explain your problem.

Additional context
Add any other context about the problem here.

Support the setting of 'maven.executable.path' in vscode workspace folder settings

Describe the bug
Open a multi-root workspace with multiple maven projects, I want one of the projects to use its own mvnw file and others use the environment maven path. But when I search using 'maven' keyword in specified folder settings, there are only two maven settings and I can't find 'maven.executable.path'

To Reproduce

  1. Open a muitl-root worksapce
  2. Open folder settings to choose a project and search maven related settings

Environments (please complete the following information as much as possible):

  • OS: Windows 10/OS X
  • VS Code version: 1.25.1
  • Extension version 0.9.2

Screenshots
image

Support for mvnDebug

Hi,

Is there any support for using mvnDebug instead of mvn? At present I have just added the following setting to use mvnDebug from my PATH.

"maven.executable.path": "mvnDebug"

Not sure if there is a downside of this?

Use case is that I want to be able to use the jetty-maven-plugin and debug my servlet code. So I run mvnDebug jetty:run and then I can attach the vscode debugger.

Thanks
Chris

Locally installed archetypes not detected

Installing an archetype and updating the local-catalog to contain said archetype does not cause it to appear in the list of available archetypes from the Maven: Generate from Maven Archetype command. I have verified that my archetype is correctly installed by cat'ng the local-catalog as well as generating a project using the archetype from the command line.

OS: Debian Stretch

0.7.0 Endgame

Dev

  • Refer to the Plan
  • Update popular archetype list

Test (with new features)

Release

  • 4/12 Update Readme.md, changelog.md
  • 4/12 Merge to master branch
  • 4/12 Trigger CI job
  • 4/12 Add tag

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.