netbeans 删除Maven Pom中的重复依赖项

tcomlyy6  于 2022-11-10  发布在  Maven
关注(0)|答案(5)|浏览(213)

我想删除maven pom.xml中的重复依赖项。
我想知道Linux、记事本++、Netbeans、Intellij ...甚至... VIM等多种工具的答案。
示例(我可以删除,但我希望搜索替换答案)

`<dependency>
        <groupId>org.glassfish.jersey.core</groupId>
        <artifactId>jersey-server</artifactId>
        <version>2.7</version>
    </dependency>
    <dependency>
        <groupId>org.glassfish.jersey.containers</groupId>
        <artifactId>jersey-container-servlet-core</artifactId>
        <version>2.7</version>
    </dependency>
    <dependency>
        <groupId>org.glassfish.jersey.containers</groupId>
        <artifactId>jersey-container-jetty-http</artifactId>
        <version>2.7</version>
    </dependency>
    <dependency>
        <groupId>org.glassfish.jersey.media</groupId>
        <artifactId>jersey-media-moxy</artifactId>
        <version>2.7</version>
    </dependency>
    <dependency>
        <groupId>org.glassfish.jersey.containers</groupId>
        <artifactId>jersey-container-jetty-http</artifactId>
        <version>2.7</version>
    </dependency>`

请写本地链接的答案可能会令人沮丧,如果删除。谢谢。

voj3qocg

voj3qocg1#

dependency:analyze-duplicate分析pom. xml中的和标记,并确定重复声明的依赖项。

mvn dependency:analyze-duplicate
t5zmwmid

t5zmwmid2#

您可以使用mvn dependency:tree命令来查找项目中重复依赖项。
使用pom的<exclusions>标记到<dependency>标记中,以从maven项目中排除重复的依赖项。

<dependencies>
    <dependency>
      <groupId>test.ProjectX</groupId>
      <artifactId>ProjectX</artifactId>
      <version>2.0</version>
      <scope>compile</scope>
      <exclusions>
        <exclusion>  
          <groupId>test.ProjectY</groupId>
          <artifactId>ProjectY</artifactId>
        </exclusion>
      </exclusions> 
    </dependency>
  </dependencies>
ozxc1zmp

ozxc1zmp3#

运行mvn clean它会告诉你重复的依赖项。然后删除它们。

ubof19bj

ubof19bj4#

由于pom.xml是XML,因此您也可以使用XSLT:
1.转到https://www.freeformatter.com/xsl-transformer.html
1.使用此XSLT:

<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:output omit-xml-declaration="yes" indent="yes"/>

<xsl:template match="/*">
    <dependencies>
        <xsl:for-each-group select="dependency" group-by="concat(groupId , '|', artifactId)">
            <xsl:sequence select="."/>
        </xsl:for-each-group>
    </dependencies>
</xsl:template>

</xsl:stylesheet>

1.从您的pom.xml中剪切<dependencies>部分作为输入
1.将XSLT的输出粘贴回pom.xml

xesrikrc

xesrikrc5#

mvn相关性:列表-Dsort=true| grep“^[信息]“|awk '{打印$2}'|切割-F1-4 -D:|分类器|唯一的|切割-F1-3 -D:|唯一-c|grep -v '^ *1 '

相关问题