如何在Maven的ProjectB中使用ProjectA的依赖关系?

约翰

我正在与Maven项目一起工作,并且有两个项目,ProjectA并且ProjectBProjectA是一个maven库,其pom如下所示:

ProjectA POM:

<?xml version="1.0" encoding="UTF-8"?>
<project
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
    xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

    <modelVersion>4.0.0</modelVersion>

    <parent>
        <groupId>com.texture.partial</groupId>
        <artifactId>PartialPlatform</artifactId>
        <version>2.1.5-RELEASE</version>
    </parent>

    <groupId>com.texture.transform.golden</groupId>
    <artifactId>SampleClientProjectA</artifactId>
    <version>1.0.4</version>

    <dependencies>
        <dependency>
            <groupId>com.google.code.gson</groupId>
            <artifactId>gson</artifactId>
            <version>2.2.4</version>
        </dependency>
        <dependency>
            <groupId>com.texture.partial.core</groupId>
            <artifactId>PartialKernel</artifactId>
        </dependency>
        <dependency>
            <groupId>com.texture.webres</groupId>
            <artifactId>WebResPartial</artifactId>
        </dependency>
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>javax.servlet-api</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>javax.servlet.jsp</groupId>
            <artifactId>jsp-api</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>com.texture.kernel</groupId>
            <artifactId>TextureServer</artifactId>
        </dependency>
        <dependency>
            <groupId>com.texture.kernel</groupId>
            <artifactId>Kernel</artifactId>
        </dependency>
        <dependency>
            <groupId>com.texture.v3jars.Houston</groupId>
            <artifactId>KerlDEL</artifactId>
        </dependency>
        <dependency>
            <groupId>com.texture.kernel</groupId>
            <artifactId>pKerl</artifactId>
        </dependency>
        <dependency>
            <groupId>com.texture.kernel</groupId>
            <artifactId>pKerlCore</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-beans</artifactId>
        </dependency>
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>javax.servlet-api</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-test</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-asm</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-expression</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-aop</artifactId>
        </dependency>
        <dependency>
            <groupId>aopalliance</groupId>
            <artifactId>aopalliance</artifactId>
        </dependency>
        <dependency>
            <groupId>org.apache.servicemix.bundles</groupId>
            <artifactId>org.apache.servicemix.bundles.cglib</artifactId>
        </dependency>
        <dependency>
            <groupId>com.texture.partial.core</groupId>
            <artifactId>ConfigWeb</artifactId>
        </dependency>
        <dependency>
            <groupId>com.texture.partial.core</groupId>
            <artifactId>PartialWeb</artifactId>
        </dependency>
        <dependency>
            <groupId>com.googlecode.jmockit</groupId>
            <artifactId>jmockit</artifactId>
            <version>1.7</version>
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>
    <build>
        <plugins>
            <plugin>
                <artifactId>maven-surefire-plugin</artifactId>
                <configuration>
                    <argLine>-javaagent:"${settings.localRepository}"/com/googlecode/jmockit/jmockit/1.7/jmockit-1.7.jar</argLine>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>cobertura-maven-plugin</artifactId>
                <configuration>
                    <instrumentation>
                        <excludes>
                            <exclude>**/test/**/*.class</exclude>
                        </excludes>
                    </instrumentation>
                    <formats>
                        <format>xml</format>
                        <format>html</format>
                    </formats>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

在我上面的pom中,PartialKernel带来了各种Spring Framework依赖项(如spring-core,)的较旧版本spring-web它带来了3.2.8.RELEASE版本,我想使用这两个spring框架的最新版本,即4.1.6.RELEASE

    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-web</artifactId>
        <version>4.1.6.RELEASE</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-core</artifactId>
        <version>4.1.6.RELEASE</version>
    </dependency>

我需要使用最新版本,因为某些类仅在最新版本中存在。因此,就像在ProjectA中一样,我在pom.xml中添加了这两个库的新版本。我有一个静态的void主代码,它将测试ProjectA功能,并且工作正常,没有任何问题。

现在,我ProjectB拥有与上述相同的pom,因为它没有最新版本的spring依赖项。在我的ProjectBpom中,我具有的依赖关系ProjectA和相同的代码,它们将测试的功能,ProjectA但是每当我在其中运行相同的类ProjectB时,总是会遇到此错误。

Exception in thread "main" java.lang.NoClassDefFoundError: org.springframework.util.concurrent.ListenableFutureCallback
Caused by: java.lang.ClassNotFoundException: org.springframework.util.concurrent.ListenableFutureCallback

我正在使用的所有与spring相关的最新代码都ProjectA已经包含了spring的最新版本。我拥有的示例测试代码只是用来调用ProjectA所有类来对其进行测试。

ProjectB POM:

