coc-maven
asmodeus812Coc extensions for maven
Published Package Summary
coc-maven
Maven support for coc.nvim: a project
explorer, commands that run goals, lifecycle phases and favorite command lines,
completion, hover, go-to-definition, code actions and conflict diagnostics for
pom.xml, dependency commands, project and module creation from archetypes,
and a search for the artifact behind an unresolved Java type.
This README covers installation, setup and configuration. Every command and
feature is described in the help page, available once the extension is
active, without :helptags:
:help coc-maven
Requirements
- Neovim or Vim with coc.nvim 0.0.82 or later.
- Maven:
mvnin$PATH, a Maven wrapper (mvnw,mvnw.cmd) in the project, or an executable thatmaven.executable.pathpoints to. - A JDK that Maven can find through
JAVA_HOME. - Optional:
coc-java(orcoc-java-dev). It provides the artifact index for completion and the artifact searcher, and reloads and imports the Java projects. The artifact index only works when the language server runs in standard mode. - Optional:
coc-xml. When it is active, the extension leaves out its own schema completion and schema hover forpom.xml. - Network access to
search.maven.organdrepo1.maven.orgfor the artifact and version search, and torepo.maven.apache.orgto update the archetype catalog.
Installation
Install the extension from its repository:
:CocInstall https://github.com/asmodeus812/coc-maven
The extension starts when you open a Java file or a workspace that contains a
pom.xml in its root or one folder below.
Setup
The filetype of pom.xml
The pom features need the filetype xml for pom.xml. If your Vim setup
gives it another filetype, map it:
vim.g.coc_filetype_map = {
['pom.xml'] = 'xml',
}
JAVA_HOME
Maven needs JAVA_HOME. Set it in the environment that starts Neovim, or give
it to the extension with maven.terminal.customEnv (see
Terminal and environment):
{
"maven.terminal.customEnv": [
{
"environmentVariable": "JAVA_HOME",
"value": "/usr/lib/jvm/java-21-openjdk"
},
{
"environmentVariable": "MAVEN_OPTS",
"value": "-Xms1024m -Xmx4096m"
}
]
}
On Windows, escape backslashes in the value:
"C:\\Program Files\\Java\\jdk-21".
Files
The extension writes:
- the files Maven generates for a project, in
maven.outputDirectory; see Generated files; - the command history of each pom, in the coc storage folder of the extension;
- the archetype catalog, when you update it, in the coc storage folder of the
extension (
:help coc-maven-archetype); - a copy of the artifact index for the artifact searcher, in the coc storage folder of the extension;
- a copy of the help page and its tags, in the coc storage folder of the
extension, which it adds to
'runtimepath'.
It edits your poms only through the dependency, module and project commands.
Troubleshooting
- "Maven not found in PATH": install Maven or a wrapper, or set
maven.executable.path; see Maven executable for the lookup order. - Completion, hover and definition do nothing in a pom: check
:set filetype?in the pom buffer. It must bexml; see The filetype of pom.xml. - No groupId or artifactId candidates: Maven Central needs network access
and
maven.completion.gavEnabledon, and the Java language server index needscoc-javain standard mode. - The explorer is empty: no
pom.xmlwas found; checkmaven.excludedFoldersandmaven.pomfile.globPattern. - Maven fails: open its output with
:CocCommand workspace.showOutput maven. The channel shows each background command line, theJAVA_HOMEset inmaven.terminal.customEnv, and the local repository.
Development
npm install # installs the dependencies and builds lib/index.js
npm run build # builds lib/index.js with esbuild
npm run watch # rebuilds on change
make update # rebuilds server/com.microsoft.java.maven.plugin.jar
NODE_ENV=production minifies the bundle, NODE_ENV=development writes a
source map. make update builds the Java language server plugin from
microsoft/vscode-maven; it needs git, a JDK and Maven.
To try a checkout, add the folder to 'runtimepath', for example
set runtimepath^=/path/to/coc-maven, after building it.
License
MIT, see LICENSE. coc-maven is a fork of
vscode-maven by Microsoft,
adapted to coc.nvim.
- Coc extensions for maven
- onLanguage:java
- workspaceContains:pom.xml
- workspaceContains:*/pom.xml
Want to build, test, or contribute to coc.nvim extensions? Explore our official SDK and testing toolkits.
Open Developer GuideVersion History
This published npm package does not include a history.md or changelog.md file. Browse its npm versions or repository releases for available release information.
Contributed Commands
All contributes.commands entries from the published package manifest for coc-maven@0.1.9.
| Command (:CocCommand) | Description |
|---|---|
| maven.explorer.show | Show Maven Explorer |
| maven.explorer.refresh | Refresh Maven Explorer |
| maven.explorer.flat | Switch to Flat View |
| maven.explorer.hierarchical | Switch to Hierarchical View |
| maven.goal.execute | Run Maven Commands for a project |
| maven.goal.custom | Run Custom Maven Goal |
| maven.goal.clean | Run Maven Phase 'clean' |
| maven.goal.validate | Run Maven Phase 'validate' |
| maven.goal.compile | Run Maven Phase 'compile' |
| maven.goal.test | Run Maven Phase 'test' |
| maven.goal.test-compile | Run Maven Phase 'test-compile' |
| maven.goal.package | Run Maven Phase 'package' |
| maven.goal.verify | Run Maven Phase 'verify' |
| maven.goal.install | Run Maven Phase 'install' |
| maven.goal.site | Run Maven Phase 'site' |
| maven.goal.deploy | Run Maven Phase 'deploy' |
| maven.favorites | Run Favorite Maven Command |
| maven.project.addFavorite | Add Favorite Maven Command |
| maven.history | Open Maven Command History |
| maven.project.effectivePom | Show Effective pom file |
| maven.project.showDependencies | Show Project Dependencies |
| maven.project.addDependency | Add Dependency to pom file |
| maven.project.openPom | Open Project pom file |
| maven.project.generatedResources | Open Generated Maven Files of a Project |
| maven.project.configuration.update | Update Java Project Configuration |
| maven.archetype.generate | Generate Project from Maven Archetype |
| maven.new.module | Create New Maven Module |
| maven.archetype.update | Update Maven Archetype Catalog |
Configuration Schema
All contributes.configuration entries from the published package manifest, including each raw property schema for coc-settings.json.
Raw JSON Schema
{
"type": [
"string",
"null"
],
"scope": "machine",
"default": null,
"description": "Path to a custom Maven settings.xml file to use (overrides the default settings)."
}Raw JSON Schema
{
"enum": [
"flat",
"hierarchical"
],
"type": "string",
"scope": "window",
"default": "hierarchical",
"description": "Layout of the Maven explorer: all projects on one level, or modules nested below the project that declares them."
}Raw JSON Schema
{
"type": "array",
"scope": "resource",
"default": [
"**/.*",
"**/node_modules",
"**/target",
"**/bin",
"**/archetype-resources"
],
"description": "Glob patterns for folders to ignore in Maven project discovery and the Maven view."
}Raw JSON Schema
{
"type": "string",
"scope": "machine-overridable",
"default": "",
"description": "Absolute path to the Maven executable to run (e.g., /usr/bin/mvn)."
}Raw JSON Schema
{
"type": "string",
"scope": "resource",
"default": "",
"description": "Folder for the files Maven generates for a project: effective-pom.xml, dependency-tree.txt, profiles.txt and plugins/. Empty uses a folder named after the md5 of the pom path in the coc storage folder of the extension. A relative path resolves against the folder of the pom, for example target/generated. ${workspaceFolder}, ${projectDir}, ${relativeProjectDir}, environment variables and a leading ~ are expanded."
}Raw JSON Schema
{
"anyOf": [
{
"type": "string"
},
{
"type": "array",
"items": {
"type": "string"
}
}
],
"scope": "machine-overridable",
"default": "",
"description": "Additional command-line options to pass to every Maven invocation (e.g., -T 1C, -Dmaven.test.skip=true)."
}Raw JSON Schema
{
"type": "array",
"items": {
"type": "object",
"title": "environment setting",
"required": [
"environmentVariable",
"value"
],
"properties": {
"value": {
"type": "string",
"description": "Value to assign to the environment variable."
},
"environmentVariable": {
"type": "string",
"minLength": 1,
"description": "Name of the environment variable to set (e.g., MAVEN_OPTS)."
}
}
},
"scope": "resource",
"default": [],
"description": "Environment variables to inject into the integrated terminal when running Maven."
}Raw JSON Schema
{
"type": "array",
"items": {
"type": "object",
"title": "Favorite commands",
"required": [
"command"
],
"properties": {
"alias": {
"type": "string",
"minLength": 1,
"description": "Optional label shown for the favorite command."
},
"debug": {
"type": "boolean",
"default": false,
"description": "Run this favorite with Maven debug output (-X)."
},
"command": {
"type": "string",
"minLength": 1,
"description": "Maven goals and options to run (omit the leading 'mvn')."
}
}
},
"scope": "resource",
"default": [
{
"alias": "Install without tests",
"command": "install -DskipTests"
},
{
"alias": "Build without tests",
"command": "clean package -DskipTests"
}
],
"description": "Saved Maven commands that appear as quick actions in the terminal."
}Raw JSON Schema
{
"type": "string",
"scope": "window",
"default": "**/pom.xml",
"description": "Glob pattern used to resolve and distinguish a POM file. Used to enable various lsp capabilities for pom files."
}Raw JSON Schema
{
"enum": [
"Interactive",
"Open",
"Cancel"
],
"type": "string",
"scope": "window",
"default": "Interactive",
"description": "Default action when prompted to open a detected Maven project."
}Raw JSON Schema
{
"enum": [
"${project.name}",
"${project.artifactId}",
"${project.artifactId}-${project.version}",
"${project.groupId}.${project.artifactId}",
"${project.groupId}.${project.artifactId}-${project.version}"
],
"type": "string",
"scope": "resource",
"default": "${project.name}",
"description": "Template for how project names are shown in the Maven view."
}Raw JSON Schema
{
"type": "boolean",
"scope": "window",
"default": true,
"description": "Query the remote Maven Central search service for GAV (GroupId, ArtifactId, Version) completions in pom.xml. The completions from the Java language server index and the local repository stay on."
}Raw JSON Schema
{
"type": "boolean",
"scope": "resource",
"default": true,
"description": "Precompute Effective POMs in the background to speed up Maven features."
}Raw JSON Schema
{
"type": "boolean",
"scope": "resource",
"default": true,
"description": "Prefer using the Maven Wrapper (mvnw) if present in the project."
}Raw JSON Schema
{
"type": "boolean",
"scope": "window",
"default": true,
"description": "Automatically recompute the Effective POM when a POM file changes."
}Raw JSON Schema
{
"type": "boolean",
"scope": "window",
"default": true,
"description": "Enable diagnostics for dependency version and conflict issues in the dependency tree."
}