Maven插件依赖异常

问题描述 投票:0回答:1

我有一个一般性问题,根据我在网络上找到的搜索结果,我知道它在一定程度上是无法解决的。

指的是排除由 pom.xml 文件中定义的插件下载的依赖项。

我在下面提供了我的 pom.xml 文件。

<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.application</groupId>
    <artifactId>SemanticFramework</artifactId>
    <packaging>war</packaging>
    <version>1.0.0-SNAPSHOT</version>
    <name>SemanticFramework Jersey Webapp</name>
    <build>
        <finalName>SemanticFramework</finalName>
        <plugins>

                <!-- https://mvnrepository.com/artifact/org.apache.maven.plugins/maven-war-plugin -->
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-war-plugin</artifactId>
                    <version>3.3.2</version>
                </plugin>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.11.0</version>


            </plugin>
            <!-- Run the application using "mvn embedded-glassfish:run" -->
            <plugin>
                <groupId>org.glassfish</groupId>
                <artifactId>maven-embedded-glassfish-plugin</artifactId>
                <version>${glassfish.version}</version>
                <configuration>
                    <goalPrefix>embedded-glassfish</goalPrefix>
                    <app>C:/Users/mariarousi/eclipse-workspace/target/${project.build.finalName}.war</app>
                    <autoDelete>true</autoDelete>
                    <port>8080</port>
                </configuration>




                <dependencies>
                    <dependency>
                        <groupId>com.sun.jersey</groupId>
                        <artifactId>jersey-servlet</artifactId>
                        <version>${project.version}</version>
                    </dependency>
                    <dependency>
                        <groupId>javax.servlet</groupId>
                        <artifactId>javax.servlet-api</artifactId>
                        <version>3.0.1</version>
                    </dependency>
                         
                       


                </dependencies>
            </plugin>
            <plugin>
                <groupId>org.apache.tomcat.maven</groupId>
                <artifactId>tomcat7-maven-plugin</artifactId>
                <version>2.2</version>

            </plugin>

        </plugins>
    </build>



    <dependencies>


        <dependency>
            <groupId>com.thoughtworks.xstream</groupId>
            <artifactId>xstream</artifactId>
            <version>1.4.20</version>
        </dependency>


         <dependency>
            <groupId>org.codehaus.jettison</groupId>
            <artifactId>jettison</artifactId>
            <version>1.5.4</version>
        </dependency>

        <dependency>
            <groupId>com.sun.jersey</groupId>
            <artifactId>jersey-servlet</artifactId>
            <version>${jersey.version}</version>
        </dependency>
        <dependency>
            <groupId>com.sun.jersey</groupId>
            <artifactId>jersey-json</artifactId>
            <version>${jersey.version}</version>
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.8.2</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>com.sun.jersey</groupId>
            <artifactId>jersey-client</artifactId>
            <version>${jersey.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-databind</artifactId>
            <version>2.13.5</version>
        </dependency>
        <dependency>
            <groupId>org.apache.httpcomponents</groupId>
            <artifactId>httpclient</artifactId>
            <version>4.5.13</version>
        </dependency>

        <dependency>
            <groupId>org.glassfish.extras</groupId>
            <artifactId>glassfish-embedded-web</artifactId>
            <version>${glassfish.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>com.google.code.gson</groupId>
            <artifactId>gson</artifactId>
            <version>2.9.0</version>
        </dependency>
        <dependency>
            <groupId>org.json</groupId>
            <artifactId>json</artifactId>
            <version>20230227</version>
        </dependency>


        <dependency>
            <groupId>com.mashape.unirest</groupId>
            <artifactId>unirest-java</artifactId>
            <version>1.4.9</version>
        </dependency>
        <dependency>
            <groupId>org.apache.jena</groupId>
            <artifactId>apache-jena-libs</artifactId>
            <type>pom</type>
            <version>4.2.0</version>
        </dependency>


        <dependency>
            <groupId>com.sun.jersey</groupId>
            <artifactId>jersey-client</artifactId>
            <version>1.19.4</version>
        </dependency>


        <dependency>
            <groupId>com.openlink.virtuoso</groupId>
            <artifactId>virtjdbc4</artifactId>
            <version>4.0</version>
            <scope>system</scope>
            <systemPath>${project.basedir}/virtjdbc4.jar</systemPath>
        </dependency>
        <dependency>


            <groupId>com.openlink.virtuoso</groupId>
            <artifactId>virt_jena3</artifactId>
            <version>3.0</version>
            <scope>system</scope>
            <systemPath>${project.basedir}/virt_jena3.jar</systemPath>
        </dependency>

    <dependency>
            <groupId>com.squareup.okhttp3</groupId>
            <artifactId>okhttp</artifactId>
            <version>5.0.0-alpha.3</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/com.googlecode.json-simple/json-simple -->
        <dependency>
            <groupId>com.googlecode.json-simple</groupId>
            <artifactId>json-simple</artifactId>
            <version>1.1.1</version>
        </dependency>



    </dependencies>

    <properties>
        <jersey.version>1.19</jersey.version>
        <glassfish.version>3.1.1</glassfish.version>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>
</project>

我的想法是排除上述 pom 文件中定义的插件导入的依赖项,因为它们提供了一些漏洞。更具体地说,我想排除

jsoup 1.10.2
,它是由我使用的插件之一自动导入的(不确定到底是哪一个,但我猜是 org.apache.maven.plugins)。

据我所知,直到某一点为止,此操作都无法在此处进行检查(https://www.baeldung.com/mvn-plugin-dependency-exclusion),但由于我不是纯java开发人员,所以我不是确定我是否错过了允许此类功能的东西。

我还想提一下,使用的java是jdk-11(在火开始之前,我知道我知道这是java的超旧版本,但是应用程序最初是在它上面构建的,并且客户端不希望对其进行更改)尊重)。

所以任何想法都会受到欢迎。

另外,如果问题在堆栈溢出社区的手册中没有完全正式化,我深表歉意,但我也不是堆栈溢出的非作者。

java maven pom.xml
1个回答
0
投票

我可以建议一种快速而简单的解决方案,有点“快速而肮脏”的解决方案。 只需直接在您的 pom 中导入具有更高版本的

jsoup
依赖项,该版本没有漏洞,这将被纳入您的最终 jar 中并覆盖从插件导入的传递性
jsoup 1.10.2

如果存在任何冲突,Maven 将使用在 pom 中找到的“最接近”的根依赖项。 这意味着,如果您有两个不同的

jsoup
依赖项导入到您的项目中,一个直接来自您的 pom,另一个以传递方式导入,则第一个将被纳入您的最终 jar 中。

您可以阅读相关内容,也许还可以专门添加

<provided>
等标签来指示您将提供版本和依赖项。

重要提示:请检查该插件是否兼容并可与其他版本的

jsoup
配合使用。确保它适用于您正在导入的新版本,而不是它尝试导入的版本。

另外,请确保您使用任何插件的最新版本,因为这些插件非常流行,并且大多数插件修复了每个版本中的漏洞,因此不要使用传递依赖项,只需更新和升级插件本身的版本即可.

© www.soinside.com 2019 - 2024. All rights reserved.