【发布时间】:2014-12-01 06:42:51
【问题描述】:
我正在开发一个名为 acme-platform 的多模块 maven 项目,其模块设置如下:
- 高级管理员
- acme-common
- acme-global
- acme 服务
- acme 客户端
- acme 注册
- acme 属性
- acme 测试
(它们在 acme-platform pom 中按此顺序列出。)
在某些模块中,我已经能够使用 Spring 的 ReflectionTestUtils 类。但是,在最后一个模块 acme-test 中,我真的想使用它,但我无法使用。 acme-test pom 中没有依赖部分,所以我添加了一个。这是 pom:
<?xml version="1.0" encoding="UTF-8"?>
http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>acme-platform</artifactId>
<groupId>com.awesomeness.acme</groupId>
<version>1.21.0</version>
<relativePath>../</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>acme-test</artifactId>
<version>1.21.0</version>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context-support</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</dependency>
</dependencies>
在添加依赖行之前,我无法将 Spring 的任何 api 导入到我的类中。导入这些行后,我可以访问大部分类,但不是全部,尤其是 ReflectionTestUtils,即使它是 spring-test 模块的一部分(可以验证 here)。
我正在使用 Intellij。我查看了其他问题的答案(例如 this one),以确保我正确更新了我的依赖项。无济于事。
有人知道为什么我不能将org.springframework.test.util.ReflectionTestUtils 导入acme-test吗?
如果您需要任何其他信息,请告诉我。
编辑
依赖的版本信息不在任何模块pom中,而是在根pom(acme-platform)中指定。同样,我可以在其他模块中导入 ReflectionTest,而不是在 acme-test 中。所以我由此推断,只要在根 pom 中使用指定版本声明依赖项,它就不需要在任何模块 pom 中指定版本。 (如果我错了,请纠正我。)
附加编辑
顺便说一句,我也无法导入junit。
【问题讨论】:
-
希望你在
<dependency>标签中提到了<version> -
我没有提到版本,但在我的理解中,我认为我不需要,因为它在其他模块中工作并且他们没有提到版本。该版本正在项目 pom 中处理。我正在更新我的问题以包含此信息。
-
this question 的答案之一可以帮助吗?
标签: java spring maven intellij-idea spring-test