我注意到一个奇怪的问题。我可以使用 Junit 运行我的测试用例,但是当我使用 maven 运行时,其中一个测试用例失败了。它抱怨没有找到 Gson 类 def。
我能够在 Maven 依赖项中看到 Gson jar。
所以我怀疑类路径不包括 Gson。所以我用 -X 运行了 maven 并注意到了一些线索。
[DEBUG] Could not find metadata com.example.libraries:Symbology:1.0.0-SNAPSHOT/maven-metadata.xml in local (C:\Users\ra\.m2\repository)
[DEBUG] Skipped remote update check for com.example.libraries:Symbology:1.0.0-SNAPSHOT/maven-metadata.xml, locally cached metadata up-to-date.
[DEBUG] Could not find metadata com.example.libraries:Symbology:1.0.0-SNAPSHOT/maven-metadata.xml in local (C:\Users\ra\.m2\repository)
[DEBUG] Skipped remote update check for com.example.libraries:Symbology:1.0.0-SNAPSHOT/maven-metadata.xml, locally cached metadata up-to-date.
[WARNING] The POM for com.example.libraries:Symbology:jar:1.0.0-SNAPSHOT is invalid, transitive dependencies (if any) will not be available: 2 problems were encountered while building the effective model for com.example.libraries:Symbology:1.0.0-SNAPSHOT
[ERROR] 'dependencies.dependency.artifactId' for ::jar is missing. @
[ERROR] 'dependencies.dependency.groupId' for ::jar is missing. @
我有一个依赖于 Symbology 项目的项目,而这又使用了 Gson。但是现在从这个日志中我看到传递依赖没有被包括在内。所以没有找到 Gson 类。
这是符号学pom:
<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.example.libraries</groupId>
<artifactId>Symbology</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>Symbology</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.10</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.1</version>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.16</version>
</dependency>
</dependencies>
这是我的项目的 Pom,它调用了 symbology :
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.example.libraries</groupId>
<artifactId>FGF</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>jar</packaging>
<distributionManagement>
<snapshotRepository>
<id>example.com</id>
<name>example.com-snapshots</name>
<url>http://example/artifactory/libs-snapshots-local</url>
</snapshotRepository>
</distributionManagement>
<name>FGF</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.10</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.16</version>
</dependency>
<dependency>
<groupId>com.example.libraries</groupId>
<artifactId>Category</artifactId>
<version>1.0.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.example.libraries</groupId>
<artifactId>Time</artifactId>
<version>1.0.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.example.libraries</groupId>
<artifactId>Display</artifactId>
<version>1.0.0-SNAPSHOT</version>
</dependency>
**<dependency>
<groupId>com.example.libraries</groupId>
<artifactId>Symbology</artifactId>
<version>1.0.0-SNAPSHOT</version>
</dependency>**
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>3.2.0.BUILD-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>cglib</groupId>
<artifactId>cglib</artifactId>
<version>2.2.2</version>
</dependency>
<dependency>
<groupId>org.apache.directory.studio</groupId>
<artifactId>org.apache.commons.lang</artifactId>
<version>2.6</version>
</dependency>
</dependencies>