maven.nvim
maven.nvim copied to clipboard
feat: Enhance Maven plugin with new actions and utilities
This pull request introduces several enhancements and new functionalities to the Maven plugin, improving its usability and extending its capabilities. The following changes have been made:
New Features:
add_dependency_to_pom.lua: Added functionality to facilitate the addition of dependencies directly to the pom.xml file, streamlining the process for users. create_project.lua: Introduced a new action to create Maven projects more efficiently, providing a user-friendly experience. init.lua: Included initialization routines for the new action scripts, ensuring proper setup and integration. create_floating_window.lua: Added utility to create floating windows for user inputs, enhancing the plugin's interface. open_maven_central.lua: Implemented a utility function to open Maven Central, allowing users to easily access repositories and dependencies. validate.lua: Created a validation module to check configurations and ensure correct setup. Modifications:
commands.lua: Updated command definitions to incorporate the new functionalities, making it easier for users to execute Maven-related tasks. config.lua: Modified configuration settings to include a new field for specifying the Maven Central URL, allowing for customization. init.lua: Adjusted initialization logic to accommodate the new utilities and actions, improving overall plugin performance.
if you want to test before merging:
{
'glaulher/maven.nvim',
branch = 'newfeat',
cmd = { 'Maven', 'MavenExec' },
dependencies = 'nvim-lua/plenary.nvim',
config = function()
require('maven').setup {
executable = 'mvn',
-- maven_central_url = 'https://mvnrepository.com/repos/central', if nil https://central.sonatype.com/
}
end,
},
Hey, I just tested out your add dependency feature and I'm encountering a bug where the plugin incorrectly places dependencies when the <dependencyManagement> tag is declared before the project's <dependencies> tag in pom.xml.
If <dependencyManagement> is defined before <dependencies>, it causes jdtls not to find the dependency. This issue also occurs when the <dependencyManagement> tag is declared but the project's <dependencies> tag isn't present, resulting in no error message indicating that the <dependencies> tag is missing from the pom.xml.
I suspect this happens because the <dependencyManagement> tag contains its own <dependencies> tags under it.
Hi, I added the <dependencyManagement> tag and the dependency seems to have been added correctly, could you put the step-by-step instructions here so I can reproduce it?
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.javaexample</groupId>
<artifactId>javaexample</artifactId>
<packaging>jar</packaging>
<version>1.0-SNAPSHOT</version>
<name>javaexample</name>
<url>http://maven.apache.org</url>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava-gwt</artifactId>
<version>33.3.1-jre</version>
</dependency>
</dependencies>
</dependencyManagement>
</project>
I want to clarify that while the plugin adds the dependency correctly to the <dependencyManagement> section,
JDTLS in doesn’t seem pick it up for autocompletion. However, if the dependency is added to the <dependencies> section directly under <project>, JDTLS works as expected with autocompletion.
Should JDTLS be able to recognize dependencies if they are only in the <dependencyManagement> section,
or do they need to be explicitly added under <dependencies> for proper recognition?
For context, here's the pom.xml that works for JDTLS:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.javaexample</groupId>
<artifactId>javaexample</artifactId>
<version>1.0-SNAPSHOT</version>
<name>javaexample</name>
<url>http://www.example.com</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.release>17</maven.compiler.release>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.junit</groupId>
<artifactId>junit-bom</artifactId>
<version>5.11.0</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-params</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.18.1</version>
</dependency>
</dependencies>
</project>
Hi @salem-karim,
Thank you for the detailed feedback! From what I understand, the issue seems to be related to how JDTLS handles dependencies declared inside the <dependencyManagement> section of the pom.xml, rather than an issue with the plugin itself. If you believe JDTLS should handle this automatically, it might be worth checking its documentation or opening an issue to confirm if there’s support for this specific case. https://github.com/mfussenegger/nvim-jdtls
Hello! I have to say its a nice plugin. But these features I am not sure should be in the :Maven command. I think it convolutes the command, its not really a maven goal to create a new project. I'd rather have a :MavenNew or :MavenCreate maybe? The other one feels a bit odd as well, but that one might be OK if it would only show up when in a .pom file and on the top or something. Thank you for your work!