<?xml version="1.0" encoding="UTF-8"?>
<project
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
    xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

    <modelVersion>4.0.0</modelVersion>

    <parent>
        <groupId>com.texture.partial</groupId>
        <artifactId>PartialPlatform</artifactId>
        <version>2.1.5-RELEASE</version>
    </parent>

    <groupId>com.texture.transform.golden</groupId>
    <artifactId>SampleTestClientProjectB</artifactId>
    <version>1.0.0</version>

    <dependencies>
        <dependency>
            <groupId>com.google.code.gson</groupId>
            <artifactId>gson</artifactId>
            <version>2.2.4</version>
        </dependency>
        <dependency>
            <groupId>com.texture.partial.core</groupId>
            <artifactId>PartialKernel</artifactId>
        </dependency>
        <dependency>
            <groupId>com.texture.webres</groupId>
            <artifactId>WebResPartial</artifactId>
        </dependency>
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>javax.servlet-api</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>javax.servlet.jsp</groupId>
            <artifactId>jsp-api</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>com.texture.kernel</groupId>
            <artifactId>TextureServer</artifactId>
        </dependency>
        <dependency>
            <groupId>com.texture.kernel</groupId>
            <artifactId>Kernel</artifactId>
        </dependency>
        <dependency>
            <groupId>com.texture.v3jars.Houston</groupId>
            <artifactId>KerlDEL</artifactId>
        </dependency>
        <dependency>
            <groupId>com.texture.kernel</groupId>
            <artifactId>pKerl</artifactId>
        </dependency>
        <dependency>
            <groupId>com.texture.kernel</groupId>
            <artifactId>pKerlCore</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-beans</artifactId>
        </dependency>
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>javax.servlet-api</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-test</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-asm</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-expression</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-aop</artifactId>
        </dependency>
        <dependency>
            <groupId>aopalliance</groupId>
            <artifactId>aopalliance</artifactId>
        </dependency>
        <dependency>
            <groupId>org.apache.servicemix.bundles</groupId>
            <artifactId>org.apache.servicemix.bundles.cglib</artifactId>
        </dependency>
        <dependency>
            <groupId>com.texture.partial.core</groupId>
            <artifactId>ConfigWeb</artifactId>
        </dependency>
        <dependency>
            <groupId>com.texture.partial.core</groupId>
            <artifactId>PartialWeb</artifactId>
        </dependency>
        <dependency>
            <groupId>com.googlecode.jmockit</groupId>
            <artifactId>jmockit</artifactId>
            <version>1.7</version>
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>com.texture.transform.golden</groupId>
            <artifactId>SampleClientProjectA</artifactId>
            <version>1.0.4</version>    
        </dependency>
    </dependencies>
    <build>
        <plugins>
            <plugin>
                <artifactId>maven-surefire-plugin</artifactId>
                <configuration>
                    <argLine>-javaagent:"${settings.localRepository}"/com/googlecode/jmockit/jmockit/1.7/jmockit-1.7.jar</argLine>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>cobertura-maven-plugin</artifactId>
                <configuration>
                    <instrumentation>
                        <excludes>
                            <exclude>**/test/**/*.class</exclude>
                        </excludes>
                    </instrumentation>
                    <formats>
                        <format>xml</format>
                        <format>html</format>
                    </formats>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

但是,当我在ProjectB中添加spring依赖关系的最新版本时,我的测试代码开始正常运行。这就是我所不想要的。有什么办法让我的ProjectB自动开始使用我在ProjectA中使用的依赖项吗?如果他们想更改它,则可以在ProjectB中的代码中覆盖它。

cat_flying

您可以尝试从pom xml中排除依赖项。这是例子。

<dependency>
    <groupId>com.texture.partial.core</groupId>
    <artifactId>PartialKernel</artifactId>
    <exclusions>
        <exclusion>  <!-- declare the exclusion here -->
          <groupId>org.springframework</groupId>
          <artifactId>spring-web</artifactId>
        </exclusion>
        <exclusion> 
          <groupId>org.springframework</groupId>
          <artifactId>spring-core</artifactId>
        </exclusion>
  </exclusions> 
</dependency>

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

如何在ProjectB的dll中从ProjectA订阅C#GUI事件

如何在SBT的.scala文件中使用外部依赖关系?

如何在SpringBoot中使用Lambok依赖关系?

在Java中使用Maven解决依赖关系

projectA ZIP 文件安装在 projectB 构建上 - maven

如何在Maven依赖项中使用JUnit 5.2 BOM?

如何在TestNG测试用例中使用Governor注入依赖关系?

如何在测试中使用gradle功能变量依赖关系?

如何在Entity Framework Core中使用循环依赖关系正确播种数据?

如何在useEffect中使用变量而不将它们置于依赖关系中?

Stack:如何在Setup.hs中使用多包依赖关系?

如何在命令行中使用带有gradle的袜子来解决依赖关系?

如何在多个项目中使用简单注入器并通过传递来解决依赖关系

如何在Django Zappa项目中使用非Python依赖关系?

如何在GWT Maven项目中使用简单的Maven项目作为依赖项?

Maven:如何在派生的JVM中执行依赖关系?

如何在IntelliJ中查看Maven依赖关系层次结构

如何在Maven中包含JavaParser依赖关系?

使用依赖关系构建Maven

如何使用bash将mvn依赖关系:tree的顶级依赖关系转换为Maven坐标列表?

如何在Eclipse中使用Maven导入Android AAR依赖项?

如何在 [SwaggerOperationFilter] 中使用依赖注入?

如何在 Laravel 中使用多重关系

如何在关系SQL查询中使用NOT

如何在Django中使用关系

Maven依赖范围。如何理解可以在哪里使用这种依赖关系?

Maven库在具有不同依赖关系的更多项目中使用

在 azure dev-ops 管道 maven 任务中使用设置文件来解决依赖关系

如何从Eclipse中刷新Maven依赖关系?